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.

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