Skip to content

Commit eaafc00

Browse files
authored
Merge pull request #3387 from Skarlso/fix_setup_env
Only setup setup-envtest when the test target is called
2 parents bd55359 + 636dd64 commit eaafc00

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

Makefile

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,6 @@ SETUP_ENVTEST_BIN := setup-envtest
136136
SETUP_ENVTEST := $(abspath $(TOOLS_BIN_DIR)/$(SETUP_ENVTEST_BIN)-$(SETUP_ENVTEST_VER))
137137
SETUP_ENVTEST_PKG := sigs.k8s.io/controller-runtime/tools/setup-envtest
138138

139-
ifeq ($(shell go env GOOS),darwin) # Use the darwin/amd64 binary until an arm64 version is available
140-
KUBEBUILDER_ASSETS ?= $(shell $(SETUP_ENVTEST) use --use-env -p path --arch amd64 $(KUBEBUILDER_ENVTEST_KUBERNETES_VERSION))
141-
else
142-
KUBEBUILDER_ASSETS ?= $(shell $(SETUP_ENVTEST) use --use-env -p path $(KUBEBUILDER_ENVTEST_KUBERNETES_VERSION))
143-
endif
144-
145139
# Enable Cluster API Framework tests for the purposes of running the PR blocking test
146140
ifeq ($(findstring \[PR-Blocking\],$(E2E_FOCUS)),\[PR-Blocking\])
147141
override undefine GINKGO_SKIP
@@ -381,15 +375,26 @@ generate-test-flavors: $(KUSTOMIZE) ## Generate test template flavors
381375
e2e-image: docker-pull-prerequisites $(TOOLS_BIN_DIR)/start.sh $(TOOLS_BIN_DIR)/restart.sh ## Build an e2e test image
382376
docker build -f Dockerfile --tag="gcr.io/k8s-staging-cluster-api/capa-manager:e2e" .
383377

384-
$(SETUP_ENVTEST): # Build setup-envtest from tools folder.
378+
.PHONY: install-setup-envtest
379+
install-setup-envtest: # Install setup-envtest so that setup-envtest's eval is executed after the tool has been installed.
385380
GOBIN=$(abspath $(TOOLS_BIN_DIR)) $(GO_INSTALL) $(SETUP_ENVTEST_PKG) $(SETUP_ENVTEST_BIN) $(SETUP_ENVTEST_VER)
386381

382+
.PHONY: setup-envtest
383+
setup-envtest: install-setup-envtest # Build setup-envtest from tools folder.
384+
@if [ $(shell go env GOOS) == "darwin" ]; then \
385+
$(eval KUBEBUILDER_ASSETS := $(shell $(SETUP_ENVTEST) use --use-env -p path --arch amd64 $(KUBEBUILDER_ENVTEST_KUBERNETES_VERSION))) \
386+
echo "kube-builder assets set using darwin OS"; \
387+
else \
388+
$(eval KUBEBUILDER_ASSETS := $(shell $(SETUP_ENVTEST) use --use-env -p path $(KUBEBUILDER_ENVTEST_KUBERNETES_VERSION))) \
389+
echo "kube-builder assets set using other OS"; \
390+
fi
391+
387392
.PHONY: test
388-
test: $(SETUP_ENVTEST) ## Run tests
393+
test: setup-envtest ## Run tests
389394
KUBEBUILDER_ASSETS="$(KUBEBUILDER_ASSETS)" go test ./...
390395

391396
.PHONY: test-verbose
392-
test-verbose: $(SETUP_ENVTEST) ## Run tests with verbose settings.
397+
test-verbose: setup-envtest ## Run tests with verbose settings.
393398
KUBEBUILDER_ASSETS="$(KUBEBUILDER_ASSETS)" go test -v ./...
394399

395400
.PHONY: test-e2e ## Run e2e tests using clusterctl
@@ -409,7 +414,7 @@ test-conformance: generate-test-flavors $(GINKGO) $(KIND) $(SSM_PLUGIN) $(KUSTOM
409414
time $(GINKGO) -tags=e2e -focus="conformance" $(CONFORMANCE_GINKGO_ARGS) ./test/e2e/suites/conformance/... -- -config-path="$(E2E_CONF_PATH)" $(CONFORMANCE_E2E_ARGS)
410415

411416
.PHONY: test-cover
412-
test-cover: $(SETUP_ENVTEST) ## Run tests with code coverage and code generate reports
417+
test-cover: setup-envtest ## Run tests with code coverage and code generate reports
413418
KUBEBUILDER_ASSETS="$(KUBEBUILDER_ASSETS)" go test -coverprofile=coverage.out ./... $(TEST_ARGS)
414419
go tool cover -func=coverage.out -o coverage.txt
415420
go tool cover -html=coverage.out -o coverage.html

0 commit comments

Comments
 (0)