Fix E306 in roles/network_plugin (#6516)

Signed-off-by: Miouge1 <maxime@root314.com>
This commit is contained in:
Maxime Guyot 2020-09-03 08:55:40 +02:00 committed by GitHub
parent 2faf53b039
commit 6245587dc8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 104 additions and 88 deletions

View file

@ -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:

View file

@ -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,9 +182,10 @@
- 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 -"
stdin: >
{ "kind": "BGPConfiguration", { "kind": "BGPConfiguration",
"apiVersion": "projectcalico.org/v3", "apiVersion": "projectcalico.org/v3",
"metadata": { "metadata": {
@ -188,15 +194,16 @@
"spec": { "spec": {
"logSeverityScreen": "Info", "logSeverityScreen": "Info",
"nodeToNodeMeshEnabled": {{ nodeToNodeMeshEnabled|default('true') }} , "nodeToNodeMeshEnabled": {{ nodeToNodeMeshEnabled|default('true') }} ,
"asNumber": {{ global_as_num }} }} ' | {{ bin_dir }}/calicoctl.sh apply -f - "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: >
{"apiVersion": "projectcalico.org/v3",
"kind": "BGPPeer", "kind": "BGPPeer",
"metadata": { "metadata": {
"name": "global-{{ item.router_id }}" "name": "global-{{ item.router_id }}"
@ -204,7 +211,7 @@
"spec": { "spec": {
"asNumber": "{{ item.as }}", "asNumber": "{{ item.as }}",
"peerIP": "{{ item.router_id }}" "peerIP": "{{ item.router_id }}"
}}' | {{ bin_dir }}/calicoctl.sh apply -f - }}
register: output register: output
retries: 4 retries: 4
until: output.rc == 0 until: output.rc == 0
@ -215,10 +222,11 @@
- 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: >
{"apiVersion": "projectcalico.org/v3",
"kind": "BGPPeer", "kind": "BGPPeer",
"metadata": { "metadata": {
"name": "peer-to-rrs" "name": "peer-to-rrs"
@ -226,7 +234,7 @@
"spec": { "spec": {
"nodeSelector": "!has(i-am-a-route-reflector)", "nodeSelector": "!has(i-am-a-route-reflector)",
"peerSelector": "has(i-am-a-route-reflector)" "peerSelector": "has(i-am-a-route-reflector)"
}}' | {{ bin_dir }}/calicoctl.sh apply -f - }}
register: output register: output
retries: 4 retries: 4
until: output.rc == 0 until: output.rc == 0
@ -237,10 +245,11 @@
- 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: >
{"apiVersion": "projectcalico.org/v3",
"kind": "BGPPeer", "kind": "BGPPeer",
"metadata": { "metadata": {
"name": "rr-mesh" "name": "rr-mesh"
@ -248,7 +257,7 @@
"spec": { "spec": {
"nodeSelector": "has(i-am-a-route-reflector)", "nodeSelector": "has(i-am-a-route-reflector)",
"peerSelector": "has(i-am-a-route-reflector)" "peerSelector": "has(i-am-a-route-reflector)"
}}' | {{ bin_dir }}/calicoctl.sh apply -f - }}
register: output register: output
retries: 4 retries: 4
until: output.rc == 0 until: output.rc == 0
@ -310,10 +319,11 @@
- 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: >
{"apiVersion": "projectcalico.org/v3",
"kind": "Node", "kind": "Node",
"metadata": { "metadata": {
"name": "{{ inventory_hostname }}" "name": "{{ inventory_hostname }}"
@ -323,7 +333,7 @@
"asNumber": "{{ local_as }}" "asNumber": "{{ local_as }}"
}, },
"orchRefs":[{"nodeName":"{{ inventory_hostname }}","orchestrator":"k8s"}] "orchRefs":[{"nodeName":"{{ inventory_hostname }}","orchestrator":"k8s"}]
}}' | {{ bin_dir }}/calicoctl.sh apply -f - }}
register: output register: output
retries: 4 retries: 4
until: output.rc == 0 until: output.rc == 0
@ -334,10 +344,11 @@
- 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: >
{"apiVersion": "projectcalico.org/v3",
"kind": "BGPPeer", "kind": "BGPPeer",
"metadata": { "metadata": {
"name": "{{ inventory_hostname }}-{{ item.router_id }}" "name": "{{ inventory_hostname }}-{{ item.router_id }}"
@ -346,7 +357,7 @@
"asNumber": "{{ item.as }}", "asNumber": "{{ item.as }}",
"node": "{{ inventory_hostname }}", "node": "{{ inventory_hostname }}",
"peerIP": "{{ item.router_id }}" "peerIP": "{{ item.router_id }}"
}}' | {{ bin_dir }}/calicoctl.sh apply -f - }}
register: output register: output
retries: 4 retries: 4
until: output.rc == 0 until: output.rc == 0

View file

@ -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: