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.

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