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.

161 lines
5.4 KiB

  1. ---
  2. - name: Testcases for calico
  3. hosts: kube_node
  4. tasks:
  5. - name: Test tunl0 routes
  6. command: "/sbin/ip route"
  7. register: routes
  8. failed_when: routes.stdout_lines
  9. | select('contains', '/' ~ calico_pool_blocksize|d(26))
  10. | select('contains', 'tunl0') | length == 0
  11. when:
  12. - (calico_ipip_mode is defined and calico_ipip_mode != 'Never')
  13. - kube_network_plugin | default('calico') == 'calico'
  14. - name: Advanced testcases for network
  15. hosts: k8s_cluster
  16. vars:
  17. agent_report_interval: 10
  18. netcheck_namespace: default
  19. netchecker_port: 31081
  20. bin_dir: "/usr/local/bin"
  21. tasks:
  22. - import_role: # noqa name[missing]
  23. name: cluster-dump
  24. - name: Wait for netchecker server
  25. command: "{{ bin_dir }}/kubectl get pods --field-selector=status.phase==Running -o jsonpath-as-json={.items[*].metadata.name} --namespace {{ netcheck_namespace }}"
  26. register: pods_json
  27. until:
  28. - pods_json.stdout | from_json | select('match', 'netchecker-server.*') | length == 1
  29. - (pods_json.stdout | from_json | select('match', 'netchecker-agent.*') | length)
  30. >= (groups['k8s_cluster'] | intersect(ansible_play_hosts) | length * 2)
  31. retries: 3
  32. delay: 10
  33. when: inventory_hostname == groups['kube_control_plane'][0]
  34. - name: Get netchecker pods
  35. command: "{{ bin_dir }}/kubectl -n {{ netcheck_namespace }} describe pod -l app={{ item }}"
  36. run_once: true
  37. delegate_to: "{{ groups['kube_control_plane'][0] }}"
  38. with_items:
  39. - netchecker-agent
  40. - netchecker-agent-hostnet
  41. when: not pods_json is success
  42. - name: Perform netchecker tests
  43. run_once: true
  44. delegate_to: "{{ groups['kube_control_plane'][0] }}"
  45. block:
  46. - name: Get netchecker agents
  47. uri:
  48. url: "http://{{ ansible_default_ipv4.address }}:{{ netchecker_port }}/api/v1/agents/"
  49. return_content: true
  50. headers:
  51. Accept: application/json
  52. register: agents
  53. retries: 18
  54. delay: "{{ agent_report_interval }}"
  55. until:
  56. - agents is success
  57. - (agents.content | from_json | length) == (groups['k8s_cluster'] | length * 2)
  58. - name: Check netchecker status
  59. uri:
  60. url: "http://{{ ansible_default_ipv4.address }}:{{ netchecker_port }}/api/v1/connectivity_check"
  61. return_content: true
  62. headers:
  63. Accept: application/json
  64. register: connectivity_check
  65. retries: 3
  66. delay: "{{ agent_report_interval }}"
  67. until:
  68. - connectivity_check is success
  69. - connectivity_check.content | from_json
  70. rescue:
  71. - name: Get kube-proxy logs
  72. command: "{{ bin_dir }}/kubectl -n kube-system logs -l k8s-app=kube-proxy"
  73. - name: Get logs from other apps
  74. command: "{{ bin_dir }}/kubectl -n kube-system logs -l k8s-app={{ item }} --all-containers"
  75. with_items:
  76. - kube-router
  77. - flannel
  78. - canal-node
  79. - calico-node
  80. - cilium
  81. - name: Netchecker tests failed
  82. fail:
  83. msg: "netchecker tests failed"
  84. - name: Check connectivity with all netchecker agents
  85. vars:
  86. connectivity_check_result: "{{ connectivity_check.content | from_json }}"
  87. agents_check_result: "{{ agents.content | from_json }}"
  88. assert:
  89. that:
  90. - agents_check_result is defined
  91. - connectivity_check_result is defined
  92. - agents_check_result.keys() | length > 0
  93. - not connectivity_check_result.Absent
  94. - not connectivity_check_result.Outdated
  95. msg: "Connectivity check to netchecker agents failed"
  96. delegate_to: "{{ groups['kube_control_plane'][0] }}"
  97. run_once: true
  98. - name: Create macvlan network conf
  99. command:
  100. cmd: "{{ bin_dir }}/kubectl create -f -"
  101. stdin: |
  102. apiVersion: "k8s.cni.cncf.io/v1"
  103. kind: NetworkAttachmentDefinition
  104. metadata:
  105. name: macvlan-conf
  106. spec:
  107. config: '{
  108. "cniVersion": "0.4.0",
  109. "type": "macvlan",
  110. "master": "eth0",
  111. "mode": "bridge",
  112. "ipam": {
  113. "type": "host-local",
  114. "subnet": "192.168.1.0/24",
  115. "rangeStart": "192.168.1.200",
  116. "rangeEnd": "192.168.1.216",
  117. "routes": [
  118. { "dst": "0.0.0.0/0" }
  119. ],
  120. "gateway": "192.168.1.1"
  121. }
  122. }'
  123. ---
  124. apiVersion: v1
  125. kind: Pod
  126. metadata:
  127. name: samplepod
  128. annotations:
  129. k8s.v1.cni.cncf.io/networks: macvlan-conf
  130. spec:
  131. containers:
  132. - name: samplepod
  133. command: ["/bin/bash", "-c", "sleep 2000000000000"]
  134. image: dougbtv/centos-network
  135. delegate_to: groups['kube_control_plane'][0]
  136. run_once: true
  137. when:
  138. - kube_network_plugin_multus | default(false) | bool
  139. - name: Check secondary macvlan interface
  140. command: "{{ bin_dir }}/kubectl exec samplepod -- ip addr show dev net1"
  141. register: output
  142. until: output.rc == 0
  143. retries: 90
  144. changed_when: false
  145. delegate_to: groups['kube_control_plane'][0]
  146. run_once: true
  147. when:
  148. - kube_network_plugin_multus | default(false) | bool