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.

140 lines
4.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 Flatcar Container Linux by Kinvolk
  8. set_fact:
  9. bin_dir: "/opt/bin"
  10. when: ansible_os_family in ["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 ["Flatcar Container Linux by Kinvolk"]
  15. - name: Approve kubelet serving certificates
  16. block:
  17. - name: Get certificate signing requests
  18. command: "{{ bin_dir }}/kubectl get csr -o name"
  19. register: get_csr
  20. changed_when: false
  21. - name: Check there are csrs
  22. assert:
  23. that: get_csr.stdout_lines | length > 0
  24. fail_msg: kubelet_rotate_server_certificates is {{ kubelet_rotate_server_certificates }} but no csr's found
  25. - name: Approve certificates
  26. command: "{{ bin_dir }}/kubectl certificate approve {{ get_csr.stdout_lines | join(' ') }}"
  27. register: certificate_approve
  28. when: get_csr.stdout_lines | length > 0
  29. changed_when: certificate_approve.stdout
  30. - debug:
  31. msg: "{{ certificate_approve.stdout.split('\n') }}"
  32. when: kubelet_rotate_server_certificates | default(false)
  33. - name: Create test namespace
  34. command: "{{ bin_dir }}/kubectl create namespace test"
  35. changed_when: false
  36. - name: Run 2 busybox pods in test ns
  37. command: "{{ bin_dir }}/kubectl run {{ item }} --image={{ test_image_repo }}:{{ test_image_tag }} --namespace test --command -- tail -f /dev/null"
  38. changed_when: false
  39. loop:
  40. - busybox1
  41. - busybox2
  42. - import_role:
  43. name: cluster-dump
  44. - name: Check that all pods are running and ready
  45. command: "{{ bin_dir }}/kubectl get pods --namespace test --no-headers -o yaml"
  46. changed_when: false
  47. register: run_pods_log
  48. until:
  49. # Check that all pods are running
  50. - '(run_pods_log.stdout | from_yaml)["items"] | map(attribute = "status.phase") | unique | list == ["Running"]'
  51. # Check that all pods are ready
  52. - '(run_pods_log.stdout | from_yaml)["items"] | map(attribute = "status.containerStatuses") | map("map", attribute = "ready") | map("min") | min'
  53. retries: 18
  54. delay: 10
  55. failed_when: false
  56. no_log: true
  57. - name: Get pod names
  58. command: "{{ bin_dir }}/kubectl get pods -n test -o json"
  59. changed_when: false
  60. register: pods
  61. no_log: true
  62. - debug:
  63. msg: "{{ pods.stdout.split('\n') }}"
  64. failed_when: not run_pods_log is success
  65. - name: Get hostnet pods
  66. command: "{{ bin_dir }}/kubectl get pods -n test -o
  67. jsonpath='{range .items[?(.spec.hostNetwork)]}{.metadata.name} {.status.podIP} {.status.containerStatuses} {end}'"
  68. changed_when: false
  69. register: hostnet_pods
  70. ignore_errors: true
  71. no_log: true
  72. - name: Get running pods
  73. command: "{{ bin_dir }}/kubectl get pods -n test -o
  74. jsonpath='{range .items[?(.status.phase==\"Running\")]}{.metadata.name} {.status.podIP} {.status.containerStatuses} {end}'"
  75. changed_when: False
  76. register: running_pods
  77. no_log: true
  78. - name: Check kubectl output
  79. command: "{{ bin_dir }}/kubectl get pods --all-namespaces -owide"
  80. changed_when: False
  81. register: get_pods
  82. no_log: true
  83. - debug:
  84. msg: "{{ get_pods.stdout.split('\n') }}"
  85. - name: Set networking facts
  86. set_fact:
  87. kube_pods_subnet: 10.233.64.0/18
  88. pod_names: "{{ (pods.stdout | from_json)['items'] | map(attribute = 'metadata.name') | list }}"
  89. pod_ips: "{{ (pods.stdout | from_json)['items'] | selectattr('status.podIP', 'defined') | map(attribute = 'status.podIP') | list }}"
  90. pods_hostnet: |
  91. {% set list = hostnet_pods.stdout.split(" ") %}
  92. {{ list }}
  93. pods_running: |
  94. {% set list = running_pods.stdout.split(" ") %}
  95. {{ list }}
  96. - name: Check pods IP are in correct network
  97. assert:
  98. that: item | ipaddr(kube_pods_subnet)
  99. when:
  100. - not item in pods_hostnet
  101. - item in pods_running
  102. with_items: "{{ pod_ips }}"
  103. - name: Ping between pods is working
  104. command: "{{ bin_dir }}/kubectl -n test exec {{ item[0] }} -- ping -c 4 {{ item[1] }}"
  105. when:
  106. - not item[0] in pods_hostnet
  107. - not item[1] in pods_hostnet
  108. with_nested:
  109. - "{{ pod_names }}"
  110. - "{{ pod_ips }}"
  111. - name: Ping between hostnet pods is working
  112. command: "{{ bin_dir }}/kubectl -n test exec {{ item[0] }} -- ping -c 4 {{ item[1] }}"
  113. when:
  114. - item[0] in pods_hostnet
  115. - item[1] in pods_hostnet
  116. with_nested:
  117. - "{{ pod_names }}"
  118. - "{{ pod_ips }}"