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.

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