You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

235 lines
8.1 KiB

  1. ---
  2. - hosts: kube_node
  3. tasks:
  4. - name: Test tunl0 routes
  5. shell: "set -o pipefail && ! /sbin/ip ro | grep '/{{ calico_pool_blocksize }} | default(26) via' | grep -v tunl0"
  6. args:
  7. executable: /bin/bash
  8. when:
  9. - (calico_ipip_mode is defined and calico_ipip_mode != 'Never' or cloud_provider is defined)
  10. - kube_network_plugin|default('calico') == 'calico'
  11. - hosts: k8s_cluster
  12. vars:
  13. agent_report_interval: 10
  14. netcheck_namespace: default
  15. netchecker_port: 31081
  16. tasks:
  17. - name: Force binaries directory for Container Linux by CoreOS and Flatcar
  18. set_fact:
  19. bin_dir: "/opt/bin"
  20. when: ansible_os_family in ["Flatcar", "Flatcar Container Linux by Kinvolk"]
  21. - name: Force binaries directory on other hosts
  22. set_fact:
  23. bin_dir: "/usr/local/bin"
  24. when: not ansible_os_family in ["Flatcar", "Flatcar Container Linux by Kinvolk"]
  25. - import_role: # noqa unnamed-task
  26. name: cluster-dump
  27. - name: Wait for netchecker server
  28. shell: "set -o pipefail && {{ bin_dir }}/kubectl get pods -o wide --namespace {{ netcheck_namespace }} | grep ^netchecker-server"
  29. args:
  30. executable: /bin/bash
  31. register: ncs_pod
  32. until: ncs_pod.stdout.find('Running') != -1
  33. retries: 3
  34. delay: 10
  35. when: inventory_hostname == groups['kube_control_plane'][0]
  36. - name: Wait for netchecker agents
  37. shell: "set -o pipefail && {{ bin_dir }}/kubectl get pods -o wide --namespace {{ netcheck_namespace }} | grep '^netchecker-agent-.*Running'"
  38. args:
  39. executable: /bin/bash
  40. register: nca_pod
  41. until: nca_pod.stdout_lines|length >= groups['k8s_cluster']|intersect(ansible_play_hosts)|length * 2
  42. retries: 3
  43. delay: 10
  44. failed_when: false
  45. when: inventory_hostname == groups['kube_control_plane'][0]
  46. - name: Get netchecker pods
  47. command: "{{ bin_dir }}/kubectl -n {{ netcheck_namespace }} describe pod -l app={{ item }}"
  48. run_once: true
  49. delegate_to: "{{ groups['kube_control_plane'][0] }}"
  50. no_log: false
  51. with_items:
  52. - netchecker-agent
  53. - netchecker-agent-hostnet
  54. when: not nca_pod is success
  55. - debug: # noqa unnamed-task
  56. var: nca_pod.stdout_lines
  57. when: inventory_hostname == groups['kube_control_plane'][0]
  58. - name: Get netchecker agents
  59. uri:
  60. url: "http://{{ ansible_default_ipv4.address }}:{{ netchecker_port }}/api/v1/agents/"
  61. return_content: yes
  62. run_once: true
  63. delegate_to: "{{ groups['kube_control_plane'][0] }}"
  64. register: agents
  65. retries: 18
  66. delay: "{{ agent_report_interval }}"
  67. until: agents.content|length > 0 and
  68. agents.content[0] == '{' and
  69. agents.content|from_json|length >= groups['k8s_cluster']|intersect(ansible_play_hosts)|length * 2
  70. failed_when: false
  71. no_log: false
  72. - name: Check netchecker status
  73. uri:
  74. url: "http://{{ ansible_default_ipv4.address }}:{{ netchecker_port }}/api/v1/connectivity_check"
  75. status_code: 200
  76. return_content: yes
  77. delegate_to: "{{ groups['kube_control_plane'][0] }}"
  78. run_once: true
  79. register: connectivity_check
  80. retries: 3
  81. delay: "{{ agent_report_interval }}"
  82. until: connectivity_check.content|length > 0 and
  83. connectivity_check.content[0] == '{'
  84. no_log: false
  85. failed_when: false
  86. when:
  87. - agents.content != '{}'
  88. - debug: # noqa unnamed-task
  89. var: ncs_pod
  90. run_once: true
  91. - name: Get kube-proxy logs
  92. command: "{{ bin_dir }}/kubectl -n kube-system logs -l k8s-app=kube-proxy"
  93. no_log: false
  94. when:
  95. - inventory_hostname == groups['kube_control_plane'][0]
  96. - not connectivity_check is success
  97. - name: Get logs from other apps
  98. command: "{{ bin_dir }}/kubectl -n kube-system logs -l k8s-app={{ item }} --all-containers"
  99. when:
  100. - inventory_hostname == groups['kube_control_plane'][0]
  101. - not connectivity_check is success
  102. no_log: false
  103. with_items:
  104. - kube-router
  105. - flannel
  106. - canal-node
  107. - calico-node
  108. - cilium
  109. - name: Parse agents list
  110. set_fact:
  111. agents_check_result: "{{ agents.content | from_json }}"
  112. delegate_to: "{{ groups['kube_control_plane'][0] }}"
  113. run_once: true
  114. when:
  115. - agents is success
  116. - agents.content is defined
  117. - agents.content[0] == '{'
  118. - debug: # noqa unnamed-task
  119. var: agents_check_result
  120. delegate_to: "{{ groups['kube_control_plane'][0] }}"
  121. run_once: true
  122. when:
  123. - agents_check_result is defined
  124. - name: Parse connectivity check
  125. set_fact:
  126. connectivity_check_result: "{{ connectivity_check.content | from_json }}"
  127. delegate_to: "{{ groups['kube_control_plane'][0] }}"
  128. run_once: true
  129. when:
  130. - connectivity_check is success
  131. - connectivity_check.content is defined
  132. - connectivity_check.content[0] == '{'
  133. - debug: # noqa unnamed-task
  134. var: connectivity_check_result
  135. delegate_to: "{{ groups['kube_control_plane'][0] }}"
  136. run_once: true
  137. when:
  138. - connectivity_check_result is defined
  139. - name: Check connectivity with all netchecker agents
  140. assert:
  141. that:
  142. - agents_check_result is defined
  143. - connectivity_check_result is defined
  144. - agents_check_result.keys() | length > 0
  145. - not connectivity_check_result.Absent
  146. - not connectivity_check_result.Outdated
  147. msg: "Connectivity check to netchecker agents failed"
  148. delegate_to: "{{ groups['kube_control_plane'][0] }}"
  149. run_once: true
  150. - name: Create macvlan network conf
  151. # We cannot use only shell: below because Ansible will render the text
  152. # with leading spaces, which means the shell will never find the string
  153. # EOF at the beginning of a line. We can avoid Ansible's unhelpful
  154. # heuristics by using the cmd parameter like this:
  155. shell:
  156. cmd: |
  157. cat <<EOF | {{ bin_dir }}/kubectl create -f -
  158. apiVersion: "k8s.cni.cncf.io/v1"
  159. kind: NetworkAttachmentDefinition
  160. metadata:
  161. name: macvlan-conf
  162. spec:
  163. config: '{
  164. "cniVersion": "0.4.0",
  165. "type": "macvlan",
  166. "master": "eth0",
  167. "mode": "bridge",
  168. "ipam": {
  169. "type": "host-local",
  170. "subnet": "192.168.1.0/24",
  171. "rangeStart": "192.168.1.200",
  172. "rangeEnd": "192.168.1.216",
  173. "routes": [
  174. { "dst": "0.0.0.0/0" }
  175. ],
  176. "gateway": "192.168.1.1"
  177. }
  178. }'
  179. EOF
  180. when:
  181. - inventory_hostname == groups['kube_control_plane'][0]
  182. - kube_network_plugin_multus|default(false)|bool
  183. - name: Annotate pod with macvlan network
  184. # We cannot use only shell: below because Ansible will render the text
  185. # with leading spaces, which means the shell will never find the string
  186. # EOF at the beginning of a line. We can avoid Ansible's unhelpful
  187. # heuristics by using the cmd parameter like this:
  188. shell:
  189. cmd: |
  190. cat <<EOF | {{ bin_dir }}/kubectl create -f -
  191. apiVersion: v1
  192. kind: Pod
  193. metadata:
  194. name: samplepod
  195. annotations:
  196. k8s.v1.cni.cncf.io/networks: macvlan-conf
  197. spec:
  198. containers:
  199. - name: samplepod
  200. command: ["/bin/bash", "-c", "sleep 2000000000000"]
  201. image: dougbtv/centos-network
  202. EOF
  203. when:
  204. - inventory_hostname == groups['kube_control_plane'][0]
  205. - kube_network_plugin_multus|default(false)|bool
  206. - name: Check secondary macvlan interface
  207. command: "{{ bin_dir }}/kubectl exec samplepod -- ip addr show dev net1"
  208. register: output
  209. until: output.rc == 0
  210. retries: 90
  211. changed_when: false
  212. when:
  213. - inventory_hostname == groups['kube_control_plane'][0]
  214. - kube_network_plugin_multus|default(false)|bool