@@ -274,18 +274,60 @@ __EOF__
274274 # cleanup
275275 kubectl delete --kustomize hack/testdata/kustomize
276276
277- # # kubectl apply multiple resources with initial failure.
278- # Pre-Condition: no POD exists
277+ # # kubectl apply multiple resources with one failure during apply phase.
278+ # Pre-Condition: namepace does not exist and no POD exists
279+ output_message=$( ! kubectl get namespace multi-resource-ns 2>&1 " ${kube_flags[@]:? } " )
280+ kube::test::if_has_string " ${output_message} " ' namespaces "multi-resource-ns" not found'
279281 kube::test::get_object_assert pods " {{range.items}}{{${id_field:? } }}:{{end}}" ' '
280282 # First pass, namespace is created, but pod is not (since namespace does not exist yet).
281- kubectl apply -f hack/testdata/multi-resource.yaml " ${kube_flags[@]:? } "
282- output_message=$( ! kubectl get pods test-pod 2>&1 " ${kube_flags[@]:? } " )
283+ output_message=$( ! kubectl apply -f hack/testdata/multi-resource-1.yaml 2>&1 " ${kube_flags[@]:? } " )
284+ kube::test::if_has_string " ${output_message} " ' namespaces "multi-resource-ns" not found'
285+ output_message=$( ! kubectl get pods test-pod -n multi-resource-ns 2>&1 " ${kube_flags[@]:? } " )
283286 kube::test::if_has_string " ${output_message} " ' pods "test-pod" not found'
284287 # Second pass, pod is created (now that namespace exists).
285- kubectl apply -f hack/testdata/multi-resource.yaml " ${kube_flags[@]:? } "
286- kube::test::get_object_assert ' pod test-pod' " {{${id_field} }}" ' test-pod'
288+ kubectl apply -f hack/testdata/multi-resource-1.yaml " ${kube_flags[@]:? } "
289+ kube::test::get_object_assert ' pods test-pod -n multi-resource-ns' " {{${id_field} }}" ' test-pod'
290+ # cleanup
291+ kubectl delete -f hack/testdata/multi-resource-1.yaml " ${kube_flags[@]:? } "
292+
293+ # # kubectl apply multiple resources with one failure during builder phase.
294+ # Pre-Condition: No configmaps
295+ kube::test::get_object_assert configmaps " {{range.items}}{{${id_field:? } }}:{{end}}" ' '
296+ # Apply a configmap and a bogus custom resource.
297+ output_message=$( ! kubectl apply -f hack/testdata/multi-resource-2.yaml 2>&1 " ${kube_flags[@]:? } " )
298+ # Should be error message from bogus custom resource.
299+ kube::test::if_has_string " ${output_message} " ' no matches for kind "Bogus" in version "example.com/v1"'
300+ # ConfigMap should have been created even with custom resource error.
301+ kube::test::get_object_assert ' configmaps foo' " {{${id_field} }}" ' foo'
302+ # cleanup
303+ kubectl delete configmaps foo " ${kube_flags[@]:? } "
304+
305+ # # kubectl apply multiple resources with one failure during builder phase.
306+ # Pre-Condition: No pods exist.
307+ kube::test::get_object_assert pods " {{range.items}}{{${id_field:? } }}:{{end}}" ' '
308+ # Applies three pods, one of which is invalid (POD-B), two succeed (pod-a, pod-c).
309+ output_message=$( ! kubectl apply -f hack/testdata/multi-resource-3.yaml 2>&1 " ${kube_flags[@]:? } " )
310+ kube::test::if_has_string " ${output_message} " ' The Pod "POD-B" is invalid'
311+ kube::test::get_object_assert ' pods pod-a' " {{${id_field} }}" ' pod-a'
312+ kube::test::get_object_assert ' pods pod-c' " {{${id_field} }}" ' pod-c'
313+ # cleanup
314+ kubectl delete pod pod-a pod-c " ${kube_flags[@]:? } "
315+ kube::test::get_object_assert pods " {{range.items}}{{${id_field:? } }}:{{end}}" ' '
316+
317+ # # kubectl apply multiple resources with one failure during apply phase.
318+ # Pre-Condition: crd does not exist, and custom resource does not exist.
319+ kube::test::get_object_assert crds " {{range.items}}{{${id_field:? } }}:{{end}}" ' '
320+ # First pass, custom resource fails, but crd apply succeeds.
321+ output_message=$( ! kubectl apply -f hack/testdata/multi-resource-4.yaml 2>&1 " ${kube_flags[@]:? } " )
322+ kube::test::if_has_string " ${output_message} " ' no matches for kind "Widget" in version "example.com/v1"'
323+ output_message=$( ! kubectl get widgets foo 2>&1 " ${kube_flags[@]:? } " )
324+ kube::test::if_has_string " ${output_message} " ' widgets.example.com "foo" not found'
325+ kube::test::get_object_assert ' crds widgets.example.com' " {{${id_field} }}" ' widgets.example.com'
326+ # Second pass, custom resource is created (now that crd exists).
327+ kubectl apply -f hack/testdata/multi-resource-4.yaml " ${kube_flags[@]:? } "
328+ kube::test::get_object_assert ' widget foo' " {{${id_field} }}" ' foo'
287329 # cleanup
288- kubectl delete -f hack/testdata/multi-resource.yaml
330+ kubectl delete -f hack/testdata/multi-resource-4 .yaml " ${kube_flags[@] :? } "
289331
290332 set +o nounset
291333 set +o errexit
0 commit comments