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.

108 lines
3.6 KiB

  1. ---
  2. - hosts: kube-master[0]
  3. vars:
  4. test_image_repo: busybox
  5. test_image_tag: latest
  6. tasks:
  7. - name: Force binaries directory for Container Linux by CoreOS and Flatcar
  8. set_fact:
  9. bin_dir: "/opt/bin"
  10. when: ansible_os_family in ["CoreOS", "Coreos", "Container Linux by CoreOS", "Flatcar", "Flatcar Container Linux by Kinvolk"]
  11. - name: Force binaries directory for other hosts
  12. set_fact:
  13. bin_dir: "/usr/local/bin"
  14. when: not ansible_os_family in ["CoreOS", "Coreos", "Container Linux by CoreOS", "Flatcar", "Flatcar Container Linux by Kinvolk"]
  15. - name: Create test namespace
  16. shell: "{{ bin_dir }}/kubectl create namespace test"
  17. - name: Run 2 busybox pods in test ns
  18. shell: "{{ bin_dir }}/kubectl run {{ item }} --image={{ test_image_repo }}:{{ test_image_tag }} --namespace test --command -- tail -f /dev/null"
  19. loop:
  20. - busybox1
  21. - busybox2
  22. - import_role:
  23. name: cluster-dump
  24. - name: Check that all pods are running and ready
  25. shell: "{{ bin_dir }}/kubectl get pods --namespace test --no-headers -o yaml"
  26. register: run_pods_log
  27. until:
  28. # Check that all pods are running
  29. - '(run_pods_log.stdout | from_yaml)["items"] | map(attribute = "status.phase") | unique | list == ["Running"]'
  30. # Check that all pods are ready
  31. - '(run_pods_log.stdout | from_yaml)["items"] | map(attribute = "status.containerStatuses") | map("map", attribute = "ready") | map("min") | min'
  32. retries: 18
  33. delay: 10
  34. failed_when: false
  35. no_log: true
  36. - name: Get pod names
  37. shell: "{{ bin_dir }}/kubectl get pods -n test -o json"
  38. register: pods
  39. no_log: true
  40. - debug:
  41. msg: "{{ pods.stdout.split('\n') }}"
  42. failed_when: not run_pods_log is success
  43. - name: Get hostnet pods
  44. command: "{{ bin_dir }}/kubectl get pods -n test -o
  45. jsonpath='{range .items[?(.spec.hostNetwork)]}{.metadata.name} {.status.podIP} {.status.containerStatuses} {end}'"
  46. register: hostnet_pods
  47. no_log: true
  48. - name: Get running pods
  49. command: "{{ bin_dir }}/kubectl get pods -n test -o
  50. jsonpath='{range .items[?(.status.phase==\"Running\")]}{.metadata.name} {.status.podIP} {.status.containerStatuses} {end}'"
  51. register: running_pods
  52. no_log: true
  53. - name: Check kubectl output
  54. shell: "{{ bin_dir }}/kubectl get pods --all-namespaces -owide"
  55. register: get_pods
  56. no_log: true
  57. - debug:
  58. msg: "{{ get_pods.stdout.split('\n') }}"
  59. - name: Set networking facts
  60. set_fact:
  61. kube_pods_subnet: 10.233.64.0/18
  62. pod_names: "{{ (pods.stdout | from_json)['items'] | map(attribute = 'metadata.name') | list }}"
  63. pod_ips: "{{ (pods.stdout | from_json)['items'] | selectattr('status.podIP', 'defined') | map(attribute = 'status.podIP') | list }}"
  64. pods_hostnet: |
  65. {% set list = hostnet_pods.stdout.split(" ") %}
  66. {{ list }}
  67. pods_running: |
  68. {% set list = running_pods.stdout.split(" ") %}
  69. {{ list }}
  70. - name: Check pods IP are in correct network
  71. assert:
  72. that: item | ipaddr(kube_pods_subnet)
  73. when:
  74. - not item in pods_hostnet
  75. - item in pods_running
  76. with_items: "{{ pod_ips }}"
  77. - name: Ping between pods is working
  78. shell: "{{ bin_dir }}/kubectl -n test exec {{ item[0] }} -- ping -c 4 {{ item[1] }}"
  79. when:
  80. - not item[0] in pods_hostnet
  81. - not item[1] in pods_hostnet
  82. with_nested:
  83. - "{{ pod_names }}"
  84. - "{{ pod_ips }}"
  85. - name: Ping between hostnet pods is working
  86. shell: "{{ bin_dir }}/kubectl -n test exec {{ item[0] }} -- ping -c 4 {{ item[1] }}"
  87. when:
  88. - item[0] in pods_hostnet
  89. - item[1] in pods_hostnet
  90. with_nested:
  91. - "{{ pod_names }}"
  92. - "{{ pod_ips }}"