Fix E306 in roles/network_plugin (#6516)
Signed-off-by: Miouge1 <maxime@root314.com>
This commit is contained in:
parent
2faf53b039
commit
6245587dc8
3 changed files with 104 additions and 88 deletions
|
@ -37,13 +37,16 @@
|
||||||
when:
|
when:
|
||||||
- "calico_vxlan_mode in ['Always', 'CrossSubnet']"
|
- "calico_vxlan_mode in ['Always', 'CrossSubnet']"
|
||||||
|
|
||||||
- name: "Get current version of calico cluster version" # noqa 306
|
- name: "Get current version of calico cluster version"
|
||||||
shell: "{{ bin_dir }}/calicoctl.sh version | grep 'Cluster Version:' | awk '{ print $3}'"
|
shell: "set -o pipefail && {{ bin_dir }}/calicoctl.sh version | grep 'Cluster Version:' | awk '{ print $3}'"
|
||||||
|
args:
|
||||||
|
executable: /bin/bash
|
||||||
register: calico_version_on_server
|
register: calico_version_on_server
|
||||||
async: 10
|
async: 10
|
||||||
poll: 3
|
poll: 3
|
||||||
run_once: yes
|
run_once: yes
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
failed_when: false
|
||||||
|
|
||||||
- name: "Determine if calico upgrade is needed"
|
- name: "Determine if calico upgrade is needed"
|
||||||
block:
|
block:
|
||||||
|
|
|
@ -85,9 +85,12 @@
|
||||||
run_once: true
|
run_once: true
|
||||||
when: calico_datastore == "etcd"
|
when: calico_datastore == "etcd"
|
||||||
|
|
||||||
- name: Calico | Check if calico network pool has already been configured # noqa 306
|
- name: Calico | Check if calico network pool has already been configured
|
||||||
|
# noqa 306 - grep will exit 1 if no match found
|
||||||
shell: >
|
shell: >
|
||||||
{{ bin_dir }}/calicoctl.sh get ippool | grep -w "{{ calico_pool_cidr | default(kube_pods_subnet) }}" | wc -l
|
{{ bin_dir }}/calicoctl.sh get ippool | grep -w "{{ calico_pool_cidr | default(kube_pods_subnet) }}" | wc -l
|
||||||
|
args:
|
||||||
|
executable: /bin/bash
|
||||||
register: calico_conf
|
register: calico_conf
|
||||||
retries: 4
|
retries: 4
|
||||||
until: calico_conf.rc == 0
|
until: calico_conf.rc == 0
|
||||||
|
@ -132,9 +135,10 @@
|
||||||
loop_control:
|
loop_control:
|
||||||
label: "{{ item.item.file }}"
|
label: "{{ item.item.file }}"
|
||||||
|
|
||||||
- name: Calico | Configure calico network pool (version < v3.3.0) # noqa 306
|
- name: Calico | Configure calico network pool (version < v3.3.0)
|
||||||
shell: >
|
command:
|
||||||
echo "
|
cmd: "{{ bin_dir }}/calicoctl.sh apply -f -"
|
||||||
|
stdin: >
|
||||||
{ "kind": "IPPool",
|
{ "kind": "IPPool",
|
||||||
"apiVersion": "projectcalico.org/v3",
|
"apiVersion": "projectcalico.org/v3",
|
||||||
"metadata": {
|
"metadata": {
|
||||||
|
@ -144,26 +148,27 @@
|
||||||
"cidr": "{{ calico_pool_cidr | default(kube_pods_subnet) }}",
|
"cidr": "{{ calico_pool_cidr | default(kube_pods_subnet) }}",
|
||||||
"ipipMode": "{{ calico_ipip_mode }}",
|
"ipipMode": "{{ calico_ipip_mode }}",
|
||||||
"vxlanMode": "{{ calico_vxlan_mode }}",
|
"vxlanMode": "{{ calico_vxlan_mode }}",
|
||||||
"natOutgoing": {{ nat_outgoing|default(false) and not peer_with_router|default(false) }} }} " | {{ bin_dir }}/calicoctl.sh apply -f -
|
"natOutgoing": {{ nat_outgoing|default(false) and not peer_with_router|default(false) }} }}
|
||||||
when:
|
when:
|
||||||
- inventory_hostname == groups['kube-master'][0]
|
- inventory_hostname == groups['kube-master'][0]
|
||||||
- 'calico_conf.stdout == "0"'
|
- 'calico_conf.stdout == "0"'
|
||||||
- calico_version is version("v3.3.0", "<")
|
- calico_version is version("v3.3.0", "<")
|
||||||
|
|
||||||
- name: Calico | Configure calico network pool (version >= v3.3.0) # noqa 306
|
- name: Calico | Configure calico network pool (version >= v3.3.0)
|
||||||
shell: >
|
command:
|
||||||
echo "
|
cmd: "{{ bin_dir }}/calicoctl.sh apply -f -"
|
||||||
|
stdin: >
|
||||||
{ "kind": "IPPool",
|
{ "kind": "IPPool",
|
||||||
"apiVersion": "projectcalico.org/v3",
|
"apiVersion": "projectcalico.org/v3",
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"name": "{{ calico_pool_name }}",
|
"name": "{{ calico_pool_name }}",
|
||||||
},
|
},
|
||||||
"spec": {
|
"spec": {
|
||||||
"blockSize": "{{ calico_pool_blocksize | default(kube_network_node_prefix) }}",
|
"blockSize": {{ calico_pool_blocksize | default(kube_network_node_prefix) }},
|
||||||
"cidr": "{{ calico_pool_cidr | default(kube_pods_subnet) }}",
|
"cidr": "{{ calico_pool_cidr | default(kube_pods_subnet) }}",
|
||||||
"ipipMode": "{{ calico_ipip_mode }}",
|
"ipipMode": "{{ calico_ipip_mode }}",
|
||||||
"vxlanMode": "{{ calico_vxlan_mode }}",
|
"vxlanMode": "{{ calico_vxlan_mode }}",
|
||||||
"natOutgoing": {{ nat_outgoing|default(false) and not peer_with_router|default(false) }} }} " | {{ bin_dir }}/calicoctl.sh apply -f -
|
"natOutgoing": {{ nat_outgoing|default(false) and not peer_with_router|default(false) }} }}
|
||||||
when:
|
when:
|
||||||
- inventory_hostname == groups['kube-master'][0]
|
- inventory_hostname == groups['kube-master'][0]
|
||||||
- 'calico_conf.stdout == "0"'
|
- 'calico_conf.stdout == "0"'
|
||||||
|
@ -177,34 +182,36 @@
|
||||||
- inventory_hostname in groups['k8s-cluster']
|
- inventory_hostname in groups['k8s-cluster']
|
||||||
run_once: yes
|
run_once: yes
|
||||||
|
|
||||||
- name: Calico | Set global as_num # noqa 306
|
- name: Calico | Set global as_num
|
||||||
shell: >
|
command:
|
||||||
echo '
|
cmd: "{{ bin_dir }}/calicoctl.sh apply -f -"
|
||||||
{ "kind": "BGPConfiguration",
|
stdin: >
|
||||||
"apiVersion": "projectcalico.org/v3",
|
{ "kind": "BGPConfiguration",
|
||||||
"metadata": {
|
"apiVersion": "projectcalico.org/v3",
|
||||||
"name": "default",
|
"metadata": {
|
||||||
},
|
"name": "default",
|
||||||
"spec": {
|
},
|
||||||
"logSeverityScreen": "Info",
|
"spec": {
|
||||||
"nodeToNodeMeshEnabled": {{ nodeToNodeMeshEnabled|default('true') }} ,
|
"logSeverityScreen": "Info",
|
||||||
"asNumber": {{ global_as_num }} }} ' | {{ bin_dir }}/calicoctl.sh apply -f -
|
"nodeToNodeMeshEnabled": {{ nodeToNodeMeshEnabled|default('true') }} ,
|
||||||
|
"asNumber": {{ global_as_num }} }}
|
||||||
changed_when: false
|
changed_when: false
|
||||||
when:
|
when:
|
||||||
- inventory_hostname == groups['kube-master'][0]
|
- inventory_hostname == groups['kube-master'][0]
|
||||||
|
|
||||||
- name: Calico | Configure peering with router(s) at global scope # noqa 306
|
- name: Calico | Configure peering with router(s) at global scope
|
||||||
shell: >
|
command:
|
||||||
echo '{
|
cmd: "{{ bin_dir }}/calicoctl.sh apply -f -"
|
||||||
"apiVersion": "projectcalico.org/v3",
|
stdin: >
|
||||||
"kind": "BGPPeer",
|
{"apiVersion": "projectcalico.org/v3",
|
||||||
"metadata": {
|
"kind": "BGPPeer",
|
||||||
"name": "global-{{ item.router_id }}"
|
"metadata": {
|
||||||
},
|
"name": "global-{{ item.router_id }}"
|
||||||
"spec": {
|
},
|
||||||
"asNumber": "{{ item.as }}",
|
"spec": {
|
||||||
"peerIP": "{{ item.router_id }}"
|
"asNumber": "{{ item.as }}",
|
||||||
}}' | {{ bin_dir }}/calicoctl.sh apply -f -
|
"peerIP": "{{ item.router_id }}"
|
||||||
|
}}
|
||||||
register: output
|
register: output
|
||||||
retries: 4
|
retries: 4
|
||||||
until: output.rc == 0
|
until: output.rc == 0
|
||||||
|
@ -215,18 +222,19 @@
|
||||||
- inventory_hostname == groups['kube-master'][0]
|
- inventory_hostname == groups['kube-master'][0]
|
||||||
- peer_with_router|default(false)
|
- peer_with_router|default(false)
|
||||||
|
|
||||||
- name: Calico | Configure peering with route reflectors at global scope # noqa 306
|
- name: Calico | Configure peering with route reflectors at global scope
|
||||||
shell: |
|
command:
|
||||||
echo '{
|
cmd: "{{ bin_dir }}/calicoctl.sh apply -f -"
|
||||||
"apiVersion": "projectcalico.org/v3",
|
stdin: >
|
||||||
"kind": "BGPPeer",
|
{"apiVersion": "projectcalico.org/v3",
|
||||||
"metadata": {
|
"kind": "BGPPeer",
|
||||||
"name": "peer-to-rrs"
|
"metadata": {
|
||||||
},
|
"name": "peer-to-rrs"
|
||||||
"spec": {
|
},
|
||||||
"nodeSelector": "!has(i-am-a-route-reflector)",
|
"spec": {
|
||||||
"peerSelector": "has(i-am-a-route-reflector)"
|
"nodeSelector": "!has(i-am-a-route-reflector)",
|
||||||
}}' | {{ bin_dir }}/calicoctl.sh apply -f -
|
"peerSelector": "has(i-am-a-route-reflector)"
|
||||||
|
}}
|
||||||
register: output
|
register: output
|
||||||
retries: 4
|
retries: 4
|
||||||
until: output.rc == 0
|
until: output.rc == 0
|
||||||
|
@ -237,18 +245,19 @@
|
||||||
- inventory_hostname == groups['kube-master'][0]
|
- inventory_hostname == groups['kube-master'][0]
|
||||||
- peer_with_calico_rr|default(false)
|
- peer_with_calico_rr|default(false)
|
||||||
|
|
||||||
- name: Calico | Configure route reflectors to peer with each other # noqa 306
|
- name: Calico | Configure route reflectors to peer with each other
|
||||||
shell: >
|
command:
|
||||||
echo '{
|
cmd: "{{ bin_dir }}/calicoctl.sh apply -f -"
|
||||||
"apiVersion": "projectcalico.org/v3",
|
stdin: >
|
||||||
"kind": "BGPPeer",
|
{"apiVersion": "projectcalico.org/v3",
|
||||||
"metadata": {
|
"kind": "BGPPeer",
|
||||||
"name": "rr-mesh"
|
"metadata": {
|
||||||
},
|
"name": "rr-mesh"
|
||||||
"spec": {
|
},
|
||||||
"nodeSelector": "has(i-am-a-route-reflector)",
|
"spec": {
|
||||||
"peerSelector": "has(i-am-a-route-reflector)"
|
"nodeSelector": "has(i-am-a-route-reflector)",
|
||||||
}}' | {{ bin_dir }}/calicoctl.sh apply -f -
|
"peerSelector": "has(i-am-a-route-reflector)"
|
||||||
|
}}
|
||||||
register: output
|
register: output
|
||||||
retries: 4
|
retries: 4
|
||||||
until: output.rc == 0
|
until: output.rc == 0
|
||||||
|
@ -310,20 +319,21 @@
|
||||||
- inventory_hostname not in groups['kube-master']
|
- inventory_hostname not in groups['kube-master']
|
||||||
- calico_datastore == "kdd"
|
- calico_datastore == "kdd"
|
||||||
|
|
||||||
- name: Calico | Configure node asNumber for per node peering # noqa 306
|
- name: Calico | Configure node asNumber for per node peering
|
||||||
shell: >
|
command:
|
||||||
echo '{
|
cmd: "{{ bin_dir }}/calicoctl.sh apply -f -"
|
||||||
"apiVersion": "projectcalico.org/v3",
|
stdin: >
|
||||||
"kind": "Node",
|
{"apiVersion": "projectcalico.org/v3",
|
||||||
"metadata": {
|
"kind": "Node",
|
||||||
"name": "{{ inventory_hostname }}"
|
"metadata": {
|
||||||
},
|
"name": "{{ inventory_hostname }}"
|
||||||
"spec": {
|
|
||||||
"bgp": {
|
|
||||||
"asNumber": "{{ local_as }}"
|
|
||||||
},
|
},
|
||||||
"orchRefs":[{"nodeName":"{{ inventory_hostname }}","orchestrator":"k8s"}]
|
"spec": {
|
||||||
}}' | {{ bin_dir }}/calicoctl.sh apply -f -
|
"bgp": {
|
||||||
|
"asNumber": "{{ local_as }}"
|
||||||
|
},
|
||||||
|
"orchRefs":[{"nodeName":"{{ inventory_hostname }}","orchestrator":"k8s"}]
|
||||||
|
}}
|
||||||
register: output
|
register: output
|
||||||
retries: 4
|
retries: 4
|
||||||
until: output.rc == 0
|
until: output.rc == 0
|
||||||
|
@ -334,19 +344,20 @@
|
||||||
- local_as is defined
|
- local_as is defined
|
||||||
- groups['calico-rr'] | default([]) | length == 0
|
- groups['calico-rr'] | default([]) | length == 0
|
||||||
|
|
||||||
- name: Calico | Configure peering with router(s) at node scope # noqa 306
|
- name: Calico | Configure peering with router(s) at node scope
|
||||||
shell: >
|
command:
|
||||||
echo '{
|
cmd: "{{ bin_dir }}/calicoctl.sh apply -f -"
|
||||||
"apiVersion": "projectcalico.org/v3",
|
stdin: >
|
||||||
"kind": "BGPPeer",
|
{"apiVersion": "projectcalico.org/v3",
|
||||||
"metadata": {
|
"kind": "BGPPeer",
|
||||||
"name": "{{ inventory_hostname }}-{{ item.router_id }}"
|
"metadata": {
|
||||||
},
|
"name": "{{ inventory_hostname }}-{{ item.router_id }}"
|
||||||
"spec": {
|
},
|
||||||
"asNumber": "{{ item.as }}",
|
"spec": {
|
||||||
"node": "{{ inventory_hostname }}",
|
"asNumber": "{{ item.as }}",
|
||||||
"peerIP": "{{ item.router_id }}"
|
"node": "{{ inventory_hostname }}",
|
||||||
}}' | {{ bin_dir }}/calicoctl.sh apply -f -
|
"peerIP": "{{ item.router_id }}"
|
||||||
|
}}
|
||||||
register: output
|
register: output
|
||||||
retries: 4
|
retries: 4
|
||||||
until: output.rc == 0
|
until: output.rc == 0
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
---
|
---
|
||||||
- name: Calico | Get kubelet hostname # noqa 306
|
- name: Calico | Get kubelet hostname
|
||||||
shell: >-
|
shell: >-
|
||||||
{{ bin_dir }}/kubectl get node -o custom-columns='NAME:.metadata.name,INTERNAL-IP:.status.addresses[?(@.type=="InternalIP")].address'
|
set -o pipefail && {{ bin_dir }}/kubectl get node -o custom-columns='NAME:.metadata.name,INTERNAL-IP:.status.addresses[?(@.type=="InternalIP")].address'
|
||||||
| egrep "{{ ansible_all_ipv4_addresses | join('$|') }}$" | cut -d" " -f1
|
| egrep "{{ ansible_all_ipv4_addresses | join('$|') }}$" | cut -d" " -f1
|
||||||
|
args:
|
||||||
|
executable: /bin/bash
|
||||||
register: calico_kubelet_name
|
register: calico_kubelet_name
|
||||||
delegate_to: "{{ groups['kube-master'][0] }}"
|
delegate_to: "{{ groups['kube-master'][0] }}"
|
||||||
when:
|
when:
|
||||||
|
|
Loading…
Reference in a new issue