From 972e6e360ad571e3cb2b8ca3f4e811ffb91dc222 Mon Sep 17 00:00:00 2001 From: Rajat Jindal Date: Mon, 6 May 2024 08:01:02 +0530 Subject: [PATCH] restructure to use common-scripts and reduce Makefile complexity Signed-off-by: Rajat Jindal --- Makefile | 26 ++++++-------- ...n-registry-push.sh => deploy-workloads.sh} | 8 ++++- scripts/run-integration-tests.sh | 21 ++++++++++++ scripts/teardown-workloads.sh | 8 +++++ scripts/workloads.sh | 34 ------------------- .../README.md | 1 + .../workloads.yaml} | 0 .../README.md | 1 + .../workloads.yaml} | 0 9 files changed, 48 insertions(+), 51 deletions(-) rename scripts/{workloads-spin-registry-push.sh => deploy-workloads.sh} (68%) create mode 100644 scripts/run-integration-tests.sh create mode 100755 scripts/teardown-workloads.sh delete mode 100755 scripts/workloads.sh create mode 100644 tests/workloads-pushed-using-docker-build-push/README.md rename tests/{workloads-docker-build-push/workload-docker-build-push.yaml => workloads-pushed-using-docker-build-push/workloads.yaml} (100%) create mode 100644 tests/workloads-pushed-using-spin-registry-push/README.md rename tests/{workloads-spin-registry-push/workload-spin-registry-push.yaml => workloads-pushed-using-spin-registry-push/workloads.yaml} (100%) diff --git a/Makefile b/Makefile index d22f59ac..0c81ac88 100644 --- a/Makefile +++ b/Makefile @@ -38,13 +38,13 @@ up: pod-status-check: ./scripts/pod-status-check.sh -./PHONY: workloads -workloads: - ./scripts/workloads.sh +./PHONY: deploy-workloads-pushed-using-docker-build-push +deploy-workloads-pushed-using-docker-build-push: + ./scripts/deploy-workloads.sh "workloads-pushed-using-docker-build-push" -./PHONY: workloads-spin-registry-push -workloads-spin-registry-push: - ./scripts/workloads-spin-registry-push.sh +./PHONY: deploy-workloads-pushed-using-spin-registry-push +deploy-workloads-pushed-using-spin-registry-push: + ./scripts/deploy-workloads.sh "workloads-pushed-using-spin-registry-push" ./PHONY: pod-terminates-test pod-terminates-test: @@ -54,18 +54,12 @@ pod-terminates-test: integration-tests: prepare-cluster-and-images integration-docker-build-push-tests integration-spin-registry-push-tests .PHONY: integration-docker-build-push-tests -integration-docker-build-push-tests: workloads pod-terminates-test - cargo test -p containerd-shim-spin-tests -- --nocapture - kubectl delete -f tests/workloads-common --wait --timeout 60s --ignore-not-found=true - kubectl delete -f tests/workloads-docker-build-push --wait --timeout 60s --ignore-not-found=true - kubectl wait pod --for=delete -l app=wasm-spin -l app=spin-keyvalue -l app=spin-outbound-redis -l app=spin-multi-trigger-app --timeout 60s +integration-docker-build-push-tests: + ./scripts/run-integration-tests.sh "workloads-pushed-using-docker-build-push" .PHONY: integration-spin-registry-push-tests pod-terminates-test -integration-spin-registry-push-tests: workloads-spin-registry-push - cargo test -p containerd-shim-spin-tests -- --nocapture - kubectl delete -f tests/workloads-common --wait --timeout 60s - kubectl delete -f tests/workloads-spin-registry-push --wait --timeout 60s - kubectl wait pod --for=delete -l app=wasm-spin -l app=spin-keyvalue -l app=spin-outbound-redis -l app=spin-multi-trigger-app --timeout 60s +integration-spin-registry-push-tests: + ./scripts/run-integration-tests.sh "workloads-pushed-using-spin-registry-push" .PHONY: prepare-cluster-and-images prepare-cluster-and-images: check-bins move-bins up pod-status-check diff --git a/scripts/workloads-spin-registry-push.sh b/scripts/deploy-workloads.sh similarity index 68% rename from scripts/workloads-spin-registry-push.sh rename to scripts/deploy-workloads.sh index d86f65c9..245e9b6e 100755 --- a/scripts/workloads-spin-registry-push.sh +++ b/scripts/deploy-workloads.sh @@ -12,8 +12,14 @@ fi # apply the workloads echo ">>> apply workloads" kubectl apply -f tests/workloads-common -kubectl apply -f tests/workloads-spin-registry-push +if [ "$1" == "workloads-pushed-using-spin-registry-push" ]; then + echo "deploying spin apps pushed to registry using 'spin registry push' command" + kubectl apply -f tests/workloads-pushed-using-spin-registry-push +else + echo "deploying spin apps pushed to registry using 'docker build && k3d image import' command" + kubectl apply -f tests/workloads-pushed-using-docker-build-push +fi # wait for all the pods to be ready kubectl wait --for=condition=ready --timeout=50s pod --all diff --git a/scripts/run-integration-tests.sh b/scripts/run-integration-tests.sh new file mode 100644 index 00000000..efe5cbfb --- /dev/null +++ b/scripts/run-integration-tests.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +set -euo pipefail + +## Deploy workloads into k3d cluster +if [ "$1" == "workloads-pushed-using-spin-registry-push" ]; then + make deploy-workloads-pushed-using-spin-registry-push +else + make deploy-workloads-pushed-using-docker-build-push +fi + + + +## Verify pods can be terminated successfully +make pod-terminates-test + +## Run integration tests +cargo test -p containerd-shim-spin-tests -- --nocapture + +## tests done, cleanup workloads for next test +make teardown-workloads \ No newline at end of file diff --git a/scripts/teardown-workloads.sh b/scripts/teardown-workloads.sh new file mode 100755 index 00000000..de245830 --- /dev/null +++ b/scripts/teardown-workloads.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +set -euo pipefail + +kubectl delete -f tests/workloads-common --wait --timeout 60s --ignore-not-found=true +kubectl delete -f tests/workloads-pushed-using-docker-build-push --wait --timeout 60s --ignore-not-found=true +kubectl delete -f tests/workloads-pushed-using-spin-registry-push --wait --timeout 60s --ignore-not-found=true +kubectl wait pod --for=delete -l app=wasm-spin -l app=spin-keyvalue -l app=spin-outbound-redis -l app=spin-multi-trigger-app --timeout 60s \ No newline at end of file diff --git a/scripts/workloads.sh b/scripts/workloads.sh deleted file mode 100755 index 5225d165..00000000 --- a/scripts/workloads.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/bash - -set -euo pipefail - -# Check if kubectl is installed -if ! command -v kubectl &> /dev/null; then - echo "kubectl is not installed. Installing..." - curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" - sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl; -fi - -# apply the workloads -echo ">>> apply workloads" -kubectl apply -f tests/workloads-common -kubectl apply -f tests/workloads-docker-build-push - - -# wait for all the pods to be ready -kubectl wait --for=condition=ready --timeout=50s pod --all - -# get and describe all the pods -echo ">>> Pods:" -kubectl get pods -o wide -kubectl describe pods - -# get and describe all the deployments -echo ">>> Deployments:" -kubectl get deployments -o wide -kubectl describe deployments - -# get and describe all the services -echo ">>> Services:" -kubectl get services -o wide -kubectl describe services \ No newline at end of file diff --git a/tests/workloads-pushed-using-docker-build-push/README.md b/tests/workloads-pushed-using-docker-build-push/README.md new file mode 100644 index 00000000..e1db68bb --- /dev/null +++ b/tests/workloads-pushed-using-docker-build-push/README.md @@ -0,0 +1 @@ +This folder has yaml file to apply workloads which are built using `docker build` and imported into k3d cluster using `k3d image import` command. \ No newline at end of file diff --git a/tests/workloads-docker-build-push/workload-docker-build-push.yaml b/tests/workloads-pushed-using-docker-build-push/workloads.yaml similarity index 100% rename from tests/workloads-docker-build-push/workload-docker-build-push.yaml rename to tests/workloads-pushed-using-docker-build-push/workloads.yaml diff --git a/tests/workloads-pushed-using-spin-registry-push/README.md b/tests/workloads-pushed-using-spin-registry-push/README.md new file mode 100644 index 00000000..299c320a --- /dev/null +++ b/tests/workloads-pushed-using-spin-registry-push/README.md @@ -0,0 +1 @@ +This folder has yaml file to apply workloads which are built using `spin build` and pushed to a registry, managed with k3d in CI, using `spin registry push` command. \ No newline at end of file diff --git a/tests/workloads-spin-registry-push/workload-spin-registry-push.yaml b/tests/workloads-pushed-using-spin-registry-push/workloads.yaml similarity index 100% rename from tests/workloads-spin-registry-push/workload-spin-registry-push.yaml rename to tests/workloads-pushed-using-spin-registry-push/workloads.yaml