Skip to content

Commit

Permalink
k3s_server: add kube_vip_bgp_peers parameter
Browse files Browse the repository at this point in the history
With the kube_vip_bgp_peers it is possible to define
multiple BGP peer ASN & address pairs for kube-vip.

Sample:

```
kube_vip_bgp_peers:
  - peer_address: 192.168.128.10
    peer_asn: 64512
  - peer_address: 192.168.128.11
    peer_asn: 64512
  - peer_address: 192.168.128.12
    peer_asn: 64512
```

It is possible to merge further lists with kube_vip_bgp_peers__*
parameters.

Sample:

```
kube_vip_bgp_peers__extra:
  - peer_address: 192.168.128.10
    peer_asn: 64512
kube_vip_bgp_peers:
  - peer_address: 192.168.128.11
    peer_asn: 64512
  - peer_address: 192.168.128.12
    peer_asn: 64512
```

This will result in the following list of BGP peer ASN & address pairs:

```
- peer_address: 192.168.128.10
  peer_asn: 64512
- peer_address: 192.168.128.11
  peer_asn: 64512
- peer_address: 192.168.128.12
  peer_asn: 64512
```

Signed-off-by: Christian Berendt <[email protected]>
  • Loading branch information
berendt committed Oct 24, 2024
1 parent fab302f commit 99f185a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions roles/k3s_server/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ kube_vip_bgp_as: "64513"
kube_vip_bgp_peeraddress: 192.168.30.1
kube_vip_bgp_peeras: "64512"

kube_vip_bgp_peers: []
kube_vip_bgp_peers_groups: ['k3s_master']

metal_lb_controller_tag_version: v0.14.3
metal_lb_speaker_tag_version: v0.14.3
metal_lb_type: native
Expand Down
8 changes: 8 additions & 0 deletions roles/k3s_server/meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ argument_specs:
description: Defines the AS for the kube-vip BGP peer
default: "64512"

kube_vip_bgp_peers:
description: List of BGP peer ASN & address pairs
default: []

kube_vip_bgp_peers_groups:
description: Inventory group in which to search for additional kube_vip_bgp_peers parameters to merge.
default: ['k3s_master']

kube_vip_iface:
description:
- Explicitly define an interface that ALL control nodes
Expand Down
4 changes: 4 additions & 0 deletions roles/k3s_server/tasks/vip.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
---
- name: Set _kube_vip_bgp_peers fact
ansible.builtin.set_fact:
_kube_vip_bgp_peers: "{{ lookup('community.general.merge_variables', '^kube_vip_bgp_peers__.+$', initial_value=kube_vip_bgp_peers, groups=kube_vip_bgp_peers_groups) }}" # yamllint disable-line rule:line-length

- name: Create manifests directory on first master
ansible.builtin.file:
path: /var/lib/rancher/k3s/server/manifests
Expand Down
5 changes: 5 additions & 0 deletions roles/k3s_server/templates/vip.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ spec:
- name: bgp_routerid
value: "{{ kube_vip_bgp_routerid }}"
{% endif %}
{% if _kube_vip_bgp_peers | length > 0 %}
- name: bgppeers
value: "{{ _kube_vip_bgp_peers | map(attribute='peer_address') | zip(_kube_vip_bgp_peers| map(attribute='peer_asn')) | map('join', ',') | join(':') }}"
{% else %}
{% if kube_vip_bgp_as is defined %}
- name: bgp_as
value: "{{ kube_vip_bgp_as }}"
Expand All @@ -73,6 +77,7 @@ spec:
- name: bgp_peeras
value: "{{ kube_vip_bgp_peeras }}"
{% endif %}
{% endif %}
{% endif %}
image: ghcr.io/kube-vip/kube-vip:{{ kube_vip_tag_version }}
imagePullPolicy: Always
Expand Down

0 comments on commit 99f185a

Please sign in to comment.