Skip to content

Commit 636dd64

Browse files
committed
Only setup setup-envtest when the test target is called
1 parent b038843 commit 636dd64

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
@@ -379,15 +373,26 @@ generate-test-flavors: $(KUSTOMIZE) ## Generate test template flavors
379373
e2e-image: docker-pull-prerequisites $(TOOLS_BIN_DIR)/start.sh $(TOOLS_BIN_DIR)/restart.sh ## Build an e2e test image
380374
docker build -f Dockerfile --tag="gcr.io/k8s-staging-cluster-api/capa-manager:e2e" .
381375

382-
$(SETUP_ENVTEST): # Build setup-envtest from tools folder.
376+
.PHONY: install-setup-envtest
377+
install-setup-envtest: # Install setup-envtest so that setup-envtest's eval is executed after the tool has been installed.
383378
GOBIN=$(abspath $(TOOLS_BIN_DIR)) $(GO_INSTALL) $(SETUP_ENVTEST_PKG) $(SETUP_ENVTEST_BIN) $(SETUP_ENVTEST_VER)
384379

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

389394
.PHONY: test-verbose
390-
test-verbose: $(SETUP_ENVTEST) ## Run tests with verbose settings.
395+
test-verbose: setup-envtest ## Run tests with verbose settings.
391396
KUBEBUILDER_ASSETS="$(KUBEBUILDER_ASSETS)" go test -v ./...
392397

393398
.PHONY: test-e2e ## Run e2e tests using clusterctl
@@ -407,7 +412,7 @@ test-conformance: generate-test-flavors $(GINKGO) $(KIND) $(SSM_PLUGIN) $(KUSTOM
407412
time $(GINKGO) -tags=e2e -focus="conformance" $(CONFORMANCE_GINKGO_ARGS) ./test/e2e/suites/conformance/... -- -config-path="$(E2E_CONF_PATH)" $(CONFORMANCE_E2E_ARGS)
408413

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

0 commit comments

Comments
 (0)