2022-08-18 15:52:37 +08:00
|
|
|
---
|
|
|
|
- name: Calico | Configure peering with router(s) at global scope
|
|
|
|
command:
|
|
|
|
cmd: "{{ bin_dir }}/calicoctl.sh apply -f -"
|
2023-07-05 11:36:54 +08:00
|
|
|
stdin: "{{ stdin is string | ternary(stdin, stdin | to_json) }}"
|
2022-08-18 15:52:37 +08:00
|
|
|
vars:
|
|
|
|
stdin: >
|
|
|
|
{"apiVersion": "projectcalico.org/v3",
|
|
|
|
"kind": "BGPPeer",
|
|
|
|
"metadata": {
|
2023-07-05 11:36:54 +08:00
|
|
|
"name": "global-{{ item.name | default(item.router_id | replace(':', '-')) }}"
|
2022-08-18 15:52:37 +08:00
|
|
|
},
|
|
|
|
"spec": {
|
|
|
|
"asNumber": "{{ item.as }}",
|
|
|
|
"peerIP": "{{ item.router_id }}"
|
|
|
|
}}
|
|
|
|
register: output
|
|
|
|
retries: 4
|
|
|
|
until: output.rc == 0
|
|
|
|
delay: "{{ retry_stagger | random + 3 }}"
|
|
|
|
with_items:
|
2023-07-05 11:36:54 +08:00
|
|
|
- "{{ peers | selectattr('scope', 'defined') | selectattr('scope', 'equalto', 'global') | list | default([]) }}"
|
2022-08-18 15:52:37 +08:00
|
|
|
when:
|
|
|
|
- inventory_hostname == groups['kube_control_plane'][0]
|
|
|
|
|
|
|
|
- name: Calico | Configure node asNumber for per node peering
|
|
|
|
command:
|
|
|
|
cmd: "{{ bin_dir }}/calicoctl.sh apply -f -"
|
2023-07-05 11:36:54 +08:00
|
|
|
stdin: "{{ stdin is string | ternary(stdin, stdin | to_json) }}"
|
2022-08-18 15:52:37 +08:00
|
|
|
vars:
|
|
|
|
stdin: >
|
|
|
|
{"apiVersion": "projectcalico.org/v3",
|
|
|
|
"kind": "Node",
|
|
|
|
"metadata": {
|
|
|
|
"name": "{{ inventory_hostname }}"
|
|
|
|
},
|
|
|
|
"spec": {
|
|
|
|
"bgp": {
|
|
|
|
"asNumber": "{{ local_as }}"
|
|
|
|
},
|
|
|
|
"orchRefs":[{"nodeName":"{{ inventory_hostname }}","orchestrator":"k8s"}]
|
|
|
|
}}
|
|
|
|
register: output
|
|
|
|
retries: 4
|
|
|
|
until: output.rc == 0
|
|
|
|
delay: "{{ retry_stagger | random + 3 }}"
|
|
|
|
when:
|
|
|
|
- inventory_hostname in groups['k8s_cluster']
|
|
|
|
- local_as is defined
|
|
|
|
- groups['calico_rr'] | default([]) | length == 0
|
|
|
|
|
|
|
|
- name: Calico | Configure peering with router(s) at node scope
|
|
|
|
command:
|
|
|
|
cmd: "{{ bin_dir }}/calicoctl.sh apply -f -"
|
2023-07-05 11:36:54 +08:00
|
|
|
stdin: "{{ stdin is string | ternary(stdin, stdin | to_json) }}"
|
2022-08-18 15:52:37 +08:00
|
|
|
vars:
|
|
|
|
stdin: >
|
|
|
|
{"apiVersion": "projectcalico.org/v3",
|
|
|
|
"kind": "BGPPeer",
|
|
|
|
"metadata": {
|
2023-07-05 11:36:54 +08:00
|
|
|
"name": "{{ inventory_hostname }}-{{ item.name | default(item.router_id | replace(':', '-')) }}"
|
2022-08-18 15:52:37 +08:00
|
|
|
},
|
|
|
|
"spec": {
|
|
|
|
"asNumber": "{{ item.as }}",
|
|
|
|
"node": "{{ inventory_hostname }}",
|
|
|
|
"peerIP": "{{ item.router_id }}",
|
2024-04-22 10:35:34 +08:00
|
|
|
{% if calico_version is version('v3.26.0', '>=') and (item.filters | default([]) | length > 0) %}
|
|
|
|
"filters": {{ item.filters }},
|
|
|
|
{% endif %}
|
2023-07-05 11:36:54 +08:00
|
|
|
"sourceAddress": "{{ item.sourceaddress | default('UseNodeIP') }}"
|
2022-08-18 15:52:37 +08:00
|
|
|
}}
|
|
|
|
register: output
|
|
|
|
retries: 4
|
|
|
|
until: output.rc == 0
|
|
|
|
delay: "{{ retry_stagger | random + 3 }}"
|
|
|
|
with_items:
|
2023-07-05 11:36:54 +08:00
|
|
|
- "{{ peers | selectattr('scope', 'undefined') | list | default([]) | union(peers | selectattr('scope', 'defined') | selectattr('scope', 'equalto', 'node') | list | default([])) }}"
|
2022-08-18 15:52:37 +08:00
|
|
|
delegate_to: "{{ groups['kube_control_plane'][0] }}"
|
|
|
|
when:
|
|
|
|
- inventory_hostname in groups['k8s_cluster']
|