diff --git a/build/root/Makefile b/build/root/Makefile index 6a86d1ea45b..b464e756381 100644 --- a/build/root/Makefile +++ b/build/root/Makefile @@ -291,7 +291,6 @@ test-cmd: @echo "$$TEST_CMD_HELP_INFO" else test-cmd: generated_files - hack/make-rules/test-kubeadm-cmd.sh hack/make-rules/test-cmd.sh endif diff --git a/hack/.shellcheck_failures b/hack/.shellcheck_failures index 2f95ce760dc..bea344f1b54 100644 --- a/hack/.shellcheck_failures +++ b/hack/.shellcheck_failures @@ -68,7 +68,6 @@ ./hack/make-rules/test-cmd.sh ./hack/make-rules/test-e2e-node.sh ./hack/make-rules/test-integration.sh -./hack/make-rules/test-kubeadm-cmd.sh ./hack/make-rules/test.sh ./hack/make-rules/update.sh ./hack/make-rules/verify.sh diff --git a/hack/make-rules/BUILD b/hack/make-rules/BUILD index fa982fcef3b..3b68b5d129f 100644 --- a/hack/make-rules/BUILD +++ b/hack/make-rules/BUILD @@ -41,14 +41,6 @@ sh_binary( ], ) -sh_binary( - name = "test-kubeadm-cmd", - srcs = ["test-kubeadm-cmd.sh"], - deps = [ - "//hack/lib", - ], -) - sh_binary( name = "build", srcs = ["build.sh"], diff --git a/test/cmd/README.md b/test/cmd/README.md new file mode 100644 index 00000000000..d5146c12e09 --- /dev/null +++ b/test/cmd/README.md @@ -0,0 +1,44 @@ +# Kubernetes Command-Line Integration Test Suite + +This document describes how you can use the Kubernetes command-line integration test-suite. + +## Running Tests + +### All Tests + +To run this entire suite, execute `make test-cmd` from the top level. This will import each file containing tests functions + +### Specific Tests + +To run a subset of tests (e.g. `run_deployment_test` and `run_impersonation_test`), execute `make test-cmd WHAT="deployment impersonation"`. Running specific +tests will not try and validate any required resources are available on the server. + +## Adding Tests + +Test functions need to have the format `run_*_test` so they can executed individually. Once a test has been added, insert a section in `legacy-script.sh` like + +```bash +###################### +# Replica Sets # +###################### + +if kube::test::if_supports_resource "${replicasets}" ; then + record_command run_rs_tests +fi +``` + +Be sure to validate any supported resouces required for the test by using the `kube::test::if_supports_resource` function. + + +### New File + +If the test resides in a new file, source the file in the top of the `legacy-script.sh` file by adding a new line in +```bash +source "${KUBE_ROOT}/test/cmd/apply.sh" +source "${KUBE_ROOT}/test/cmd/apps.sh" +source "${KUBE_ROOT}/test/cmd/authorization.sh" +source "${KUBE_ROOT}/test/cmd/batch.sh" +... +``` + +Please keep the order of the source list alphabetical. diff --git a/hack/make-rules/test-kubeadm-cmd.sh b/test/cmd/kubeadm.sh similarity index 65% rename from hack/make-rules/test-kubeadm-cmd.sh rename to test/cmd/kubeadm.sh index 86d82b08926..aae65bf9741 100755 --- a/hack/make-rules/test-kubeadm-cmd.sh +++ b/test/cmd/kubeadm.sh @@ -18,15 +18,19 @@ set -o errexit set -o nounset set -o pipefail -KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../.. -source "${KUBE_ROOT}/hack/lib/init.sh" +run_kubeadm_tests() { + set -o nounset + set -o errexit -KUBEADM_PATH="${KUBEADM_PATH:=$(kube::realpath "${KUBE_ROOT}")/cluster/kubeadm.sh}" + KUBEADM_PATH="${KUBEADM_PATH:=$(kube::realpath "${KUBE_ROOT}")/cluster/kubeadm.sh}" -# If testing a different version of kubeadm than the current build, you can -# comment this out to save yourself from needlessly building here. -make -C "${KUBE_ROOT}" WHAT=cmd/kubeadm + # If testing a different version of kubeadm than the current build, you can + # comment this out to save yourself from needlessly building here. + make -C "${KUBE_ROOT}" WHAT=cmd/kubeadm -make -C "${KUBE_ROOT}" test \ + make -C "${KUBE_ROOT}" test \ WHAT=k8s.io/kubernetes/cmd/kubeadm/test/cmd \ KUBE_TEST_ARGS="--kubeadm-path '${KUBEADM_PATH}'" + set +o nounset + set +o errexit +} \ No newline at end of file diff --git a/test/cmd/legacy-script.sh b/test/cmd/legacy-script.sh index 3eea6394656..bf3e871bef9 100755 --- a/test/cmd/legacy-script.sh +++ b/test/cmd/legacy-script.sh @@ -40,6 +40,7 @@ source "${KUBE_ROOT}/test/cmd/diff.sh" source "${KUBE_ROOT}/test/cmd/discovery.sh" source "${KUBE_ROOT}/test/cmd/generic-resources.sh" source "${KUBE_ROOT}/test/cmd/get.sh" +source "${KUBE_ROOT}/test/cmd/kubeadm.sh" source "${KUBE_ROOT}/test/cmd/kubeconfig.sh" source "${KUBE_ROOT}/test/cmd/node-management.sh" source "${KUBE_ROOT}/test/cmd/old-print.sh" @@ -385,6 +386,23 @@ runTests() { kubectl get "${kube_flags[@]}" -f hack/testdata/kubernetes-service.yaml fi + cleanup_tests(){ + kube::test::clear_all + if [[ -n "${foundError}" ]]; then + echo "FAILED TESTS: ""${foundError}" + exit 1 + fi + } + + if [[ -n "${WHAT-}" ]]; then + for pkg in ${WHAT} + do + record_command run_${pkg}_tests + done + cleanup_tests + return + fi + ######################### # Kubectl version # ######################### @@ -836,6 +854,7 @@ runTests() { record_command run_plugins_tests + ################# # Impersonation # ################# @@ -847,10 +866,5 @@ runTests() { record_command run_wait_tests - kube::test::clear_all - - if [[ -n "${foundError}" ]]; then - echo "FAILED TESTS: ""${foundError}" - exit 1 - fi + cleanup_tests }