From a70a758a1460782d1110d205a1aa59d9a91463e5 Mon Sep 17 00:00:00 2001 From: Lin Yang Date: Mon, 6 Jan 2025 17:10:42 +0800 Subject: [PATCH] test: migrate integration test to run on k3d Signed-off-by: Lin Yang --- .github/workflows/main.yml | 2 +- Makefile | 15 ++++++++++++++- scripts/k3d-with-registry.sh | 8 ++++++-- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 88ee4de5d..db4c549fb 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -552,7 +552,7 @@ jobs: USE_PRIVATE_REGISTRY: "false" run: | touch .env - make kind-up + make k3d-up ./demo/run-fsm-demo.sh go run ./ci/cmd/maestro.go diff --git a/Makefile b/Makefile index 97f22280b..e1b6746d4 100644 --- a/Makefile +++ b/Makefile @@ -33,7 +33,7 @@ DOCKER_BUILDX_OUTPUT ?= type=registry LDFLAGS ?= "-X $(BUILD_DATE_VAR)=$(BUILD_DATE) -X $(BUILD_VERSION_VAR)=$(VERSION) -X $(BUILD_GITCOMMIT_VAR)=$(GIT_SHA) -s -w" # These two values are combined and passed to go test -E2E_FLAGS ?= -installType=KindCluster +E2E_FLAGS ?= -installType=K3dCluster E2E_FLAGS_DEFAULT := -test.v -ginkgo.v -ginkgo.progress -ctrRegistry $(CTR_REGISTRY) -fsmImageTag $(CTR_TAG) # Installed Go version @@ -189,10 +189,18 @@ format-c: kind-up: ./scripts/kind-with-registry.sh +.PHONY: k3d-up +k3d-up: + ./scripts/k3d-with-registry.sh + .PHONY: kind-reset kind-reset: kind delete cluster --name fsm +.PHONY: k3d-reset +k3d-reset: + k3d cluster delete fsm + .PHONY: test-e2e test-e2e: DOCKER_BUILDX_OUTPUT=type=docker test-e2e: docker-build-fsm build-fsm docker-build-tcp-echo-server @@ -206,6 +214,11 @@ kind-demo: export CTR_REGISTRY=localhost:5000 kind-demo: .env kind-up clean-fsm ./demo/run-fsm-demo.sh +.PHONY: k3d-demo +k3d-demo: export CTR_REGISTRY=localhost:5000 +k3d-demo: .env k3d-up clean-fsm + ./demo/run-fsm-demo.sh + .PHONE: build-bookwatcher build-bookwatcher: GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o ./demo/bin/bookwatcher/bookwatcher ./demo/cmd/bookwatcher diff --git a/scripts/k3d-with-registry.sh b/scripts/k3d-with-registry.sh index 439c5b753..1b5f89d2f 100755 --- a/scripts/k3d-with-registry.sh +++ b/scripts/k3d-with-registry.sh @@ -32,11 +32,15 @@ jq_reg_exists=".[] | select(.name == \"$final_reg_name\")" jq_reg_running=".[] | select(.name == \"$final_reg_name\" and .State.Running == true)" num_of_exists=$(k3d registry list -o json | jq "$jq_reg_exists" | jq -s 'length') if [ "${num_of_exists}" == '0' ]; then + # no k3d managed registry found, kill any running registry container and create a new one + docker kill $(docker ps --format json | jq -r 'select(.Image == "registry:2" and .State == "running") | .ID') k3d registry create "$reg_name" --port "127.0.0.1:$reg_port" else num_of_running=$(k3d registry list -o json | jq "$jq_reg_running" | jq -s 'length') - if [ "${num_of_exists}" == '1' ] && [ "${num_of_running}" == '0' ]; then - k3d registry delete "$final_reg_name" + if [ "${num_of_running}" == '0' ]; then + k3d registry delete --all + # no k3d managed registry found, kill any running registry container and create a new one + docker kill $(docker ps --format json | jq -r 'select(.Image == "registry:2" and .State == "running") | .ID') k3d registry create "$reg_name" --port "127.0.0.1:$reg_port" fi fi