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.

68 lines
2.3 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: Check kubectl output
  12. shell: "{{bin_dir}}/kubectl get pods --all-namespaces -owide"
  13. register: get_pods
  14. - debug: msg="{{get_pods.stdout}}"
  15. - name: Get pod names
  16. shell: "{{bin_dir}}/kubectl get pods -o json"
  17. register: pods
  18. until: '"ContainerCreating" not in pods.stdout'
  19. retries: 60
  20. delay: 2
  21. no_log: true
  22. - name: Get hostnet pods
  23. command: "{{bin_dir}}/kubectl get pods -o
  24. jsonpath='{range .items[?(.spec.hostNetwork)]}{.metadata.name} {.status.podIP} {.status.containerStatuses} {end}'"
  25. register: hostnet_pods
  26. - name: Get running pods
  27. command: "{{bin_dir}}/kubectl get pods -o
  28. jsonpath='{range .items[?(.status.phase==\"Running\")]}{.metadata.name} {.status.podIP} {.status.containerStatuses} {end}'"
  29. register: running_pods
  30. - set_fact:
  31. kube_pods_subnet: 10.233.64.0/18
  32. pod_names: "{{ (pods.stdout | from_json)['items'] | map(attribute = 'metadata.name') | list }}"
  33. pod_ips: "{{ (pods.stdout | from_json)['items'] | selectattr('status.podIP', 'defined') | map(attribute = 'status.podIP') | list }}"
  34. pods_hostnet: |
  35. {% set list = hostnet_pods.stdout.split(" ") %}
  36. {{list}}
  37. pods_running: |
  38. {% set list = running_pods.stdout.split(" ") %}
  39. {{list}}
  40. - name: Check pods IP are in correct network
  41. assert:
  42. that: item | ipaddr(kube_pods_subnet)
  43. when: not item in pods_hostnet and item in pods_running
  44. with_items: "{{pod_ips}}"
  45. - name: Ping between pods is working
  46. shell: "{{bin_dir}}/kubectl exec {{item[0]}} -- ping -c 4 {{ item[1] }}"
  47. when: not item[0] in pods_hostnet and not item[1] in pods_hostnet
  48. with_nested:
  49. - "{{pod_names}}"
  50. - "{{pod_ips}}"
  51. - name: Ping between hostnet pods is working
  52. shell: "{{bin_dir}}/kubectl exec {{item[0]}} -- ping -c 4 {{ item[1] }}"
  53. when: item[0] in pods_hostnet and item[1] in pods_hostnet
  54. with_nested:
  55. - "{{pod_names}}"
  56. - "{{pod_ips}}"