From 26c026c2d130ec5ec3d6bb511d08ade53c7d8e7c Mon Sep 17 00:00:00 2001 From: Abhijith Ravindra Date: Tue, 5 Nov 2024 07:43:20 +0100 Subject: [PATCH] (chore): execute e2e from root make --- .github/workflows/ci-e2e-test.yaml | 9 +---- Makefile | 65 +++++++++++++++++------------- e2e/Makefile | 37 ----------------- e2e/README.md | 14 +++---- 4 files changed, 44 insertions(+), 81 deletions(-) delete mode 100644 e2e/Makefile diff --git a/.github/workflows/ci-e2e-test.yaml b/.github/workflows/ci-e2e-test.yaml index f96f5ba6..c7ee1639 100644 --- a/.github/workflows/ci-e2e-test.yaml +++ b/.github/workflows/ci-e2e-test.yaml @@ -73,13 +73,7 @@ jobs: - name: "Prepare E2E Config" id: config run: | - make cli - ${{ github.workspace }}/bin/greenhousectl dev setup -f ${{ github.workspace }}/e2e/config.json - - kind get kubeconfig --name ${{ env.ADMIN_CLUSTER}} > ${{ github.workspace }}/bin/${{env.ADMIN_CLUSTER}}.kubeconfig - kind get kubeconfig --name ${{ env.REMOTE_CLUSTER}} > ${{ github.workspace }}/bin/${{env.REMOTE_CLUSTER}}.kubeconfig - kind get kubeconfig --name ${{ env.REMOTE_CLUSTER}} --internal > ${{ github.workspace }}/bin/${{env.REMOTE_CLUSTER}}-int.kubeconfig - + make setup-e2e echo "admin_config=$GITHUB_WORKSPACE/bin/${{env.ADMIN_CLUSTER}}.kubeconfig" >> $GITHUB_OUTPUT echo "remote_config=$GITHUB_WORKSPACE/bin/${{env.REMOTE_CLUSTER}}.kubeconfig" >> $GITHUB_OUTPUT echo "remote_int_config=$GITHUB_WORKSPACE/bin/${{env.REMOTE_CLUSTER}}-int.kubeconfig" >> $GITHUB_OUTPUT @@ -88,7 +82,6 @@ jobs: - name: "E2E Run" id: e2e continue-on-error: true - working-directory: ${{ github.workspace }}/e2e env: SCENARIO: ${{ matrix.e2es }} EXECUTION_ENV: gh-actions diff --git a/Makefile b/Makefile index 1574b58e..0ed5f48d 100644 --- a/Makefile +++ b/Makefile @@ -102,27 +102,6 @@ generate-documentation: check-gen-crd-api-reference-docs test: generate-manifests generate envtest ## Run tests. KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out -v -.PHONY: e2e -e2e: - go test -tags="e2e" ./test/e2e/... -coverprofile cover.out -test.v - -.PHONY: e2e-local -e2e-local: generate-manifests generate envtest ## Run e2e tests against mock api. - unset USE_EXISTING_CLUSTER && KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test -tags="e2e" ./test/e2e/... -coverprofile cover.out -ginkgo.v -test.v - -.PHONY: e2e-remote -e2e-remote: ## Run e2e tests against a remote Greenhouse cluster. TEST_KUBECONFIG must be set. - USE_EXISTING_CLUSTER=true go test -tags="e2e" ./test/e2e/... -coverprofile cover.out -ginkgo.v -test.v - -.PHONY: e2e-local-cluster -e2e-local-cluster: e2e-local-cluster-create ## Run e2e tests on a local KIND cluster. - USE_EXISTING_CLUSTER=true TEST_KUBECONFIG=$(shell pwd)/test/e2e/local-cluster/e2e.kubeconfig INTERNAL_KUBECONFIG=$(shell pwd)/test/e2e/local-cluster/e2e.internal.kubeconfig go test -tags="e2e" ./test/e2e/... -coverprofile cover.out -ginkgo.v -test.v - -.PHONY: e2e-local-cluster-create -e2e-local-cluster-create: - cd test/e2e/local-cluster && go run . --dockerImagePlatform=$(PLATFORM) - - .PHONY: fmt fmt: goimports GOBIN=$(LOCALBIN) go fmt ./... @@ -250,24 +229,52 @@ else cd website && hugo server endif -.PHONY: setup-dev -setup-dev: cli - $(CLI) dev setup -f dev-env/localenv/sample.config.json - -.PHONY: dev-docs -dev-docs: - go run -tags="dev" -mod=mod dev-env/localenv/docs.go - +SCENARIO ?= cluster ADMIN_CLUSTER ?= greenhouse-admin +REMOTE_CLUSTER ?=greenhouse-remote +EXECUTION_ENV ?= LOCAL ADMIN_NAMESPACE ?= greenhouse ADMIN_RELEASE ?= greenhouse ADMIN_CHART_PATH ?= charts/manager WEBHOOK_DEV ?= false +.PHONY: setup-dev +setup-dev: cli + $(CLI) dev setup -f dev-env/localenv/sample.config.json + .PHONY: setup-webhook setup-webhook: cli $(CLI) dev setup webhook --name $(ADMIN_CLUSTER) --namespace $(ADMIN_NAMESPACE) --release $(ADMIN_RELEASE) --chart-path $(ADMIN_CHART_PATH) --dockerfile ./ --dev-mode=$(WEBHOOK_DEV) +.PHONY: setup-e2e +setup-e2e: cli + $(CLI) dev setup -f e2e/config.json + make prepare-e2e + +.PHONY: e2e +e2e: + GOMEGA_DEFAULT_EVENTUALLY_TIMEOUT="2m" go test -tags="$(SCENARIO)E2E" ${PWD}/e2e/$(SCENARIO) -mod=readonly -test.v -ginkgo.v + +.PHONY: e2e-local +e2e-local: prepare-e2e + GREENHOUSE_ADMIN_KUBECONFIG="${PWD}/bin/$(ADMIN_CLUSTER).kubeconfig" \ + GREENHOUSE_REMOTE_KUBECONFIG="${PWD}/bin/$(REMOTE_CLUSTER).kubeconfig" \ + GREENHOUSE_REMOTE_INT_KUBECONFIG="${PWD}/bin/$(REMOTE_CLUSTER)-int.kubeconfig" \ + CONTROLLER_LOGS_PATH="${PWD}/bin/$(SCENARIO)-e2e-pod-logs.txt" \ + EXECUTION_ENV=$(EXECUTION_ENV) \ + GOMEGA_DEFAULT_EVENTUALLY_TIMEOUT="2m" \ + go test -tags="$(SCENARIO)E2E" ${PWD}/e2e/$(SCENARIO) -test.v -ginkgo.v + +.PHONY: prepare-e2e +prepare-e2e: + kind get kubeconfig --name $(ADMIN_CLUSTER) > ${PWD}/bin/$(ADMIN_CLUSTER).kubeconfig + kind get kubeconfig --name $(REMOTE_CLUSTER) > ${PWD}/bin/$(REMOTE_CLUSTER).kubeconfig + kind get kubeconfig --name $(REMOTE_CLUSTER) --internal > ${PWD}/bin/$(REMOTE_CLUSTER)-int.kubeconfig + +.PHONY: dev-docs +dev-docs: + go run -tags="dev" -mod=mod dev-env/localenv/docs.go + # Download and install mockery locally via `brew install mockery` MOCKERY := $(shell which mockery) mockery: diff --git a/e2e/Makefile b/e2e/Makefile deleted file mode 100644 index dc14cbc9..00000000 --- a/e2e/Makefile +++ /dev/null @@ -1,37 +0,0 @@ -SCENARIO ?= cluster -NAME ?= -ADMIN_CLUSTER ?=greenhouse-admin -REMOTE_CLUSTER ?=greenhouse-remote -EXECUTION_ENV ?= LOCAL - -.PHONY: e2e-local -e2e-local: prepare - GREENHOUSE_ADMIN_KUBECONFIG="${PWD}/../bin/$(ADMIN_CLUSTER).kubeconfig" \ - GREENHOUSE_REMOTE_KUBECONFIG="${PWD}/../bin/$(REMOTE_CLUSTER).kubeconfig" \ - GREENHOUSE_REMOTE_INT_KUBECONFIG="${PWD}/../bin/$(REMOTE_CLUSTER)-int.kubeconfig" \ - CONTROLLER_LOGS_PATH="${PWD}/../bin/$(SCENARIO)-e2e-pod-logs.txt" \ - EXECUTION_ENV=$(EXECUTION_ENV) \ - GOMEGA_DEFAULT_EVENTUALLY_TIMEOUT="2m" \ - go test -tags="$(SCENARIO)E2E" ./$(SCENARIO) -test.v -ginkgo.v - -.PHONY: e2e -e2e: - GOMEGA_DEFAULT_EVENTUALLY_TIMEOUT="2m" go test -tags="$(SCENARIO)E2E" ./$(SCENARIO) -mod=readonly -test.v -ginkgo.v - -.PHONY: admin-cluster -admin-cluster: - kind create cluster --name $(ADMIN_CLUSTER) - -.PHONY: remote-cluster -remote-cluster: - kind create cluster --name $(REMOTE_CLUSTER) --config kind-config.yaml - -.PHONY: delete-cluster -delete-cluster: - kind delete cluster --name $(NAME) - -.PHONY: prepare -prepare: - kind get kubeconfig --name $(ADMIN_CLUSTER) > ../bin/$(ADMIN_CLUSTER).kubeconfig - kind get kubeconfig --name $(REMOTE_CLUSTER) > ../bin/$(REMOTE_CLUSTER).kubeconfig - kind get kubeconfig --name $(REMOTE_CLUSTER) --internal > ../bin/$(REMOTE_CLUSTER)-int.kubeconfig diff --git a/e2e/README.md b/e2e/README.md index cecd68ff..45168441 100644 --- a/e2e/README.md +++ b/e2e/README.md @@ -164,7 +164,6 @@ Example (Goland): ### Tips Pod logs for the controller manager and webhooks can be very long and can be difficult to read especially when you are running multiple tests. - If you want to get logs for a specific test and you have set the `CONTROLLER_LOGS_PATH` environment variable, you can extract the logs from a specific time. Example: @@ -203,22 +202,23 @@ var _ = AfterSuite(func() { This is not foolproof as there could be reconciliations happening on different resources, especially in a real cluster, but it can help in narrowing down the logs to a specific test run. -If you are using `Eventually` in your tests, you need to ensure that the result that you are expecting actually happens quickly as the default timeout for `Eventually` is 1 second. +If `Eventually` in used in tests, ensure that the result being expected happens quickly. + +> The test is started with the env GOMEGA_DEFAULT_EVENTUALLY_TIMEOUT="2m" -If you are expecting something to happen but takes longer than 1 second, you can increase the timeout for `Eventually` by passing the timeout value as the first argument. +If some result is expected to happen, but takes longer than 2m, the timeout for `Eventually` can be increased by passing the timeout value as the first argument. Example: ```go Eventually(func() bool { // your code here -}, 10*time.Second, 1*time.Second).Should(BeTrue()) +}, 150*time.Second, 10*time.Second).Should(BeTrue()) ``` -This will wait for 10 seconds for the condition to be true, checking every 1 second. +This will wait for 150 seconds for the condition to be true, polling every 10 seconds. Alternatively, you can use `WaitUntilResourceReadyOrNotReady` in [e2e](../pkg/e2e/e2e.go) to wait for a resource to be ready or not ready. - -`WaitUntilResourceReadyOrNotReady` has a timeout of 2 minutes with exponential backoff and will wait for a resource to be ready or not ready. +`WaitUntilResourceReadyOrNotReady` has a timeout of 3 minutes with exponential backoff and will wait for a resource to be ready or not ready. > Note: You can only use `WaitUntilResourceReadyOrNotReady` for resources that use the `lifecycle.Reconcile` interface. \ No newline at end of file