Skip to content

Commit

Permalink
(chore): execute e2e from root make
Browse files Browse the repository at this point in the history
  • Loading branch information
abhijith-darshan committed Nov 5, 2024
1 parent 0dd041b commit 26c026c
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 81 deletions.
9 changes: 1 addition & 8 deletions .github/workflows/ci-e2e-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
65 changes: 36 additions & 29 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./...
Expand Down Expand Up @@ -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:
Expand Down
37 changes: 0 additions & 37 deletions e2e/Makefile

This file was deleted.

14 changes: 7 additions & 7 deletions e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.

0 comments on commit 26c026c

Please sign in to comment.