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.

105 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 a replica controller composed of 2 pods in test ns
  18. shell: "{{ bin_dir }}/kubectl run test --image={{ test_image_repo }}:{{ test_image_tag }} --namespace test --replicas=2 --command -- tail -f /dev/null"
  19. - import_role:
  20. name: cluster-dump
  21. - name: Check that all pods are running and ready
  22. shell: "{{ bin_dir }}/kubectl get pods --namespace test --no-headers -o yaml"
  23. register: run_pods_log
  24. until:
  25. # Check that all pods are running
  26. - '(run_pods_log.stdout | from_yaml)["items"] | map(attribute = "status.phase") | unique | list == ["Running"]'
  27. # Check that all pods are ready
  28. - '(run_pods_log.stdout | from_yaml)["items"] | map(attribute = "status.containerStatuses") | map("map", attribute = "ready") | map("min") | min'
  29. retries: 18
  30. delay: 10
  31. failed_when: false
  32. no_log: true
  33. - name: Get pod names
  34. shell: "{{ bin_dir }}/kubectl get pods -n test -o json"
  35. register: pods
  36. no_log: true
  37. - debug:
  38. msg: "{{ pods.stdout.split('\n') }}"
  39. failed_when: not run_pods_log is success
  40. - name: Get hostnet pods
  41. command: "{{ bin_dir }}/kubectl get pods -n test -o
  42. jsonpath='{range .items[?(.spec.hostNetwork)]}{.metadata.name} {.status.podIP} {.status.containerStatuses} {end}'"
  43. register: hostnet_pods
  44. no_log: true
  45. - name: Get running pods
  46. command: "{{ bin_dir }}/kubectl get pods -n test -o
  47. jsonpath='{range .items[?(.status.phase==\"Running\")]}{.metadata.name} {.status.podIP} {.status.containerStatuses} {end}'"
  48. register: running_pods
  49. no_log: true
  50. - name: Check kubectl output
  51. shell: "{{ bin_dir }}/kubectl get pods --all-namespaces -owide"
  52. register: get_pods
  53. no_log: true
  54. - debug:
  55. msg: "{{ get_pods.stdout.split('\n') }}"
  56. - name: Set networking facts
  57. set_fact:
  58. kube_pods_subnet: 10.233.64.0/18
  59. pod_names: "{{ (pods.stdout | from_json)['items'] | map(attribute = 'metadata.name') | list }}"
  60. pod_ips: "{{ (pods.stdout | from_json)['items'] | selectattr('status.podIP', 'defined') | map(attribute = 'status.podIP') | list }}"
  61. pods_hostnet: |
  62. {% set list = hostnet_pods.stdout.split(" ") %}
  63. {{ list }}
  64. pods_running: |
  65. {% set list = running_pods.stdout.split(" ") %}
  66. {{ list }}
  67. - name: Check pods IP are in correct network
  68. assert:
  69. that: item | ipaddr(kube_pods_subnet)
  70. when:
  71. - not item in pods_hostnet
  72. - item in pods_running
  73. with_items: "{{ pod_ips }}"
  74. - name: Ping between pods is working
  75. shell: "{{ bin_dir }}/kubectl -n test exec {{ item[0] }} -- ping -c 4 {{ item[1] }}"
  76. when:
  77. - not item[0] in pods_hostnet
  78. - not item[1] in pods_hostnet
  79. with_nested:
  80. - "{{ pod_names }}"
  81. - "{{ pod_ips }}"
  82. - name: Ping between hostnet pods is working
  83. shell: "{{ bin_dir }}/kubectl -n test exec {{ item[0] }} -- ping -c 4 {{ item[1] }}"
  84. when:
  85. - item[0] in pods_hostnet
  86. - item[1] in pods_hostnet
  87. with_nested:
  88. - "{{ pod_names }}"
  89. - "{{ pod_ips }}"