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.

222 lines
7.1 KiB

  1. ---
  2. - hosts: kube-node
  3. tasks:
  4. - name: Test tunl0 routes
  5. shell: "set -o pipefail && ! /sbin/ip ro | grep '/26 via' | grep -v tunl0"
  6. args:
  7. executable: /bin/bash
  8. when:
  9. - (ipip|default(true) 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 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 Container Linux by Kinvolk"]
  25. - import_role:
  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:
  56. var: nca_pod.stdout_lines
  57. failed_when: not nca_pod is success
  58. when: inventory_hostname == groups['kube_control_plane'][0]
  59. - name: Get netchecker agents
  60. uri:
  61. url: "http://{{ ansible_default_ipv4.address }}:{{ netchecker_port }}/api/v1/agents/"
  62. return_content: yes
  63. run_once: true
  64. delegate_to: "{{ groups['kube_control_plane'][0] }}"
  65. register: agents
  66. retries: 18
  67. delay: "{{ agent_report_interval }}"
  68. until: agents.content|length > 0 and
  69. agents.content[0] == '{' and
  70. agents.content|from_json|length >= groups['k8s-cluster']|intersect(ansible_play_hosts)|length * 2
  71. failed_when: false
  72. no_log: true
  73. - debug:
  74. var: agents.content | from_json
  75. failed_when: not agents is success and not agents.content=='{}'
  76. run_once: true
  77. when:
  78. - agents.content is defined
  79. - agents.content
  80. - agents.content[0] == '{'
  81. - name: Check netchecker status
  82. uri:
  83. url: "http://{{ ansible_default_ipv4.address }}:{{ netchecker_port }}/api/v1/connectivity_check"
  84. status_code: 200
  85. return_content: yes
  86. delegate_to: "{{ groups['kube_control_plane'][0] }}"
  87. run_once: true
  88. register: result
  89. retries: 3
  90. delay: "{{ agent_report_interval }}"
  91. until: result.content|length > 0 and
  92. result.content[0] == '{'
  93. no_log: true
  94. failed_when: false
  95. when:
  96. - agents.content != '{}'
  97. - debug:
  98. var: ncs_pod
  99. run_once: true
  100. when: not result is success
  101. - name: Get kube-proxy logs
  102. command: "{{ bin_dir }}/kubectl -n kube-system logs -l k8s-app=kube-proxy"
  103. no_log: false
  104. when:
  105. - inventory_hostname == groups['kube_control_plane'][0]
  106. - not result is success
  107. - name: Get logs from other apps
  108. command: "{{ bin_dir }}/kubectl -n kube-system logs -l k8s-app={{ item }} --all-containers"
  109. when:
  110. - inventory_hostname == groups['kube_control_plane'][0]
  111. - not result is success
  112. no_log: false
  113. with_items:
  114. - kube-router
  115. - flannel
  116. - canal-node
  117. - calico-node
  118. - cilium
  119. - debug:
  120. var: result.content | from_json
  121. failed_when: not result is success
  122. run_once: true
  123. when:
  124. - not agents.content == '{}'
  125. - result.content
  126. - result.content[0] == '{'
  127. - debug:
  128. var: result
  129. failed_when: not result is success
  130. run_once: true
  131. when:
  132. - not agents.content == '{}'
  133. - debug:
  134. msg: "Cannot get reports from agents, consider as PASSING"
  135. run_once: true
  136. when:
  137. - agents.content == '{}'
  138. - name: Create macvlan network conf
  139. # We cannot use only shell: below because Ansible will render the text
  140. # with leading spaces, which means the shell will never find the string
  141. # EOF at the beginning of a line. We can avoid Ansible's unhelpful
  142. # heuristics by using the cmd parameter like this:
  143. shell:
  144. cmd: |
  145. cat <<EOF | {{ bin_dir }}/kubectl create -f -
  146. apiVersion: "k8s.cni.cncf.io/v1"
  147. kind: NetworkAttachmentDefinition
  148. metadata:
  149. name: macvlan-conf
  150. spec:
  151. config: '{
  152. "cniVersion": "0.4.0",
  153. "type": "macvlan",
  154. "master": "eth0",
  155. "mode": "bridge",
  156. "ipam": {
  157. "type": "host-local",
  158. "subnet": "192.168.1.0/24",
  159. "rangeStart": "192.168.1.200",
  160. "rangeEnd": "192.168.1.216",
  161. "routes": [
  162. { "dst": "0.0.0.0/0" }
  163. ],
  164. "gateway": "192.168.1.1"
  165. }
  166. }'
  167. EOF
  168. when:
  169. - inventory_hostname == groups['kube_control_plane'][0]
  170. - kube_network_plugin_multus|default(false)|bool
  171. - name: Annotate pod with macvlan network
  172. # We cannot use only shell: below because Ansible will render the text
  173. # with leading spaces, which means the shell will never find the string
  174. # EOF at the beginning of a line. We can avoid Ansible's unhelpful
  175. # heuristics by using the cmd parameter like this:
  176. shell:
  177. cmd: |
  178. cat <<EOF | {{ bin_dir }}/kubectl create -f -
  179. apiVersion: v1
  180. kind: Pod
  181. metadata:
  182. name: samplepod
  183. annotations:
  184. k8s.v1.cni.cncf.io/networks: macvlan-conf
  185. spec:
  186. containers:
  187. - name: samplepod
  188. command: ["/bin/bash", "-c", "sleep 2000000000000"]
  189. image: dougbtv/centos-network
  190. EOF
  191. when:
  192. - inventory_hostname == groups['kube_control_plane'][0]
  193. - kube_network_plugin_multus|default(false)|bool
  194. - name: Check secondary macvlan interface
  195. command: "{{ bin_dir }}/kubectl exec samplepod -- ip addr show dev net1"
  196. register: output
  197. until: output.rc == 0
  198. retries: 90
  199. changed_when: false
  200. when:
  201. - inventory_hostname == groups['kube_control_plane'][0]
  202. - kube_network_plugin_multus|default(false)|bool