Adds integration test for apply failures when applying multiple resources

This commit is contained in:
Sean R. Sullivan 2020-03-26 22:33:04 -07:00
parent b75990cc7b
commit 1083c0fe05
2 changed files with 32 additions and 0 deletions

19
hack/testdata/multi-resource.yaml vendored Normal file
View File

@ -0,0 +1,19 @@
# Tests that initial failures to not block subsequent applies.
# Pod must be before namespace, so it initially fails. Second
# apply of pod should succeed, since namespace finally exists.
apiVersion: v1
kind: Pod
metadata:
name: test-pod
namespace: multi-resource-ns
labels:
name: test-pod-label
spec:
containers:
- name: kubernetes-pause
image: k8s.gcr.io/pause:2.0
---
apiVersion: v1
kind: Namespace
metadata:
name: multi-resource-ns

View File

@ -274,6 +274,19 @@ __EOF__
# cleanup # cleanup
kubectl delete --kustomize hack/testdata/kustomize kubectl delete --kustomize hack/testdata/kustomize
## kubectl apply multiple resources with initial failure.
# Pre-Condition: no POD exists
kube::test::get_object_assert pods "{{range.items}}{{${id_field:?}}}:{{end}}" ''
# First pass, namespace is created, but pod is not (since namespace does not exist yet).
kubectl apply -f hack/testdata/multi-resource.yaml "${kube_flags[@]:?}"
output_message=$(! kubectl get pods test-pod 2>&1 "${kube_flags[@]:?}")
kube::test::if_has_string "${output_message}" 'pods "test-pod" not found'
# Second pass, pod is created (now that namespace exists).
kubectl apply -f hack/testdata/multi-resource.yaml "${kube_flags[@]:?}"
kube::test::get_object_assert 'pod test-pod' "{{${id_field}}}" 'test-pod'
# cleanup
kubectl delete -f hack/testdata/multi-resource.yaml
set +o nounset set +o nounset
set +o errexit set +o errexit
} }