Skip to content

Commit

Permalink
test: migrate integration test to run on k3d
Browse files Browse the repository at this point in the history
Signed-off-by: Lin Yang <[email protected]>
  • Loading branch information
reaver-flomesh committed Jan 6, 2025
1 parent f210b3b commit a70a758
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 6 additions & 2 deletions scripts/k3d-with-registry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a70a758

Please sign in to comment.