From 8c3b2851f6a129cdfae6e257594489da9454da16 Mon Sep 17 00:00:00 2001 From: Erwan Miran Date: Sat, 28 Sep 2024 11:06:01 +0200 Subject: [PATCH] feat(calico): add support for numAllowedLocalASNumbers on bgppeers per node definition (#11570) --- docs/CNI/calico.md | 5 ++++- docs/calico_peer_example/new-york.yml | 4 ++++ docs/calico_peer_example/paris.yml | 4 ++++ roles/network_plugin/calico/tasks/peer_with_router.yml | 3 +++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/docs/CNI/calico.md b/docs/CNI/calico.md index 24c646b2f..2b3890914 100644 --- a/docs/CNI/calico.md +++ b/docs/CNI/calico.md @@ -89,9 +89,12 @@ node1 ansible_ssh_host=95.54.0.12 local_as=xxxxxx Peers can be defined using the `peers` variable (see docs/calico_peer_example examples). In order to define global peers, the `peers` variable can be defined in group_vars with the "scope" attribute of each global peer set to "global". -In order to define peers on a per node basis, the `peers` variable must be defined in hostvars. +In order to define peers on a per node basis, the `peers` variable must be defined in hostvars or group_vars with the "scope" attribute unset or set to "node". + NB: Ansible's `hash_behaviour` is by default set to "replace", thus defining both global and per node peers would end up with having only per node peers. If having both global and per node peers defined was meant to happen, global peers would have to be defined in hostvars for each host (as well as per node peers) +NBĀ²: Peers definition at node scope can be customized with additional fields `filters`, `sourceAddress` and `numAllowedLocalASNumbers` (see for details) + Since calico 3.4, Calico supports advertising Kubernetes service cluster IPs over BGP, just as it advertises pod IPs. This can be enabled by setting the following variable as follow in group_vars (k8s_cluster/k8s-net-calico.yml) diff --git a/docs/calico_peer_example/new-york.yml b/docs/calico_peer_example/new-york.yml index af497a9a9..3f44e5593 100644 --- a/docs/calico_peer_example/new-york.yml +++ b/docs/calico_peer_example/new-york.yml @@ -2,9 +2,13 @@ # peers: # - router_id: "10.99.0.34" # as: "65xxx" +# filters: [] +# numallowedlocalasnumbers: 0 # sourceaddress: "None" # - router_id: "10.99.0.35" # as: "65xxx" +# filters: [] +# numallowedlocalasnumbers: 0 # sourceaddress: "None" # loadbalancer_apiserver: diff --git a/docs/calico_peer_example/paris.yml b/docs/calico_peer_example/paris.yml index 1768e0305..746a7ddc7 100644 --- a/docs/calico_peer_example/paris.yml +++ b/docs/calico_peer_example/paris.yml @@ -2,9 +2,13 @@ # peers: # - router_id: "10.99.0.2" # as: "65xxx" +# filters: [] +# numallowedlocalasnumbers: 0 # sourceaddress: "None" # - router_id: "10.99.0.3" # as: "65xxx" +# filters: [] +# numallowedlocalasnumbers: 0 # sourceaddress: "None" # loadbalancer_apiserver: diff --git a/roles/network_plugin/calico/tasks/peer_with_router.yml b/roles/network_plugin/calico/tasks/peer_with_router.yml index e9b4feced..333494724 100644 --- a/roles/network_plugin/calico/tasks/peer_with_router.yml +++ b/roles/network_plugin/calico/tasks/peer_with_router.yml @@ -100,6 +100,9 @@ {% if calico_version is version('v3.26.0', '>=') and (item.filters | default([]) | length > 0) %} "filters": {{ item.filters }}, {% endif %} + {% if calico_version is version('v3.23.0', '>=') and (item.numallowedlocalasnumbers | default(0) > 0) %} + "numAllowedLocalASNumbers": {{ item.numallowedlocalasnumbers }}, + {% endif %} "sourceAddress": "{{ item.sourceaddress | default('UseNodeIP') }}" }} register: output