|
4 | 4 | vars: |
5 | 5 | test_image_repo: registry.k8s.io/e2e-test-images/agnhost |
6 | 6 | test_image_tag: "2.40" |
| 7 | + bin_dir: "/usr/local/bin" |
7 | 8 |
|
8 | 9 | tasks: |
9 | | - - name: Force binaries directory for Flatcar Container Linux by Kinvolk |
10 | | - set_fact: |
11 | | - bin_dir: "/opt/bin" |
12 | | - when: ansible_os_family in ["Flatcar", "Flatcar Container Linux by Kinvolk"] |
13 | | - |
14 | | - - name: Force binaries directory for other hosts |
15 | | - set_fact: |
16 | | - bin_dir: "/usr/local/bin" |
17 | | - when: not ansible_os_family in ["Flatcar", "Flatcar Container Linux by Kinvolk"] |
18 | 10 |
|
19 | 11 | - name: Check kubelet serving certificates approved with kubelet_csr_approver |
20 | 12 | when: |
|
29 | 21 | register: csr_json |
30 | 22 | changed_when: false |
31 | 23 |
|
32 | | - - debug: # noqa name[missing] |
33 | | - var: csrs |
34 | | - |
35 | 24 | - name: Check there are csrs |
36 | 25 | assert: |
37 | 26 | that: csrs | length > 0 |
|
67 | 56 | when: get_csr.stdout_lines | length > 0 |
68 | 57 | changed_when: certificate_approve.stdout |
69 | 58 |
|
70 | | - - debug: # noqa name[missing] |
71 | | - msg: "{{ certificate_approve.stdout.split('\n') }}" |
72 | | - |
73 | | - |
74 | 59 | - name: Create test namespace |
75 | 60 | command: "{{ bin_dir }}/kubectl create namespace test" |
76 | 61 | changed_when: false |
77 | 62 |
|
78 | 63 | - name: Run 2 agnhost pods in test ns |
79 | 64 | command: |
80 | | - cmd: "{{ bin_dir }}/kubectl apply -f -" |
| 65 | + cmd: "{{ bin_dir }}/kubectl apply --namespace test -f -" |
81 | 66 | stdin: | |
82 | 67 | apiVersion: apps/v1 |
83 | 68 | kind: Deployment |
|
107 | 92 | type: RuntimeDefault |
108 | 93 | changed_when: false |
109 | 94 |
|
110 | | - - import_role: # noqa name[missing] |
111 | | - name: cluster-dump |
112 | | - |
113 | 95 | - name: Check that all pods are running and ready |
| 96 | + vars: |
| 97 | + pods: "{{ (pods_json.stdout | from_json)['items'] }}" |
114 | 98 | block: |
115 | 99 | - name: Check Deployment is ready |
116 | | - command: "{{ bin_dir }}/kubectl rollout status deploy --namespace test agnhost --timeout=180" |
| 100 | + command: "{{ bin_dir }}/kubectl rollout status deploy --namespace test agnhost --timeout=180s" |
117 | 101 | changed_when: false |
118 | | - rescue: |
119 | 102 | - name: Get pod names |
120 | 103 | command: "{{ bin_dir }}/kubectl get pods -n test -o json" |
121 | 104 | changed_when: false |
122 | | - register: pods |
| 105 | + register: pods_json |
123 | 106 |
|
124 | | - - name: Get running pods |
125 | | - command: "{{ bin_dir }}/kubectl get pods -n test -o |
126 | | - jsonpath='{range .items[?(.status.phase==\"Running\")]}{.metadata.name} {.status.podIP} {.status.containerStatuses} {end}'" |
127 | | - changed_when: false |
128 | | - register: running_pods |
| 107 | + - name: Check pods IP are in correct network |
| 108 | + assert: |
| 109 | + that: pods |
| 110 | + | selectattr('status.phase', '==', 'Running') |
| 111 | + | selectattr('status.podIP', 'ansible.utils.in_network', kube_pods_subnet) |
| 112 | + | length == 2 |
| 113 | + |
| 114 | + - name: Curl between pods is working |
| 115 | + command: "{{ bin_dir }}/kubectl -n test exec {{ item[0].metadata.name }} -- curl {{ item[1].status.podIP }}:8080" |
| 116 | + with_nested: |
| 117 | + - "{{ pods }}" |
| 118 | + - "{{ pods }}" |
| 119 | + rescue: |
| 120 | + - name: List pods cluster-wide |
| 121 | + command: "{{ bin_dir }}/kubectl get pods --all-namespaces -owide" |
| 122 | + changed_when: false |
129 | 123 |
|
130 | | - - name: Check kubectl output |
131 | | - command: "{{ bin_dir }}/kubectl get pods --all-namespaces -owide" |
132 | | - changed_when: false |
133 | | - register: get_pods |
134 | | - |
135 | | - - debug: # noqa name[missing] |
136 | | - msg: "{{ get_pods.stdout.split('\n') }}" |
137 | | - |
138 | | - - name: Set networking facts |
139 | | - set_fact: |
140 | | - kube_pods_subnet: 10.233.64.0/18 |
141 | | - pod_names: "{{ (pods.stdout | from_json)['items'] | map(attribute='metadata.name') | list }}" |
142 | | - pod_ips: "{{ (pods.stdout | from_json)['items'] | selectattr('status.podIP', 'defined') | map(attribute='status.podIP') | list }}" |
143 | | - pods_running: | |
144 | | - {% set list = running_pods.stdout.split(" ") %} |
145 | | - {{ list }} |
146 | | -
|
147 | | - - name: Check pods IP are in correct network |
148 | | - assert: |
149 | | - that: item | ansible.utils.ipaddr(kube_pods_subnet) |
150 | | - when: |
151 | | - - item in pods_running |
152 | | - with_items: "{{ pod_ips }}" |
153 | | - |
154 | | - - name: Curl between pods is working |
155 | | - command: "{{ bin_dir }}/kubectl -n test exec {{ item[0] }} -- curl {{ item[1] }}:8080" |
156 | | - with_nested: |
157 | | - - "{{ pod_names }}" |
158 | | - - "{{ pod_ips }}" |
| 124 | + - import_role: # noqa name[missing] |
| 125 | + name: cluster-dump |
| 126 | + - fail: # noqa name[missing] |
0 commit comments