From a9d4ce42e1e47fd76a5ac271197540d23f967fc2 Mon Sep 17 00:00:00 2001 From: Toni Finger Date: Tue, 17 Sep 2024 13:00:00 +0200 Subject: [PATCH 1/7] Inital kaas sonobuoy usage Derived from the PoC, this commit presents the setup for the provision of SCS-kaas tests using sonoboy and golang. Signed-off-by: Toni Finger --- .../Dockerfile | 2 +- .../Makefile | 0 .../README.md | 0 .../go.mod | 0 .../go.sum | 0 .../plugin.yaml | 2 +- .../scs_k8s_conformance_tests}/main_test.go | 0 .../scs_k8s_conformance_tests}/main_test.go.template | 0 .../scs_k8s_conformance_tests}/scs_0200_example_test.go | 0 .../scs_k8s_conformance_tests}/scs_0201_example_test.go | 0 .../scs_k8s_conformance_tests}/template_test.go.template | 0 11 files changed, 2 insertions(+), 2 deletions(-) rename Tests/kaas/{kaas-sonobuoy-go-example-e2e-framework => kaas-sonobuoy-tests}/Dockerfile (93%) rename Tests/kaas/{kaas-sonobuoy-go-example-e2e-framework => kaas-sonobuoy-tests}/Makefile (100%) rename Tests/kaas/{kaas-sonobuoy-go-example-e2e-framework => kaas-sonobuoy-tests}/README.md (100%) rename Tests/kaas/{kaas-sonobuoy-go-example-e2e-framework => kaas-sonobuoy-tests}/go.mod (100%) rename Tests/kaas/{kaas-sonobuoy-go-example-e2e-framework => kaas-sonobuoy-tests}/go.sum (100%) rename Tests/kaas/{kaas-sonobuoy-go-example-e2e-framework => kaas-sonobuoy-tests}/plugin.yaml (94%) rename Tests/kaas/{kaas-sonobuoy-go-example-e2e-framework/scs_k8s_tests => kaas-sonobuoy-tests/scs_k8s_conformance_tests}/main_test.go (100%) rename Tests/kaas/{kaas-sonobuoy-go-example-e2e-framework/scs_k8s_tests => kaas-sonobuoy-tests/scs_k8s_conformance_tests}/main_test.go.template (100%) rename Tests/kaas/{kaas-sonobuoy-go-example-e2e-framework/scs_k8s_tests => kaas-sonobuoy-tests/scs_k8s_conformance_tests}/scs_0200_example_test.go (100%) rename Tests/kaas/{kaas-sonobuoy-go-example-e2e-framework/scs_k8s_tests => kaas-sonobuoy-tests/scs_k8s_conformance_tests}/scs_0201_example_test.go (100%) rename Tests/kaas/{kaas-sonobuoy-go-example-e2e-framework/scs_k8s_tests => kaas-sonobuoy-tests/scs_k8s_conformance_tests}/template_test.go.template (100%) diff --git a/Tests/kaas/kaas-sonobuoy-go-example-e2e-framework/Dockerfile b/Tests/kaas/kaas-sonobuoy-tests/Dockerfile similarity index 93% rename from Tests/kaas/kaas-sonobuoy-go-example-e2e-framework/Dockerfile rename to Tests/kaas/kaas-sonobuoy-tests/Dockerfile index 86ca601cb..738c3bd55 100644 --- a/Tests/kaas/kaas-sonobuoy-go-example-e2e-framework/Dockerfile +++ b/Tests/kaas/kaas-sonobuoy-tests/Dockerfile @@ -15,7 +15,7 @@ RUN apt-get update && apt-get install -y wget jq && \ fi && \ chmod +x /usr/bin/kubectl -COPY ./scs_k8s_tests /src/scs_k8s_tests +COPY ./scs_k8s_conformance_tests /src/scs_k8s_conformance_tests WORKDIR /src COPY go.* /src/ ENV CGO_ENABLED=0 diff --git a/Tests/kaas/kaas-sonobuoy-go-example-e2e-framework/Makefile b/Tests/kaas/kaas-sonobuoy-tests/Makefile similarity index 100% rename from Tests/kaas/kaas-sonobuoy-go-example-e2e-framework/Makefile rename to Tests/kaas/kaas-sonobuoy-tests/Makefile diff --git a/Tests/kaas/kaas-sonobuoy-go-example-e2e-framework/README.md b/Tests/kaas/kaas-sonobuoy-tests/README.md similarity index 100% rename from Tests/kaas/kaas-sonobuoy-go-example-e2e-framework/README.md rename to Tests/kaas/kaas-sonobuoy-tests/README.md diff --git a/Tests/kaas/kaas-sonobuoy-go-example-e2e-framework/go.mod b/Tests/kaas/kaas-sonobuoy-tests/go.mod similarity index 100% rename from Tests/kaas/kaas-sonobuoy-go-example-e2e-framework/go.mod rename to Tests/kaas/kaas-sonobuoy-tests/go.mod diff --git a/Tests/kaas/kaas-sonobuoy-go-example-e2e-framework/go.sum b/Tests/kaas/kaas-sonobuoy-tests/go.sum similarity index 100% rename from Tests/kaas/kaas-sonobuoy-go-example-e2e-framework/go.sum rename to Tests/kaas/kaas-sonobuoy-tests/go.sum diff --git a/Tests/kaas/kaas-sonobuoy-go-example-e2e-framework/plugin.yaml b/Tests/kaas/kaas-sonobuoy-tests/plugin.yaml similarity index 94% rename from Tests/kaas/kaas-sonobuoy-go-example-e2e-framework/plugin.yaml rename to Tests/kaas/kaas-sonobuoy-tests/plugin.yaml index c3af316e2..1daa0297a 100644 --- a/Tests/kaas/kaas-sonobuoy-go-example-e2e-framework/plugin.yaml +++ b/Tests/kaas/kaas-sonobuoy-tests/plugin.yaml @@ -1,6 +1,6 @@ sonobuoy-config: driver: Job - plugin-name: scsconformance + plugin-name: scs-conformance result-format: gojson description: An easy to start from project for making K8s aware tests. spec: diff --git a/Tests/kaas/kaas-sonobuoy-go-example-e2e-framework/scs_k8s_tests/main_test.go b/Tests/kaas/kaas-sonobuoy-tests/scs_k8s_conformance_tests/main_test.go similarity index 100% rename from Tests/kaas/kaas-sonobuoy-go-example-e2e-framework/scs_k8s_tests/main_test.go rename to Tests/kaas/kaas-sonobuoy-tests/scs_k8s_conformance_tests/main_test.go diff --git a/Tests/kaas/kaas-sonobuoy-go-example-e2e-framework/scs_k8s_tests/main_test.go.template b/Tests/kaas/kaas-sonobuoy-tests/scs_k8s_conformance_tests/main_test.go.template similarity index 100% rename from Tests/kaas/kaas-sonobuoy-go-example-e2e-framework/scs_k8s_tests/main_test.go.template rename to Tests/kaas/kaas-sonobuoy-tests/scs_k8s_conformance_tests/main_test.go.template diff --git a/Tests/kaas/kaas-sonobuoy-go-example-e2e-framework/scs_k8s_tests/scs_0200_example_test.go b/Tests/kaas/kaas-sonobuoy-tests/scs_k8s_conformance_tests/scs_0200_example_test.go similarity index 100% rename from Tests/kaas/kaas-sonobuoy-go-example-e2e-framework/scs_k8s_tests/scs_0200_example_test.go rename to Tests/kaas/kaas-sonobuoy-tests/scs_k8s_conformance_tests/scs_0200_example_test.go diff --git a/Tests/kaas/kaas-sonobuoy-go-example-e2e-framework/scs_k8s_tests/scs_0201_example_test.go b/Tests/kaas/kaas-sonobuoy-tests/scs_k8s_conformance_tests/scs_0201_example_test.go similarity index 100% rename from Tests/kaas/kaas-sonobuoy-go-example-e2e-framework/scs_k8s_tests/scs_0201_example_test.go rename to Tests/kaas/kaas-sonobuoy-tests/scs_k8s_conformance_tests/scs_0201_example_test.go diff --git a/Tests/kaas/kaas-sonobuoy-go-example-e2e-framework/scs_k8s_tests/template_test.go.template b/Tests/kaas/kaas-sonobuoy-tests/scs_k8s_conformance_tests/template_test.go.template similarity index 100% rename from Tests/kaas/kaas-sonobuoy-go-example-e2e-framework/scs_k8s_tests/template_test.go.template rename to Tests/kaas/kaas-sonobuoy-tests/scs_k8s_conformance_tests/template_test.go.template From 8fb53382d76ae15bdd5da58d13a13092c1799bc6 Mon Sep 17 00:00:00 2001 From: Toni Finger Date: Wed, 25 Sep 2024 16:10:15 +0200 Subject: [PATCH 2/7] Update Rework Makefile Apply kind configuration Signed-off-by: Toni Finger --- .gitignore | 1 + Tests/kaas/kaas-sonobuoy-tests/Makefile | 83 ++++++++++--------- Tests/kaas/kaas-sonobuoy-tests/README.md | 29 ++++--- .../kaas/kaas-sonobuoy-tests/kind_config.yaml | 10 +++ ...l => scs-conformance-sonobuoy-plugin.yaml} | 6 +- 5 files changed, 72 insertions(+), 57 deletions(-) create mode 100644 Tests/kaas/kaas-sonobuoy-tests/kind_config.yaml rename Tests/kaas/kaas-sonobuoy-tests/{plugin.yaml => scs-conformance-sonobuoy-plugin.yaml} (70%) diff --git a/.gitignore b/.gitignore index 4d7851fab..4595d59ea 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ .DS_Store node_modules Tests/kaas/results/ +Tests/kaas/kaas-sonobuoy-tests/results/ *.tar.gz diff --git a/Tests/kaas/kaas-sonobuoy-tests/Makefile b/Tests/kaas/kaas-sonobuoy-tests/Makefile index dbf6757c3..c2183bbae 100644 --- a/Tests/kaas/kaas-sonobuoy-tests/Makefile +++ b/Tests/kaas/kaas-sonobuoy-tests/Makefile @@ -1,32 +1,28 @@ # Makefile # This makefile is for development purpose +############################################################################### +## Setup: ## +############################################################################### SHELL = /bin/bash -#SED ?= sed DOCKERFILE="Dockerfile" IMAGE_REGISTRY="ghcr.io/sovereigncloudstack/standards" -IMAGE_NAME="scsconformance" -#IMAGE_VERSION_TAG ="v0.1.2" +IMAGE_NAME="scs-kaas-conformance" KIND_CLUSTER ="testcluster" -#PLUGIN_NAME="k8s-default-storage-class-plugin-go" -PLUGIN_NAME="plugin" +PLUGIN_NAME="scs-conformance-sonobuoy-plugin" PLUGIN_FILE="${PLUGIN_NAME}.yaml" +KIND_CONFIG_FILE="kind_config.yaml" -#~ SONO_WAIT = 1 -#~ SONO_TIMEOUT = 60 - -KUBERNETES_SERVICE_HOST=127.0.0.1 -KUBERNETES_SERVICE_PORT=34743 - +SONO_WAIT= 30 ############################################################################### ## Helpers: ## ############################################################################### -ifeq ($(IMAGE_VERSION_TAG),) +ifndef IMAGE_VERSION_TAG: export TAG=dev else export TAG=${IMAGE_VERSION_TAG} @@ -46,70 +42,75 @@ kind-init: @echo "[KindCluster] ${KIND_CLUSTER}" @echo "" - ############################################################################### ## For develpoment usage: ## ############################################################################### dev-prerequests: - @echo "[check-test-setup]" @kind version - @docker version + @docker version -f json | jq '.Client.Version' @sonobuoy version --short + @yq --version + @jq --version @go version @docker buildx version dev-setup: kind-init - kind create cluster --name ${KIND_CLUSTER} + kind create cluster --config ${KIND_CONFIG_FILE} --name ${KIND_CLUSTER} dev-build: container-init - @echo "[build]" + @echo "[Building image...]" DOCKER_BUILDKIT=1 docker build . -f ${DOCKERFILE} -t ${SONOBUOY_IMAGE} kind load docker-image --name ${KIND_CLUSTER} ${SONOBUOY_IMAGE} -dev-go: - @echo "[go]" - @echo "[KubernetesService] ${KUBERNETES_SERVICE_HOST}:${KUBERNETES_SERVICE_PORT}" - @rm -rf ./build || true - @mkdir ./build - go test -c -o ./build ./... -# go test -c -o ./build ./... --args --skip-labels="type=pod-list" -# go tool test2json ./build -test.v +dev-run: + @echo "[Running sonobuoy...]" + @sonobuoy run -p ${PLUGIN_FILE} --wait=${SONO_WAIT} + @sonobuoy status -dev-run: - @echo "[run-test]" - @echo "sonobuoy run --plugin ${PLUGIN_FILE} --wait=${SONO_WAIT} --timeout=${SONO_TIMEOUT}" -#~ @sonobuoy run --plugin ${PLUGIN_FILE} --wait=${SONO_WAIT} --timeout=${SONO_TIMEOUT} - @sonobuoy run --plugin ${PLUGIN_FILE} +dev-run-background: + @echo "[Running sonobuoy in background...]" + @sonobuoy run -p ${PLUGIN_FILE} @sonobuoy status -dev-result: - @echo "[result]" - #outfile=$(sonobuoy retrieve) && mkdir results && tar -xf ${outfile} -C results +dev-result: dev-clean-result + @echo "[Retrieve results...]" sonobuoy retrieve - sonobuoy results *.tar.gz + @echo "[Extracting results...]" mkdir results tar -xf *.tar.gz -C results + cat results/plugins/scs-kaas-conformance/sonobuoy_results.yaml | yq + cat results/plugins/scs-kaas-conformance/results/global/out.json | jq + @echo "[Displaying results...]" + sonobuoy results *.tar.gz -dev-clean: - @echo "[clean]" - @sonobuoy delete --all --wait || true - @sonobuoy status || true +dev-rerun: dev-clean-sonobuoy dev-build dev-run dev-result + + +dev-clean-result: @rm -rf *.tar.gz || true @rm -rf results || true +dev-clean-sonobuoy: dev-clean-result + @echo "[Cleanup sonobuoy environment from cluster...]" + @sonobuoy delete --all --wait || true + @sonobuoy status || true -dev-purge: kind-init dev-clean - @echo "[purge]" + +dev-purge: kind-init clean-sonobuoy + @echo "[Purge everthing...]" + @echo "[Deleting kind cluster...]" kind delete cluster --name ${KIND_CLUSTER} || true + @echo "[Removing docker image...]" docker rmi ${SONOBUOY_IMAGE} || true + @rm -rf ./build || true +PHONY: dev-prerequests dev-build dev-run dev-result dev-clean-sonobuoy dev-clean-result dev-purge dev-rerun dev-run-background -PHONY: dev-prerequests dev-build dev-run dev-result dev-clean dev-clean dev-purge diff --git a/Tests/kaas/kaas-sonobuoy-tests/README.md b/Tests/kaas/kaas-sonobuoy-tests/README.md index cf5681dac..b455bc373 100644 --- a/Tests/kaas/kaas-sonobuoy-tests/README.md +++ b/Tests/kaas/kaas-sonobuoy-tests/README.md @@ -34,21 +34,20 @@ For test development with Sonobuoy, [KinD](https://kind.sigs.k8s.io/) is used as make dev-setup ``` -1. Set environment variables +* (Optional): Set env ```bash - export IMAGE_VERSION_TAG="dev" - export K8S_HOST= - export K8S_PORT= + export TEST_STANDARD= ``` -2. Build the image and upload it to the KinD cluster + +1. Build the image and upload it to the KinD cluster ```bash make dev-build ``` -3. Execute the Sonobuoy plugin +2. Execute the Sonobuoy plugin ```bash make dev-run @@ -61,7 +60,7 @@ For test development with Sonobuoy, [KinD](https://kind.sigs.k8s.io/) is used as sonobuoy status ``` -4. Retrieve the Results +3. Retrieve the Results Once Sonobuoy is done running the plugin you can retrieve the results as following: @@ -69,7 +68,7 @@ For test development with Sonobuoy, [KinD](https://kind.sigs.k8s.io/) is used as make dev-result ``` -5. Clean the Sonobuoy testcase from the KinD cluster +4. Clean the Sonobuoy testcase from the KinD cluster Cleaning up all Kubernetes resources which were placed on the KinD cluster by sonobuoy @@ -77,10 +76,14 @@ For test development with Sonobuoy, [KinD](https://kind.sigs.k8s.io/) is used as make dev-clean ``` -6. Purge everything +These steps can also be carried out in short form using the following command: - Deleting the KinD cluster +```bash +make dev-rerun +``` - ```bash - make dev-purge - ``` +Finnaly to remove the kind cluster simply use: + +```bash +make dev-purge +``` diff --git a/Tests/kaas/kaas-sonobuoy-tests/kind_config.yaml b/Tests/kaas/kaas-sonobuoy-tests/kind_config.yaml new file mode 100644 index 000000000..947a9fa8a --- /dev/null +++ b/Tests/kaas/kaas-sonobuoy-tests/kind_config.yaml @@ -0,0 +1,10 @@ +kind: Cluster +apiVersion: kind.x-k8s.io/v1alpha4 +networking: + apiServerAddress: 127.0.0.1 + apiServerPort: 6443 +nodes: +- role: control-plane +- role: worker +- role: worker +- role: worker diff --git a/Tests/kaas/kaas-sonobuoy-tests/plugin.yaml b/Tests/kaas/kaas-sonobuoy-tests/scs-conformance-sonobuoy-plugin.yaml similarity index 70% rename from Tests/kaas/kaas-sonobuoy-tests/plugin.yaml rename to Tests/kaas/kaas-sonobuoy-tests/scs-conformance-sonobuoy-plugin.yaml index 1daa0297a..48097d943 100644 --- a/Tests/kaas/kaas-sonobuoy-tests/plugin.yaml +++ b/Tests/kaas/kaas-sonobuoy-tests/scs-conformance-sonobuoy-plugin.yaml @@ -1,13 +1,13 @@ sonobuoy-config: driver: Job - plugin-name: scs-conformance + plugin-name: scs-kaas-conformance result-format: gojson - description: An easy to start from project for making K8s aware tests. + description: A testsuite for testing the scs conformance of k8s clusters. spec: command: - bash args: ["-c","go tool test2json ./custom.test -test.v | tee ${SONOBUOY_RESULTS_DIR}/out.json ; echo ${SONOBUOY_RESULTS_DIR}/out.json > ${SONOBUOY_RESULTS_DIR}/done"] - image: ghcr.io/sovereigncloudstack/standards/scsconformance:dev + image: ghcr.io/sovereigncloudstack/standards/scs-kaas-conformance:dev env: - name: NS_PREFIX value: custom From bb6bef46061c733edc181443a6eaa693d2f57df2 Mon Sep 17 00:00:00 2001 From: Toni Finger Date: Thu, 26 Sep 2024 11:18:12 +0200 Subject: [PATCH 3/7] fixup Signed-off-by: Toni Finger --- Tests/kaas/kaas-sonobuoy-tests/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/kaas/kaas-sonobuoy-tests/Makefile b/Tests/kaas/kaas-sonobuoy-tests/Makefile index c2183bbae..6781bd689 100644 --- a/Tests/kaas/kaas-sonobuoy-tests/Makefile +++ b/Tests/kaas/kaas-sonobuoy-tests/Makefile @@ -22,7 +22,7 @@ SONO_WAIT= 30 ## Helpers: ## ############################################################################### -ifndef IMAGE_VERSION_TAG: +ifeq ($(IMAGE_VERSION_TAG),) export TAG=dev else export TAG=${IMAGE_VERSION_TAG} From 8471b93d39d759831e07fc7806cd3dadf40cb65d Mon Sep 17 00:00:00 2001 From: tonifinger <129007376+tonifinger@users.noreply.github.com> Date: Thu, 26 Sep 2024 20:28:12 +0200 Subject: [PATCH 4/7] Update Tests/kaas/kaas-sonobuoy-tests/Makefile Co-authored-by: Michal Gubricky Signed-off-by: tonifinger <129007376+tonifinger@users.noreply.github.com> --- Tests/kaas/kaas-sonobuoy-tests/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/kaas/kaas-sonobuoy-tests/Makefile b/Tests/kaas/kaas-sonobuoy-tests/Makefile index 6781bd689..c75e854d2 100644 --- a/Tests/kaas/kaas-sonobuoy-tests/Makefile +++ b/Tests/kaas/kaas-sonobuoy-tests/Makefile @@ -104,7 +104,7 @@ dev-clean-sonobuoy: dev-clean-result @sonobuoy status || true -dev-purge: kind-init clean-sonobuoy +dev-purge: kind-init dev-clean-sonobuoy @echo "[Purge everthing...]" @echo "[Deleting kind cluster...]" kind delete cluster --name ${KIND_CLUSTER} || true From 28e241681f7e9b6aa116556f9dd26d848c96ad3b Mon Sep 17 00:00:00 2001 From: Toni Finger Date: Mon, 30 Sep 2024 11:19:24 +0200 Subject: [PATCH 5/7] Added the option to test only certain test functions. This commit introduces a development mode that allows the test suite itself to create a Kubernetes cluster for testing Signed-off-by: Toni Finger --- Tests/kaas/kaas-sonobuoy-tests/Makefile | 15 ++- Tests/kaas/kaas-sonobuoy-tests/README.md | 17 +-- Tests/kaas/kaas-sonobuoy-tests/go.mod | 5 +- Tests/kaas/kaas-sonobuoy-tests/go.sum | 28 ----- .../scs_k8s_conformance_tests/main_test.go | 77 +++++++++---- .../main_test.go.template | 107 ------------------ .../scs_0200_example_test.go | 83 -------------- .../scs_0200_smoke_test.go | 16 +++ .../scs_0201_example_test.go | 80 ------------- .../template_test.go.template | 66 ----------- 10 files changed, 95 insertions(+), 399 deletions(-) delete mode 100644 Tests/kaas/kaas-sonobuoy-tests/scs_k8s_conformance_tests/main_test.go.template delete mode 100644 Tests/kaas/kaas-sonobuoy-tests/scs_k8s_conformance_tests/scs_0200_example_test.go create mode 100644 Tests/kaas/kaas-sonobuoy-tests/scs_k8s_conformance_tests/scs_0200_smoke_test.go delete mode 100644 Tests/kaas/kaas-sonobuoy-tests/scs_k8s_conformance_tests/scs_0201_example_test.go delete mode 100644 Tests/kaas/kaas-sonobuoy-tests/scs_k8s_conformance_tests/template_test.go.template diff --git a/Tests/kaas/kaas-sonobuoy-tests/Makefile b/Tests/kaas/kaas-sonobuoy-tests/Makefile index c75e854d2..b7099cee7 100644 --- a/Tests/kaas/kaas-sonobuoy-tests/Makefile +++ b/Tests/kaas/kaas-sonobuoy-tests/Makefile @@ -16,7 +16,7 @@ PLUGIN_NAME="scs-conformance-sonobuoy-plugin" PLUGIN_FILE="${PLUGIN_NAME}.yaml" KIND_CONFIG_FILE="kind_config.yaml" -SONO_WAIT= 30 +SONO_WAIT= 10 ############################################################################### ## Helpers: ## @@ -69,7 +69,6 @@ dev-build: container-init dev-run: @echo "[Running sonobuoy...]" @sonobuoy run -p ${PLUGIN_FILE} --wait=${SONO_WAIT} - @sonobuoy status dev-run-background: @@ -85,7 +84,7 @@ dev-result: dev-clean-result mkdir results tar -xf *.tar.gz -C results cat results/plugins/scs-kaas-conformance/sonobuoy_results.yaml | yq - cat results/plugins/scs-kaas-conformance/results/global/out.json | jq + cat results/plugins/scs-kaas-conformance/results/global/out.json | jq '.Output' @echo "[Displaying results...]" sonobuoy results *.tar.gz @@ -93,6 +92,15 @@ dev-result: dev-clean-result dev-rerun: dev-clean-sonobuoy dev-build dev-run dev-result +test-function: + @echo "only run tests for: $${TESTFUNCTION_CODE}" + DEVELOPMENT_MODE=createcluster go test -run=$${TESTFUNCTION_CODE} ./... || true + + +lint: + @echo "NOT YET IMPLEMENTED" + + dev-clean-result: @rm -rf *.tar.gz || true @rm -rf results || true @@ -101,7 +109,6 @@ dev-clean-result: dev-clean-sonobuoy: dev-clean-result @echo "[Cleanup sonobuoy environment from cluster...]" @sonobuoy delete --all --wait || true - @sonobuoy status || true dev-purge: kind-init dev-clean-sonobuoy diff --git a/Tests/kaas/kaas-sonobuoy-tests/README.md b/Tests/kaas/kaas-sonobuoy-tests/README.md index b455bc373..a8704197c 100644 --- a/Tests/kaas/kaas-sonobuoy-tests/README.md +++ b/Tests/kaas/kaas-sonobuoy-tests/README.md @@ -34,13 +34,6 @@ For test development with Sonobuoy, [KinD](https://kind.sigs.k8s.io/) is used as make dev-setup ``` -* (Optional): Set env - - ```bash - export TEST_STANDARD= - ``` - - 1. Build the image and upload it to the KinD cluster ```bash @@ -87,3 +80,13 @@ Finnaly to remove the kind cluster simply use: ```bash make dev-purge ``` + +## Execution of only certain test functions for development purposes + +```bash +export TESTFUNCTION_CODE= +make test-function +``` + + + diff --git a/Tests/kaas/kaas-sonobuoy-tests/go.mod b/Tests/kaas/kaas-sonobuoy-tests/go.mod index b1fe960ce..1fe28bda6 100644 --- a/Tests/kaas/kaas-sonobuoy-tests/go.mod +++ b/Tests/kaas/kaas-sonobuoy-tests/go.mod @@ -1,6 +1,6 @@ -module kaas/kaas-sonobuoy-go-example-2 +module kaas/kaas-sonobuoy-tests -go 1.17 +go 1.21 require ( github.com/vmware-tanzu/sonobuoy-plugins/plugin-helper v0.0.0-20211029183731-1d6848b67eec @@ -27,6 +27,7 @@ require ( github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b // indirect github.com/sirupsen/logrus v1.7.0 // indirect github.com/spf13/pflag v1.0.5 // indirect + github.com/vladimirvivien/gexe v0.1.1 // indirect github.com/vmware-tanzu/sonobuoy v1.11.5-prerelease.1.0.20211004145628-b633b4fefcdc // indirect golang.org/x/net v0.23.0 // indirect golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d // indirect diff --git a/Tests/kaas/kaas-sonobuoy-tests/go.sum b/Tests/kaas/kaas-sonobuoy-tests/go.sum index 7fed0bb8f..5bddac2e0 100644 --- a/Tests/kaas/kaas-sonobuoy-tests/go.sum +++ b/Tests/kaas/kaas-sonobuoy-tests/go.sum @@ -413,7 +413,6 @@ github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/bbolt v1.3.5/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ= @@ -444,9 +443,6 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= -golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= -golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -478,8 +474,6 @@ golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzB golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.1-0.20200828183125-ce943fd02449/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -511,12 +505,7 @@ golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/ golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210224082022-3d97a244fca7/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= -golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= -golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs= golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -533,8 +522,6 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -583,21 +570,12 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210426230700-d19ff857e887/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= -golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= -golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8= golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -607,9 +585,6 @@ golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -659,8 +634,6 @@ golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roY golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= -golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -783,7 +756,6 @@ k8s.io/code-generator v0.21.1/go.mod h1:hUlps5+9QaTrKx+jiM4rmq7YmH8wPOIko64uZCHD k8s.io/component-base v0.21.1/go.mod h1:NgzFZ2qu4m1juby4TnrmpR8adRk6ka62YdH5DkIIyKA= k8s.io/gengo v0.0.0-20200413195148-3a45101e95ac/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0= k8s.io/gengo v0.0.0-20201214224949-b6c5ce23f027/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E= -k8s.io/klog v1.0.0 h1:Pt+yjF5aB1xDSVbau4VsWe+dQNzA0qv1LlXdC2dF6Q8= k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I= k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE= k8s.io/klog/v2 v2.2.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y= diff --git a/Tests/kaas/kaas-sonobuoy-tests/scs_k8s_conformance_tests/main_test.go b/Tests/kaas/kaas-sonobuoy-tests/scs_k8s_conformance_tests/main_test.go index 95b2e0482..fff5f3d73 100644 --- a/Tests/kaas/kaas-sonobuoy-tests/scs_k8s_conformance_tests/main_test.go +++ b/Tests/kaas/kaas-sonobuoy-tests/scs_k8s_conformance_tests/main_test.go @@ -5,24 +5,24 @@ import ( "fmt" "os" "testing" - + "log" plugin_helper "github.com/vmware-tanzu/sonobuoy-plugins/plugin-helper" v1 "k8s.io/api/core/v1" "sigs.k8s.io/e2e-framework/pkg/env" "sigs.k8s.io/e2e-framework/pkg/envconf" + "sigs.k8s.io/e2e-framework/pkg/envfuncs" ) const ( ProgressReporterCtxKey = "SONOBUOY_PROGRESS_REPORTER" NamespacePrefixKey = "NS_PREFIX" + DevelopmentModeKey = "DEVELOPMENT_MODE" ) var testenv env.Environment func TestMain(m *testing.M) { - // Assume we are running in the cluster as a Sonobuoy plugin. - testenv = env.NewInClusterConfig() // Specifying a run ID so that multiple runs wouldn't collide. Allow a prefix to be set via env var // so that a plugin configuration (yaml file) can easily set that without code changes. @@ -32,21 +32,65 @@ func TestMain(m *testing.M) { // Create updateReporter; will also place into context during Setup for use in features. updateReporter := plugin_helper.NewProgressReporter(0) - testenv.Setup(func(ctx context.Context, config *envconf.Config) (context.Context, error) { - // Try and create the client; doing it before all the tests allows the tests to assume - // it can be created without error and they can just use config.Client(). - _,err:=config.NewClient() - return context.WithValue(ctx,ProgressReporterCtxKey,updateReporter) ,err - }) + developmentMode := os.Getenv(DevelopmentModeKey) + log.Printf("Setup test enviornment for: %#v", developmentMode ) + + switch KubernetesEnviornment := developmentMode; KubernetesEnviornment { + + case "createcluster": + log.Println("Create kind cluster for test") + testenv = env.New() + kindClusterName := envconf.RandomName("gotestcluster", 16) + //~ namespace := envconf.RandomName("testnamespace", 16) + + testenv.Setup( + envfuncs.CreateKindCluster(kindClusterName), + ) + + testenv.Finish( + //~ envfuncs.DeleteNamespace(namespace), + envfuncs.DestroyKindCluster(kindClusterName), + ) + + case "usecluster": + log.Println("Use existing k8s cluster for the test") + log.Println("TO_BE_IMPLEMENTED") + //~ testenv = env.NewFromFlags() + //~ KubeConfig:= os.Getenv(KUBECONFIGFILE) + //~ testenv = env.NewWithKubeConfig(KubeConfig) + + default: + // Assume we are running in the cluster as a Sonobuoy plugin. + log.Println("Running tests inside k8s cluster") + testenv = env.NewInClusterConfig() + + testenv.Setup(func(ctx context.Context, config *envconf.Config) (context.Context, error) { + // Try and create the client; doing it before all the tests allows the tests to assume + // it can be created without error and they can just use config.Client(). + _,err:=config.NewClient() + return context.WithValue(ctx,ProgressReporterCtxKey,updateReporter) ,err + }) + + testenv.Finish( + func(ctx context.Context, cfg *envconf.Config) (context.Context, error) { + log.Println("Finished go test suite") + //~ if err := ???; err != nil{ + //~ return ctx, err + //~ } + return ctx, nil + }, + ) + + } testenv.BeforeEachTest(func(ctx context.Context, cfg *envconf.Config, t *testing.T) (context.Context, error) { - fmt.Println("BeforeEachTest") + fmt.Println("BeforeEachTest") updateReporter.StartTest(t.Name()) return createNSForTest(ctx, cfg, t, runID) }) testenv.AfterEachTest(func(ctx context.Context, cfg *envconf.Config, t *testing.T) (context.Context, error) { - fmt.Println("AfterEachTest") + fmt.Println("AfterEachTest") updateReporter.StopTest(t.Name(),t.Failed(),t.Skipped(),nil) return deleteNSForTest(ctx, cfg, t, runID) }) @@ -67,17 +111,6 @@ func TestMain(m *testing.M) { }) */ - testenv.Finish( - // Teardown func: delete kind cluster - func(ctx context.Context, cfg *envconf.Config) (context.Context, error) { - fmt.Println("Finished go test suite") - //~ if err := ???; err != nil{ - //~ return ctx, err - //~ } - return ctx, nil - }, - ) - os.Exit(testenv.Run(m)) } diff --git a/Tests/kaas/kaas-sonobuoy-tests/scs_k8s_conformance_tests/main_test.go.template b/Tests/kaas/kaas-sonobuoy-tests/scs_k8s_conformance_tests/main_test.go.template deleted file mode 100644 index 0d3f577a0..000000000 --- a/Tests/kaas/kaas-sonobuoy-tests/scs_k8s_conformance_tests/main_test.go.template +++ /dev/null @@ -1,107 +0,0 @@ -/* -Copyright 2021 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package k8s_test_template - -import ( - "context" - "fmt" - "os" - "testing" - - plugin_helper "github.com/vmware-tanzu/sonobuoy-plugins/plugin-helper" - v1 "k8s.io/api/core/v1" - "sigs.k8s.io/e2e-framework/pkg/env" - "sigs.k8s.io/e2e-framework/pkg/envconf" -) - - -const ( - ProgressReporterCtxKey = "SONOBUOY_PROGRESS_REPORTER" - NamespacePrefixKey = "NS_PREFIX" -) - -var testenv env.Environment - -func TestMain(m *testing.M) { - // Assume we are running in the cluster as a Sonobuoy plugin. - testenv = env.NewInClusterConfig() - - // Specifying a run ID so that multiple runs wouldn't collide. Allow a prefix to be set via env var - // so that a plugin configuration (yaml file) can easily set that without code changes. - nsPrefix := os.Getenv(NamespacePrefixKey) - runID := envconf.RandomName(nsPrefix, 4) - - // Create updateReporter; will also place into context during Setup for use in features. - updateReporter := plugin_helper.NewProgressReporter(0) - - testenv.Setup(func(ctx context.Context, config *envconf.Config) (context.Context, error) { - // Try and create the client; doing it before all the tests allows the tests to assume - // it can be created without error and they can just use config.Client(). - _,err:=config.NewClient() - return context.WithValue(ctx,ProgressReporterCtxKey,updateReporter) ,err - }) - - testenv.BeforeEachTest(func(ctx context.Context, cfg *envconf.Config, t *testing.T) (context.Context, error) { - updateReporter.StartTest(t.Name()) - return createNSForTest(ctx, cfg, t, runID) - }) - testenv.AfterEachTest(func(ctx context.Context, cfg *envconf.Config, t *testing.T) (context.Context, error) { - updateReporter.StopTest(t.Name(),t.Failed(),t.Skipped(),nil) - return deleteNSForTest(ctx, cfg, t, runID) - }) - - /* - testenv.BeforeEachFeature(func(ctx context.Context, config *envconf.Config, info features.Feature) (context.Context, error) { - // Note that you can also add logic here for before a feature is tested. There may be - // more than one feature in a test. - return ctx, nil - }) - testenv.AfterEachFeature(func(ctx context.Context, config *envconf.Config, info features.Feature) (context.Context, error) { - // Note that you can also add logic here for after a feature is tested. There may be - // more than one feature in a test. - return ctx, nil - }) - */ - - os.Exit(testenv.Run(m)) -} - -// CreateNSForTest creates a random namespace with the runID as a prefix. It is stored in the context -// so that the deleteNSForTest routine can look it up and delete it. -func createNSForTest(ctx context.Context, cfg *envconf.Config, t *testing.T, runID string) (context.Context, error) { - ns := envconf.RandomName(runID, 10) - ctx = context.WithValue(ctx, nsKey(t), ns) - - t.Logf("Creating namespace %v for test %v", ns, t.Name()) - nsObj := v1.Namespace{} - nsObj.Name = ns - return ctx, cfg.Client().Resources().Create(ctx, &nsObj) -} - -// DeleteNSForTest looks up the namespace corresponding to the given test and deletes it. -func deleteNSForTest(ctx context.Context, cfg *envconf.Config, t *testing.T, runID string) (context.Context, error) { - ns := fmt.Sprint(ctx.Value(nsKey(t))) - t.Logf("Deleting namespace %v for test %v", ns, t.Name()) - - nsObj := v1.Namespace{} - nsObj.Name = ns - return ctx, cfg.Client().Resources().Delete(ctx, &nsObj) -} - -func nsKey(t *testing.T) string { - return "NS-for-%v" + t.Name() -} diff --git a/Tests/kaas/kaas-sonobuoy-tests/scs_k8s_conformance_tests/scs_0200_example_test.go b/Tests/kaas/kaas-sonobuoy-tests/scs_k8s_conformance_tests/scs_0200_example_test.go deleted file mode 100644 index ee30f453c..000000000 --- a/Tests/kaas/kaas-sonobuoy-tests/scs_k8s_conformance_tests/scs_0200_example_test.go +++ /dev/null @@ -1,83 +0,0 @@ -/* - Copyright 2021 The Kubernetes Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -package scs_k8s_tests - -import ( - "context" - "testing" - "time" - "fmt" - plugin_helper "github.com/vmware-tanzu/sonobuoy-plugins/plugin-helper" - corev1 "k8s.io/api/core/v1" - "sigs.k8s.io/e2e-framework/pkg/envconf" - "sigs.k8s.io/e2e-framework/pkg/features" -) - - -func Test_scs_0200_sonobuoy_pass(t *testing.T) { - fmt.Println("Test a passing test") - testvar := 5 - if testvar != 5 { - t.Errorf("testvar = %d; want 5", testvar) - } -} - -func Test_scs_0200_sonobuoy_fail(t *testing.T) { - fmt.Println("Test a failing test") - testvar := 5 - if testvar != 3 { - t.Errorf("testvar = %d; want 3", testvar) - } -} - -func Test_scs_0200_sonobuoy_TestListPods(t *testing.T) { - f := features.New("pod list").WithLabel("type", "pod-count").Assess( - "pods from kube-system", - func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - var pods corev1.PodList - err := cfg.Client().Resources("kube-system").List(context.TODO(), &pods) - if err != nil { - t.Fatal(err) - } - t.Logf("found %d pods", len(pods.Items)) - if len(pods.Items) == 0 { - t.Fatal("no pods in namespace kube-system") - } - return ctx - }) - - testenv.Test(t, f.Feature()) -} - -func Test_scs_0200_sonobuoy_TestListPods_Long(t *testing.T) { - f := features.New("pod list").WithLabel("type", "progress").Assess( - "pods from kube-system", - func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - var pods corev1.PodList - err := cfg.Client().Resources("kube-system").List(context.TODO(), &pods) - if err != nil { - t.Fatal(err) - } - progressReporterVal := ctx.Value(ProgressReporterCtxKey) - progressReporter:=progressReporterVal.(plugin_helper.ProgressReporter) - for i:=0;i<5;i++{ - time.Sleep(5*time.Second) - progressReporter.SendMessageAsync("Waiting for a long test...") - } - return ctx - }) - - testenv.Test(t, f.Feature()) -} - diff --git a/Tests/kaas/kaas-sonobuoy-tests/scs_k8s_conformance_tests/scs_0200_smoke_test.go b/Tests/kaas/kaas-sonobuoy-tests/scs_k8s_conformance_tests/scs_0200_smoke_test.go new file mode 100644 index 000000000..83909b41a --- /dev/null +++ b/Tests/kaas/kaas-sonobuoy-tests/scs_k8s_conformance_tests/scs_0200_smoke_test.go @@ -0,0 +1,16 @@ +package scs_k8s_tests + +import ( + "testing" + "os" +) + + +func Test_scs_0200_smoke(t *testing.T) { + // This test ensures that no DevelopmentMode was set + // when using this test-suite productively + developmentMode := os.Getenv(DevelopmentModeKey) + if developmentMode != "" { + t.Errorf("developmentMode is set to = %v; want None", developmentMode ) + } +} diff --git a/Tests/kaas/kaas-sonobuoy-tests/scs_k8s_conformance_tests/scs_0201_example_test.go b/Tests/kaas/kaas-sonobuoy-tests/scs_k8s_conformance_tests/scs_0201_example_test.go deleted file mode 100644 index 1771f8058..000000000 --- a/Tests/kaas/kaas-sonobuoy-tests/scs_k8s_conformance_tests/scs_0201_example_test.go +++ /dev/null @@ -1,80 +0,0 @@ -package scs_k8s_tests - -import ( - "context" - "testing" - "time" - "fmt" - plugin_helper "github.com/vmware-tanzu/sonobuoy-plugins/plugin-helper" - corev1 "k8s.io/api/core/v1" - "sigs.k8s.io/e2e-framework/pkg/envconf" - "sigs.k8s.io/e2e-framework/pkg/features" -) - - -func Test_scs_0201_TestDummyIn(t *testing.T) { - fmt.Println("DEBUG: dummy test") - testvar := 5 - if testvar != 3 { - t.Errorf("testvar = %d; want 3", testvar) - } -} - -func Test_scs_0201_TestListPods(t *testing.T) { - f := features.New("pod list").Assess( - "pods from kube-system", - func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - var pods corev1.PodList - err := cfg.Client().Resources("kube-system").List(context.TODO(), &pods) - if err != nil { - t.Fatal(err) - } - t.Logf("found %d pods", len(pods.Items)) - if len(pods.Items) == 0 { - t.Fatal("no pods in namespace kube-system") - } - return ctx - }) - - testenv.Test(t, f.Feature()) -} - -func Test_scs_0201_TestListPodsFailing(t *testing.T) { - f := features.New("pod list").Assess( - "pods from kube-test-a", - func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - var pods corev1.PodList - err := cfg.Client().Resources("kube-test-a").List(context.TODO(), &pods) - if err != nil { - t.Fatal(err) - } - t.Logf("found %d pods", len(pods.Items)) - if len(pods.Items) == 0 { - t.Fatal("no pods in namespace kube-test-a") - } - return ctx - }) - - testenv.Test(t, f.Feature()) -} - -func Test_scs_0201_TestLongTest(t *testing.T) { - f := features.New("pod list").Assess( - "pods from kube-system", - func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - var pods corev1.PodList - err := cfg.Client().Resources("kube-system").List(context.TODO(), &pods) - if err != nil { - t.Fatal(err) - } - progressReporterVal := ctx.Value(ProgressReporterCtxKey) - progressReporter:=progressReporterVal.(plugin_helper.ProgressReporter) - for i:=0;i<5;i++{ - time.Sleep(5*time.Second) - progressReporter.SendMessageAsync("Waiting for a long test...") - } - return ctx - }) - - testenv.Test(t, f.Feature()) -} diff --git a/Tests/kaas/kaas-sonobuoy-tests/scs_k8s_conformance_tests/template_test.go.template b/Tests/kaas/kaas-sonobuoy-tests/scs_k8s_conformance_tests/template_test.go.template deleted file mode 100644 index bf5476938..000000000 --- a/Tests/kaas/kaas-sonobuoy-tests/scs_k8s_conformance_tests/template_test.go.template +++ /dev/null @@ -1,66 +0,0 @@ -/* - Copyright 2021 The Kubernetes Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -package k8s_test_template - -import ( - "context" - "testing" - "time" - - plugin_helper "github.com/vmware-tanzu/sonobuoy-plugins/plugin-helper" - corev1 "k8s.io/api/core/v1" - "sigs.k8s.io/e2e-framework/pkg/envconf" - "sigs.k8s.io/e2e-framework/pkg/features" -) - - -func TestListPods(t *testing.T) { - f := features.New("pod list").Assess( - "pods from kube-system", - func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - var pods corev1.PodList - err := cfg.Client().Resources("kube-system").List(context.TODO(), &pods) - if err != nil { - t.Fatal(err) - } - t.Logf("found %d pods", len(pods.Items)) - if len(pods.Items) == 0 { - t.Fatal("no pods in namespace kube-system") - } - return ctx - }) - - testenv.Test(t, f.Feature()) -} - -func TestLongTest(t *testing.T) { - f := features.New("pod list").Assess( - "pods from kube-system", - func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - var pods corev1.PodList - err := cfg.Client().Resources("kube-system").List(context.TODO(), &pods) - if err != nil { - t.Fatal(err) - } - progressReporterVal := ctx.Value(ProgressReporterCtxKey) - progressReporter:=progressReporterVal.(plugin_helper.ProgressReporter) - for i:=0;i<5;i++{ - time.Sleep(5*time.Second) - progressReporter.SendMessageAsync("Waiting for a long test...") - } - return ctx - }) - - testenv.Test(t, f.Feature()) -} From 87901c68c324633f5c170c783ab297a383eba388 Mon Sep 17 00:00:00 2001 From: Toni Finger Date: Mon, 30 Sep 2024 12:09:07 +0200 Subject: [PATCH 6/7] Fixup scs_k8s_conformance_tests/main_test.go Signed-off-by: Toni Finger --- .../scs_k8s_conformance_tests/main_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Tests/kaas/kaas-sonobuoy-tests/scs_k8s_conformance_tests/main_test.go b/Tests/kaas/kaas-sonobuoy-tests/scs_k8s_conformance_tests/main_test.go index fff5f3d73..8359b1b0f 100644 --- a/Tests/kaas/kaas-sonobuoy-tests/scs_k8s_conformance_tests/main_test.go +++ b/Tests/kaas/kaas-sonobuoy-tests/scs_k8s_conformance_tests/main_test.go @@ -54,10 +54,10 @@ func TestMain(m *testing.M) { case "usecluster": log.Println("Use existing k8s cluster for the test") - log.Println("TO_BE_IMPLEMENTED") - //~ testenv = env.NewFromFlags() + log.Println("Not Yet Implemented") + //~ testenv = env.NewFromFlags() //~ KubeConfig:= os.Getenv(KUBECONFIGFILE) - //~ testenv = env.NewWithKubeConfig(KubeConfig) + //~ testenv = env.NewWithKubeConfig(KubeConfig) default: // Assume we are running in the cluster as a Sonobuoy plugin. From 6561a3121d9a585b4498e70b58d85bc00e36de29 Mon Sep 17 00:00:00 2001 From: Toni Finger Date: Tue, 1 Oct 2024 10:09:33 +0200 Subject: [PATCH 7/7] Update README.md Signed-off-by: Toni Finger --- Tests/kaas/kaas-sonobuoy-tests/README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/Tests/kaas/kaas-sonobuoy-tests/README.md b/Tests/kaas/kaas-sonobuoy-tests/README.md index a8704197c..b5db4532d 100644 --- a/Tests/kaas/kaas-sonobuoy-tests/README.md +++ b/Tests/kaas/kaas-sonobuoy-tests/README.md @@ -87,6 +87,3 @@ make dev-purge export TESTFUNCTION_CODE= make test-function ``` - - -