Prune should respect namespace

This commit is contained in:
Ted Yu 2019-09-25 16:43:08 -07:00
parent 06fc5b7f17
commit 88e2f8e04f
3 changed files with 17 additions and 0 deletions

View File

@ -2,6 +2,7 @@ apiVersion: v1
kind: Pod
metadata:
name: b
namespace: nsb
labels:
prune-group: "true"
spec:

View File

@ -635,6 +635,9 @@ See http://k8s.io/docs/reference/using-api/api-concepts/#conflicts`, err)
}
for n := range visitedNamespaces {
if len(o.Namespace) != 0 && n != o.Namespace {
continue
}
for _, m := range namespacedRESTMappings {
if err := p.prune(n, m); err != nil {
return fmt.Errorf("error pruning namespaced object %v: %v", m.GroupVersionKind, err)

View File

@ -144,6 +144,19 @@ __EOF__
output_message=$(! kubectl get pods a 2>&1 "${kube_flags[@]:?}")
kube::test::if_has_string "${output_message}" 'pods "a" not found'
kubectl delete pods a
kubectl delete pods b
# apply a
kubectl apply --namespace nsb -l prune-group=true -f hack/testdata/prune/a.yaml "${kube_flags[@]:?}"
# apply b with namespace
kubectl apply --namespace nsb --prune -l prune-group=true -f hack/testdata/prune/b.yaml "${kube_flags[@]:?}"
# check right pod exists
kube::test::get_object_assert 'pods b' "{{${id_field:?}}}" 'b'
# check wrong pod doesn't exist
output_message=$(! kubectl get pods a 2>&1 "${kube_flags[@]:?}")
kube::test::if_has_string "${output_message}" 'pods "a" not found'
# cleanup
kubectl delete pods b