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:
|
2024-06-05 01:02:23 +08:00
|
|
|
- "{{ peers | default([]) | selectattr('scope', 'defined') | selectattr('scope', 'equalto', 'global') | list }}"
|
2022-08-18 15:52:37 +08:00
|
|
|
when:
|
|
|
|
- inventory_hostname == groups['kube_control_plane'][0]
|
|
|
|
|
2024-05-06 11:30:59 +08:00
|
|
|
- name: Calico | Get node for per node peering
|
|
|
|
command:
|
|
|
|
cmd: "{{ bin_dir }}/calicoctl.sh get node {{ inventory_hostname }}"
|
|
|
|
register: output_get_node
|
|
|
|
when:
|
|
|
|
- inventory_hostname in groups['k8s_cluster']
|
|
|
|
- local_as is defined
|
|
|
|
- groups['calico_rr'] | default([]) | length == 0
|
|
|
|
delegate_to: "{{ groups['kube_control_plane'][0] }}"
|
|
|
|
|
|
|
|
- name: Calico | Patch node asNumber for per node peering
|
|
|
|
command:
|
|
|
|
cmd: |-
|
|
|
|
{{ bin_dir }}/calicoctl.sh patch node "{{ inventory_hostname }}" --patch '{{ patch is string | ternary(patch, patch | to_json) }}'
|
|
|
|
vars:
|
|
|
|
patch: >
|
|
|
|
{"spec": {
|
|
|
|
"bgp": {
|
|
|
|
"asNumber": "{{ local_as }}"
|
|
|
|
},
|
|
|
|
"orchRefs": [{"nodeName": "{{ inventory_hostname }}", "orchestrator": "k8s"}]
|
|
|
|
}}
|
|
|
|
register: output
|
|
|
|
retries: 0
|
|
|
|
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
|
|
|
|
- output_get_node.rc == 0
|
|
|
|
|
2022-08-18 15:52:37 +08:00
|
|
|
- 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
|
2024-05-06 11:30:59 +08:00
|
|
|
- output_get_node.rc != 0
|
2022-08-18 15:52:37 +08:00
|
|
|
|
|
|
|
- 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:
|
2024-06-05 01:02:23 +08:00
|
|
|
- "{{ peers | default([]) | selectattr('scope', 'undefined') | list | union(peers | default([]) | selectattr('scope', 'defined') | selectattr('scope', 'equalto', 'node') | list ) }}"
|
2022-08-18 15:52:37 +08:00
|
|
|
delegate_to: "{{ groups['kube_control_plane'][0] }}"
|
|
|
|
when:
|
|
|
|
- inventory_hostname in groups['k8s_cluster']
|