mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-19 09:52:49 +00:00
Add integration test for diff --prune --selector
This PR adds new integration tests for `kubectl diff --prune -l` to catch possible regressions in the future.
This commit is contained in:
parent
d6fe718e19
commit
6e8a1beda7
35
hack/testdata/prune/a_selector.yaml
vendored
Normal file
35
hack/testdata/prune/a_selector.yaml
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: a
|
||||
namespace: nsbprune
|
||||
labels:
|
||||
prune-group: "true"
|
||||
spec:
|
||||
containers:
|
||||
- name: kubernetes-pause
|
||||
image: registry.k8s.io/pause:3.9
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: b
|
||||
namespace: nsbprune
|
||||
labels:
|
||||
prune-group: "true"
|
||||
spec:
|
||||
containers:
|
||||
- name: kubernetes-pause
|
||||
image: registry.k8s.io/pause:3.9
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: c
|
||||
namespace: nsbprune
|
||||
labels:
|
||||
prune-group: "false"
|
||||
spec:
|
||||
containers:
|
||||
- name: kubernetes-pause
|
||||
image: registry.k8s.io/pause:3.9
|
23
hack/testdata/prune/a_selector_prune.yaml
vendored
Normal file
23
hack/testdata/prune/a_selector_prune.yaml
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: a
|
||||
namespace: nsbprune
|
||||
labels:
|
||||
prune-group: "true"
|
||||
spec:
|
||||
containers:
|
||||
- name: kubernetes-pause
|
||||
image: registry.k8s.io/pause:3.9
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: c
|
||||
namespace: nsbprune
|
||||
labels:
|
||||
prune-group: "false"
|
||||
spec:
|
||||
containers:
|
||||
- name: kubernetes-pause
|
||||
image: registry.k8s.io/pause:3.9
|
@ -47,7 +47,7 @@ func newPruner(dc dynamic.Interface, m meta.RESTMapper, r []prune.Resource, sele
|
||||
dynamicClient: dc,
|
||||
mapper: m,
|
||||
resources: r,
|
||||
labelSelector: selector,
|
||||
//labelSelector: selector,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -114,6 +114,26 @@ run_kubectl_diff_tests() {
|
||||
kubectl delete -f hack/testdata/pod.yaml
|
||||
kubectl delete -f hack/testdata/prune/b.yaml
|
||||
|
||||
## kubectl diff --prune with label selector
|
||||
kubectl create ns nsbprune
|
||||
kubectl apply --namespace nsbprune -f hack/testdata/prune/a_selector.yaml
|
||||
kube::test::get_object_assert 'pods a -n nsbprune' "{{${id_field:?}}}" 'a'
|
||||
kube::test::get_object_assert 'pods b -n nsbprune' "{{${id_field:?}}}" 'b'
|
||||
kube::test::get_object_assert 'pods c -n nsbprune' "{{${id_field:?}}}" 'c'
|
||||
# Make sure that kubectl diff does not return neither pod 'b' nor pod 'c' without prune flag
|
||||
output_message=$(kubectl diff -l prune-group=true -f hack/testdata/prune/a_selector_prune.yaml)
|
||||
kube::test::if_has_not_string "${output_message}" "name: b"
|
||||
kube::test::if_has_not_string "${output_message}" "name: c"
|
||||
# the exist code for diff is 1 because pod name 'b' is found in the given label selector but not 'c'
|
||||
output_message=$(kubectl diff --prune -l prune-group=true -f hack/testdata/prune/a_selector_prune.yaml || test $? -eq 1)
|
||||
# pod 'b' should be in output, it is pruned. On the other hand, 'c' should not be, it's label selector is different
|
||||
kube::test::if_has_string "${output_message}" 'name: b'
|
||||
kube::test::if_has_not_string "${output_message}" "name: c"
|
||||
|
||||
# Cleanup
|
||||
kubectl delete -f hack/testdata/prune/a_selector.yaml
|
||||
|
||||
|
||||
set +o nounset
|
||||
set +o errexit
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user