Skip to content

Commit 30f0a14

Browse files
authored
Merge pull request #11792 from VannTen/flake/race_sa_creation
Fix flakey test + cleanup in testcases/030-checknetwork
2 parents acfaef2 + 12ed1fc commit 30f0a14

File tree

1 file changed

+33
-62
lines changed

1 file changed

+33
-62
lines changed

tests/testcases/030_check-network.yml

Lines changed: 33 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -79,60 +79,47 @@
7979
command:
8080
cmd: "{{ bin_dir }}/kubectl apply -f -"
8181
stdin: |
82-
apiVersion: v1
83-
kind: Pod
82+
apiVersion: apps/v1
83+
kind: Deployment
8484
metadata:
85-
name: {{ item }}
86-
namespace: test
85+
name: agnhost
8786
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
100108
changed_when: false
101-
loop:
102-
- agnhost1
103-
- agnhost2
104109

105110
- import_role: # noqa name[missing]
106111
name: cluster-dump
107112

108113
- 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
136123

137124
- name: Get running pods
138125
command: "{{ bin_dir }}/kubectl get pods -n test -o
@@ -153,9 +140,6 @@
153140
kube_pods_subnet: 10.233.64.0/18
154141
pod_names: "{{ (pods.stdout | from_json)['items'] | map(attribute='metadata.name') | list }}"
155142
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 }}
159143
pods_running: |
160144
{% set list = running_pods.stdout.split(" ") %}
161145
{{ list }}
@@ -164,24 +148,11 @@
164148
assert:
165149
that: item | ansible.utils.ipaddr(kube_pods_subnet)
166150
when:
167-
- not item in pods_hostnet
168151
- item in pods_running
169152
with_items: "{{ pod_ips }}"
170153

171154
- name: Curl between pods is working
172155
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
185156
with_nested:
186157
- "{{ pod_names }}"
187158
- "{{ pod_ips }}"

0 commit comments

Comments
 (0)