diff --git a/hack/make-rules/test-cmd-util.sh b/hack/make-rules/test-cmd-util.sh index 8e7598c7227..93c0b76714f 100755 --- a/hack/make-rules/test-cmd-util.sh +++ b/hack/make-rules/test-cmd-util.sh @@ -1710,6 +1710,208 @@ run_kubectl_request_timeout_tests() { set +o errexit } +run_template_output_tests() { + set -o nounset + set -o errexit + + kube::log::status "Testing --template support on commands" + ### Test global request timeout option + # Pre-condition: no POD exists + create_and_use_new_namespace + kube::test::get_object_assert pods "{{range.items}}{{$id_field}}:{{end}}" '' + # Command + # check that create supports --template output + kubectl create "${kube_flags[@]}" -f test/fixtures/doc-yaml/admin/limitrange/valid-pod.yaml + # Post-condition: valid-pod POD is created + kubectl get "${kube_flags[@]}" pods -o json + kube::test::get_object_assert pods "{{range.items}}{{$id_field}}:{{end}}" 'valid-pod:' + + # check that patch command supports --template output + output_message=$(kubectl "${kube_flags[@]}" patch --dry-run pods/valid-pod -p '{"patched":"value3"}' --type=merge --template="{{ .metadata.name }}:") + kube::test::if_has_string "${output_message}" 'valid-pod:' + + # check that label command supports --template output + output_message=$(kubectl "${kube_flags[@]}" label --dry-run pods/valid-pod label=value --template="{{ .metadata.name }}:") + kube::test::if_has_string "${output_message}" 'valid-pod:' + + # check that annotate command supports --template output + output_message=$(kubectl "${kube_flags[@]}" annotate --dry-run pods/valid-pod annotation=value --template="{{ .metadata.name }}:") + kube::test::if_has_string "${output_message}" 'valid-pod:' + + # check that apply command supports --template output + output_message=$(kubectl "${kube_flags[@]}" apply --dry-run -f test/fixtures/doc-yaml/admin/limitrange/valid-pod.yaml --template="{{ .metadata.name }}:") + kube::test::if_has_string "${output_message}" 'valid-pod:' + + # check that create command supports --template output + output_message=$(kubectl "${kube_flags[@]}" create -f test/fixtures/doc-yaml/admin/limitrange/valid-pod.yaml --dry-run --template="{{ .metadata.name }}:") + kube::test::if_has_string "${output_message}" 'valid-pod:' + + # check that autoscale command supports --template output + output_message=$(kubectl "${kube_flags[@]}" autoscale --max=2 -f hack/testdata/scale-deploy-1.yaml --dry-run --template="{{ .metadata.name }}:") + kube::test::if_has_string "${output_message}" 'scale-1:' + + # check that expose command supports --template output + output_message=$(kubectl "${kube_flags[@]}" expose -f hack/testdata/redis-slave-replicaset.yaml --save-config --port=80 --target-port=8000 --dry-run --template="{{ .metadata.name }}:") + kube::test::if_has_string "${output_message}" 'redis-slave:' + + # check that convert command supports --template output + output_message=$(kubectl "${kube_flags[@]}" convert -f hack/testdata/deployment-revision1.yaml --output-version=apps/v1beta1 --template="{{ .metadata.name }}:") + kube::test::if_has_string "${output_message}" 'nginx:' + + # check that run command supports --template output + output_message=$(kubectl "${kube_flags[@]}" run --dry-run --template="{{ .metadata.name }}:" pi --image=perl --restart=OnFailure -- perl -Mbignum=bpi -wle 'print bpi(2000)') + kube::test::if_has_string "${output_message}" 'pi:' + + # check that taint command supports --template output + output_message=$(kubectl "${kube_flags[@]}" taint node 127.0.0.1 dedicated=foo:PreferNoSchedule --template="{{ .metadata.name }}:") + kube::test::if_has_string "${output_message}" '127.0.0.1:' + # untaint node + kubectl taint node 127.0.0.1 dedicated- + + # check that "apply set-last-applied" command supports --template output + kubectl "${kube_flags[@]}" create -f test/e2e/testing-manifests/statefulset/cassandra/controller.yaml + output_message=$(kubectl "${kube_flags[@]}" apply set-last-applied -f test/e2e/testing-manifests/statefulset/cassandra/controller.yaml --dry-run --create-annotation --template="{{ .metadata.name }}:") + kube::test::if_has_string "${output_message}" 'cassandra:' + + # check that "auth reconcile" command supports --template output + output_message=$(kubectl "${kube_flags[@]}" auth reconcile --dry-run -f test/fixtures/pkg/kubectl/cmd/auth/rbac-resource-plus.yaml --template="{{ .metadata.name }}:") + kube::test::if_has_string "${output_message}" 'testing-CR:testing-CRB:testing-RB:testing-R:' + + # check that "config view" command supports --template output + output_message=$(kubectl "${kube_flags[@]}" config view --output=go-template="{{ .kind }}:") + kube::test::if_has_string "${output_message}" 'Config' + + # check that "create clusterrole" command supports --template output + output_message=$(kubectl "${kube_flags[@]}" create clusterrole --template="{{ .metadata.name }}:" --verb get myclusterrole --non-resource-url /logs/ --resource pods) + kube::test::if_has_string "${output_message}" 'myclusterrole:' + + # check that "create clusterrolebinding" command supports --template output + output_message=$(kubectl "${kube_flags[@]}" create clusterrolebinding foo --clusterrole=myclusterrole --template="{{ .metadata.name }}:") + kube::test::if_has_string "${output_message}" 'foo:' + + # check that "create configmap" command supports --template output + output_message=$(kubectl "${kube_flags[@]}" create configmap cm --dry-run --template="{{ .metadata.name }}:") + kube::test::if_has_string "${output_message}" 'cm:' + + # check that "create deployment" command supports --template output + output_message=$(kubectl "${kube_flags[@]}" create deployment deploy --dry-run --image=nginx --template="{{ .metadata.name }}:") + kube::test::if_has_string "${output_message}" 'deploy:' + + # check that "create job" command supports --template output + kubectl create "${kube_flags[@]}" -f - <