@@ -223,6 +223,30 @@ __EOF__
223
223
# cleanup
224
224
kubectl delete svc prune-svc 2>&1 " ${kube_flags[@]:? } "
225
225
226
+ # # kubectl apply --prune can prune resources not in the defaulted namespace
227
+ # Pre-Condition: namespace nsb exists; no POD exists
228
+ kubectl create ns nsb
229
+ kube::test::get_object_assert pods " {{range.items}}{{${id_field:? } }}:{{end}}" ' '
230
+ # apply a into namespace nsb
231
+ kubectl apply --namespace nsb -f hack/testdata/prune/a.yaml " ${kube_flags[@]:? } "
232
+ kube::test::get_object_assert ' pods a -n nsb' " {{${id_field:? } }}" ' a'
233
+ # apply b with namespace
234
+ kubectl apply --namespace nsb -f hack/testdata/prune/b.yaml " ${kube_flags[@]:? } "
235
+ kube::test::get_object_assert ' pods b -n nsb' " {{${id_field:? } }}" ' b'
236
+ # apply --prune must prune a
237
+ kubectl apply --prune --all -f hack/testdata/prune/b.yaml
238
+ # check wrong pod doesn't exist
239
+ output_message=$( ! kubectl get pods a -n nsb 2>&1 " ${kube_flags[@]:? } " )
240
+ kube::test::if_has_string " ${output_message} " ' pods "a" not found'
241
+ # check right pod exists
242
+ kube::test::get_object_assert ' pods b -n nsb' " {{${id_field:? } }}" ' b'
243
+
244
+ # cleanup
245
+ kubectl delete ns nsb
246
+
247
+ # # kubectl apply -n must fail if input file contains namespace other than the one given in -n
248
+ output_message=$( ! kubectl apply -n foo -f hack/testdata/prune/b.yaml 2>&1 " ${kube_flags[@]:? } " )
249
+ kube::test::if_has_string " ${output_message} " ' the namespace from the provided object "nsb" does not match the namespace "foo".'
226
250
227
251
# # kubectl apply -f some.yml --force
228
252
# Pre-condition: no service exists
0 commit comments