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.

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