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.

218 lines
6.9 KiB

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