Skip to content

Commit 085beca

Browse files
authored
Merge pull request kubernetes#94854 from knight42/fix/run_kubectl_apply_tests
test(apply): deflake run_kubectl_apply_tests(round 3)
2 parents f101203 + 57619aa commit 085beca

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

test/cmd/apply.sh

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ __EOF__
159159
# Dry-run create the CR
160160
kubectl "${kube_flags[@]:?}" apply --dry-run=server -f hack/testdata/CRD/resource.yaml "${kube_flags[@]:?}"
161161
# Make sure that the CR doesn't exist
162-
! kubectl "${kube_flags[@]:?}" get resource/myobj || exit 1
162+
! kubectl "${kube_flags[@]:?}" get resource/myobj 2>/dev/null || exit 1
163163

164164
# clean-up
165165
kubectl "${kube_flags[@]:?}" delete customresourcedefinition resources.mygroup.example.com
@@ -173,11 +173,8 @@ __EOF__
173173
kube::test::get_object_assert 'pods a -n nsb' "{{${id_field:?}}}" 'a'
174174
# apply b with namespace
175175
kubectl apply --namespace nsb --prune -l prune-group=true -f hack/testdata/prune/b.yaml "${kube_flags[@]:?}"
176-
# check right pod exists
177-
kube::test::get_object_assert 'pods b -n nsb' "{{${id_field:?}}}" 'b'
178-
# check wrong pod doesn't exist
179-
output_message=$(! kubectl get pods a -n nsb 2>&1 "${kube_flags[@]:?}")
180-
kube::test::if_has_string "${output_message}" 'pods "a" not found'
176+
# check right pod exists and wrong pod doesn't exist
177+
kube::test::wait_object_assert 'pods -n nsb' "{{range.items}}{{${id_field:?}}}:{{end}}" 'b:'
181178

182179
# cleanup
183180
kubectl delete pods b -n nsb
@@ -191,8 +188,7 @@ __EOF__
191188
# check right pod exists
192189
kube::test::get_object_assert 'pods a' "{{${id_field:?}}}" 'a'
193190
# check wrong pod doesn't exist
194-
output_message=$(! kubectl get pods b -n nsb 2>&1 "${kube_flags[@]:?}")
195-
kube::test::if_has_string "${output_message}" 'pods "b" not found'
191+
kube::test::wait_object_assert 'pods -n nsb' "{{range.items}}{{${id_field:?}}}:{{end}}" ''
196192

197193
# apply b
198194
kubectl apply -l prune-group=true -f hack/testdata/prune/b.yaml "${kube_flags[@]:?}"
@@ -254,11 +250,8 @@ __EOF__
254250
kube::test::get_object_assert 'pods b -n nsb' "{{${id_field:?}}}" 'b'
255251
# apply --prune must prune a
256252
kubectl apply --prune --all -f hack/testdata/prune/b.yaml
257-
# check wrong pod doesn't exist
258-
output_message=$(! kubectl get pods a -n nsb 2>&1 "${kube_flags[@]:?}")
259-
kube::test::if_has_string "${output_message}" 'pods "a" not found'
260-
# check right pod exists
261-
kube::test::get_object_assert 'pods b -n nsb' "{{${id_field:?}}}" 'b'
253+
# check wrong pod doesn't exist and right pod exists
254+
kube::test::wait_object_assert 'pods -n nsb' "{{range.items}}{{${id_field:?}}}:{{end}}" 'b:'
262255

263256
# cleanup
264257
kubectl delete ns nsb
@@ -471,7 +464,7 @@ __EOF__
471464
# Dry-run create the CR
472465
kubectl "${kube_flags[@]:?}" apply --server-side --dry-run=server -f hack/testdata/CRD/resource.yaml "${kube_flags[@]:?}"
473466
# Make sure that the CR doesn't exist
474-
! kubectl "${kube_flags[@]:?}" get resource/myobj || exit 1
467+
! kubectl "${kube_flags[@]:?}" get resource/myobj 2>/dev/null || exit 1
475468

476469
# clean-up
477470
kubectl "${kube_flags[@]:?}" delete customresourcedefinition resources.mygroup.example.com

0 commit comments

Comments
 (0)