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.

225 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-master'][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-master'][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-master'][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-master'][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-master'][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-master'][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-master'][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-master'][0]
  111. - not result is success
  112. no_log: false
  113. with_items:
  114. - kube-router
  115. - flannel
  116. - contiv-ovs
  117. - contiv-netplugin
  118. - contiv-netmaster
  119. - canal-node
  120. - calico-node
  121. - cilium
  122. - debug:
  123. var: result.content | from_json
  124. failed_when: not result is success
  125. run_once: true
  126. when:
  127. - not agents.content == '{}'
  128. - result.content
  129. - result.content[0] == '{'
  130. - debug:
  131. var: result
  132. failed_when: not result is success
  133. run_once: true
  134. when:
  135. - not agents.content == '{}'
  136. - debug:
  137. msg: "Cannot get reports from agents, consider as PASSING"
  138. run_once: true
  139. when:
  140. - agents.content == '{}'
  141. - name: Create macvlan network conf
  142. # We cannot use only shell: below because Ansible will render the text
  143. # with leading spaces, which means the shell will never find the string
  144. # EOF at the beginning of a line. We can avoid Ansible's unhelpful
  145. # heuristics by using the cmd parameter like this:
  146. shell:
  147. cmd: |
  148. cat <<EOF | {{ bin_dir }}/kubectl create -f -
  149. apiVersion: "k8s.cni.cncf.io/v1"
  150. kind: NetworkAttachmentDefinition
  151. metadata:
  152. name: macvlan-conf
  153. spec:
  154. config: '{
  155. "cniVersion": "0.4.0",
  156. "type": "macvlan",
  157. "master": "eth0",
  158. "mode": "bridge",
  159. "ipam": {
  160. "type": "host-local",
  161. "subnet": "192.168.1.0/24",
  162. "rangeStart": "192.168.1.200",
  163. "rangeEnd": "192.168.1.216",
  164. "routes": [
  165. { "dst": "0.0.0.0/0" }
  166. ],
  167. "gateway": "192.168.1.1"
  168. }
  169. }'
  170. EOF
  171. when:
  172. - inventory_hostname == groups['kube-master'][0]
  173. - kube_network_plugin_multus|default(false)|bool
  174. - name: Annotate pod with macvlan network
  175. # We cannot use only shell: below because Ansible will render the text
  176. # with leading spaces, which means the shell will never find the string
  177. # EOF at the beginning of a line. We can avoid Ansible's unhelpful
  178. # heuristics by using the cmd parameter like this:
  179. shell:
  180. cmd: |
  181. cat <<EOF | {{ bin_dir }}/kubectl create -f -
  182. apiVersion: v1
  183. kind: Pod
  184. metadata:
  185. name: samplepod
  186. annotations:
  187. k8s.v1.cni.cncf.io/networks: macvlan-conf
  188. spec:
  189. containers:
  190. - name: samplepod
  191. command: ["/bin/bash", "-c", "sleep 2000000000000"]
  192. image: dougbtv/centos-network
  193. EOF
  194. when:
  195. - inventory_hostname == groups['kube-master'][0]
  196. - kube_network_plugin_multus|default(false)|bool
  197. - name: Check secondary macvlan interface
  198. command: "{{ bin_dir }}/kubectl exec samplepod -- ip addr show dev net1"
  199. register: output
  200. until: output.rc == 0
  201. retries: 90
  202. changed_when: false
  203. when:
  204. - inventory_hostname == groups['kube-master'][0]
  205. - kube_network_plugin_multus|default(false)|bool