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.4 KiB

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