|
79 | 79 | command:
|
80 | 80 | cmd: "{{ bin_dir }}/kubectl apply -f -"
|
81 | 81 | stdin: |
|
82 |
| - apiVersion: v1 |
83 |
| - kind: Pod |
| 82 | + apiVersion: apps/v1 |
| 83 | + kind: Deployment |
84 | 84 | metadata:
|
85 |
| - name: {{ item }} |
86 |
| - namespace: test |
| 85 | + name: agnhost |
87 | 86 | spec:
|
88 |
| - containers: |
89 |
| - - name: agnhost |
90 |
| - image: {{ test_image_repo }}:{{ test_image_tag }} |
91 |
| - command: ['/agnhost', 'netexec', '--http-port=8080'] |
92 |
| - securityContext: |
93 |
| - allowPrivilegeEscalation: false |
94 |
| - capabilities: |
95 |
| - drop: ['ALL'] |
96 |
| - runAsUser: 1000 |
97 |
| - runAsNonRoot: true |
98 |
| - seccompProfile: |
99 |
| - type: RuntimeDefault |
| 87 | + replicas: 2 |
| 88 | + selector: |
| 89 | + matchLabels: |
| 90 | + app: agnhost |
| 91 | + template: |
| 92 | + metadata: |
| 93 | + labels: |
| 94 | + app: agnhost |
| 95 | + spec: |
| 96 | + containers: |
| 97 | + - name: agnhost |
| 98 | + image: {{ test_image_repo }}:{{ test_image_tag }} |
| 99 | + command: ['/agnhost', 'netexec', '--http-port=8080'] |
| 100 | + securityContext: |
| 101 | + allowPrivilegeEscalation: false |
| 102 | + capabilities: |
| 103 | + drop: ['ALL'] |
| 104 | + runAsUser: 1000 |
| 105 | + runAsNonRoot: true |
| 106 | + seccompProfile: |
| 107 | + type: RuntimeDefault |
100 | 108 | changed_when: false
|
101 |
| - loop: |
102 |
| - - agnhost1 |
103 |
| - - agnhost2 |
104 | 109 |
|
105 | 110 | - import_role: # noqa name[missing]
|
106 | 111 | name: cluster-dump
|
107 | 112 |
|
108 | 113 | - name: Check that all pods are running and ready
|
109 |
| - command: "{{ bin_dir }}/kubectl get pods --namespace test --no-headers -o yaml" |
110 |
| - changed_when: false |
111 |
| - register: run_pods_log |
112 |
| - until: |
113 |
| - # Check that all pods are running |
114 |
| - - '(run_pods_log.stdout | from_yaml)["items"] | map(attribute = "status.phase") | unique | list == ["Running"]' |
115 |
| - # Check that all pods are ready |
116 |
| - - '(run_pods_log.stdout | from_yaml)["items"] | map(attribute = "status.containerStatuses") | map("map", attribute = "ready") | map("min") | min' |
117 |
| - retries: 18 |
118 |
| - delay: 10 |
119 |
| - failed_when: false |
120 |
| - |
121 |
| - - name: Get pod names |
122 |
| - command: "{{ bin_dir }}/kubectl get pods -n test -o json" |
123 |
| - changed_when: false |
124 |
| - register: pods |
125 |
| - |
126 |
| - - debug: # noqa name[missing] |
127 |
| - msg: "{{ pods.stdout.split('\n') }}" |
128 |
| - failed_when: not run_pods_log is success |
129 |
| - |
130 |
| - - name: Get hostnet pods |
131 |
| - command: "{{ bin_dir }}/kubectl get pods -n test -o |
132 |
| - jsonpath='{range .items[?(.spec.hostNetwork)]}{.metadata.name} {.status.podIP} {.status.containerStatuses} {end}'" |
133 |
| - changed_when: false |
134 |
| - register: hostnet_pods |
135 |
| - ignore_errors: true # noqa ignore-errors |
| 114 | + block: |
| 115 | + - name: Check Deployment is ready |
| 116 | + command: "{{ bin_dir }}/kubectl rollout status deploy --namespace test agnhost --timeout=180" |
| 117 | + changed_when: false |
| 118 | + rescue: |
| 119 | + - name: Get pod names |
| 120 | + command: "{{ bin_dir }}/kubectl get pods -n test -o json" |
| 121 | + changed_when: false |
| 122 | + register: pods |
136 | 123 |
|
137 | 124 | - name: Get running pods
|
138 | 125 | command: "{{ bin_dir }}/kubectl get pods -n test -o
|
|
153 | 140 | kube_pods_subnet: 10.233.64.0/18
|
154 | 141 | pod_names: "{{ (pods.stdout | from_json)['items'] | map(attribute='metadata.name') | list }}"
|
155 | 142 | pod_ips: "{{ (pods.stdout | from_json)['items'] | selectattr('status.podIP', 'defined') | map(attribute='status.podIP') | list }}"
|
156 |
| - pods_hostnet: | |
157 |
| - {% set list = hostnet_pods.stdout.split(" ") %} |
158 |
| - {{ list }} |
159 | 143 | pods_running: |
|
160 | 144 | {% set list = running_pods.stdout.split(" ") %}
|
161 | 145 | {{ list }}
|
|
164 | 148 | assert:
|
165 | 149 | that: item | ansible.utils.ipaddr(kube_pods_subnet)
|
166 | 150 | when:
|
167 |
| - - not item in pods_hostnet |
168 | 151 | - item in pods_running
|
169 | 152 | with_items: "{{ pod_ips }}"
|
170 | 153 |
|
171 | 154 | - name: Curl between pods is working
|
172 | 155 | command: "{{ bin_dir }}/kubectl -n test exec {{ item[0] }} -- curl {{ item[1] }}:8080"
|
173 |
| - when: |
174 |
| - - not item[0] in pods_hostnet |
175 |
| - - not item[1] in pods_hostnet |
176 |
| - with_nested: |
177 |
| - - "{{ pod_names }}" |
178 |
| - - "{{ pod_ips }}" |
179 |
| - |
180 |
| - - name: Curl between hostnet pods is working |
181 |
| - command: "{{ bin_dir }}/kubectl -n test exec {{ item[0] }} -- curl {{ item[1] }}:8080" |
182 |
| - when: |
183 |
| - - item[0] in pods_hostnet |
184 |
| - - item[1] in pods_hostnet |
185 | 156 | with_nested:
|
186 | 157 | - "{{ pod_names }}"
|
187 | 158 | - "{{ pod_ips }}"
|
0 commit comments