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.

80 lines
2.6 KiB

  1. ---
  2. - hosts: kube-master[0]
  3. tasks:
  4. - name: Force binaries directory for Container Linux by CoreOS
  5. set_fact:
  6. bin_dir: "/opt/bin"
  7. when: ansible_os_family in ["CoreOS", "Container Linux by CoreOS"]
  8. - set_fact:
  9. bin_dir: "/usr/local/bin"
  10. when: not ansible_os_family in ["CoreOS", "Container Linux by CoreOS"]
  11. - name: Wait for pods to be ready
  12. shell: "{{bin_dir}}/kubectl get pods -n test"
  13. register: pods
  14. until:
  15. - '"ContainerCreating" not in pods.stdout'
  16. - '"Pending" not in pods.stdout'
  17. - '"Terminating" not in pods.stdout'
  18. retries: 60
  19. delay: 2
  20. no_log: true
  21. - name: Get pod names
  22. shell: "{{bin_dir}}/kubectl get pods -n test -o json"
  23. register: pods
  24. no_log: true
  25. - name: Get hostnet pods
  26. command: "{{bin_dir}}/kubectl get pods -n test -o
  27. jsonpath='{range .items[?(.spec.hostNetwork)]}{.metadata.name} {.status.podIP} {.status.containerStatuses} {end}'"
  28. register: hostnet_pods
  29. no_log: true
  30. - name: Get running pods
  31. command: "{{bin_dir}}/kubectl get pods -n test -o
  32. jsonpath='{range .items[?(.status.phase==\"Running\")]}{.metadata.name} {.status.podIP} {.status.containerStatuses} {end}'"
  33. register: running_pods
  34. no_log: true
  35. - name: Check kubectl output
  36. shell: "{{bin_dir}}/kubectl get pods --all-namespaces -owide"
  37. register: get_pods
  38. no_log: true
  39. - debug: msg="{{get_pods.stdout.split('\n')}}"
  40. - set_fact:
  41. kube_pods_subnet: 10.233.64.0/18
  42. pod_names: "{{ (pods.stdout | from_json)['items'] | map(attribute = 'metadata.name') | list }}"
  43. pod_ips: "{{ (pods.stdout | from_json)['items'] | selectattr('status.podIP', 'defined') | map(attribute = 'status.podIP') | list }}"
  44. pods_hostnet: |
  45. {% set list = hostnet_pods.stdout.split(" ") %}
  46. {{list}}
  47. pods_running: |
  48. {% set list = running_pods.stdout.split(" ") %}
  49. {{list}}
  50. - name: Check pods IP are in correct network
  51. assert:
  52. that: item | ipaddr(kube_pods_subnet)
  53. when: not item in pods_hostnet and item in pods_running
  54. with_items: "{{pod_ips}}"
  55. - name: Ping between pods is working
  56. shell: "{{bin_dir}}/kubectl exec {{item[0]}} -- ping -c 4 {{ item[1] }}"
  57. when: not item[0] in pods_hostnet and not item[1] in pods_hostnet
  58. with_nested:
  59. - "{{pod_names}}"
  60. - "{{pod_ips}}"
  61. - name: Ping between hostnet pods is working
  62. shell: "{{bin_dir}}/kubectl exec {{item[0]}} -- ping -c 4 {{ item[1] }}"
  63. when: item[0] in pods_hostnet and item[1] in pods_hostnet
  64. with_nested:
  65. - "{{pod_names}}"
  66. - "{{pod_ips}}"