Allows kubectl create -f to filter by selector.

This commit is contained in:
Zihong Zheng
2017-01-17 19:07:55 -08:00
parent 16f45aee85
commit 6b9860cf54
2 changed files with 34 additions and 9 deletions

View File

@@ -900,6 +900,22 @@ run_kubectl_apply_tests() {
kubectl delete svc prune-svc 2>&1 "${kube_flags[@]}"
}
# Runs tests related to kubectl create --filename(-f) --selector(-l).
run_kubectl_create_filter_tests() {
## kubectl create -f with label selector should only create matching objects
# Pre-Condition: no POD exists
kube::test::get_object_assert pods "{{range.items}}{{$id_field}}:{{end}}" ''
# create
kubectl create -l unique-label=bingbang -f hack/testdata/filter "${kube_flags[@]}"
# check right pod exists
kube::test::get_object_assert 'pods selector-test-pod' "{{${labels_field}.name}}" 'selector-test-pod'
# check wrong pod doesn't exist
output_message=$(! kubectl get pods selector-test-pod-dont-apply 2>&1 "${kube_flags[@]}")
kube::test::if_has_string "${output_message}" 'pods "selector-test-pod-dont-apply" not found'
# cleanup
kubectl delete pods selector-test-pod
}
# Runs tests for --save-config tests.
run_save_config_tests() {
## Configuration annotations should be set when --save-config is enabled
@@ -2592,6 +2608,7 @@ runTests() {
# run for federation apiserver as well.
run_kubectl_apply_tests
run_kubectl_run_tests
run_kubectl_create_filter_tests
fi
###############