diff --git a/Makefile b/Makefile index 4b7b159de..7d1c24467 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,6 @@ +# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary. +ENVTEST_K8S_VERSION = 1.26.0 + # Adding .PHONY to hold command shortcuts. .PHONY: release @@ -100,12 +103,16 @@ all: test docker-build # Run tests test: build test-only -test-only: - @echo - @echo "If tests fail due to no matches for kind \"CustomResourceDefinition\" in version \"apiextensions.k8s.io/v1\"," - @echo "please remove the old kubebuilder and reinstall it - https://book.kubebuilder.io/quick-start.html#installation" - @echo - go test ${DIRS} -coverprofile cover.out +LOCALBIN ?= $(shell pwd)/hack +ENVTEST ?= $(LOCALBIN)/setup-envtest + +test-only: envtest + KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ${DIRS} -coverprofile cover.out + +.PHONY: envtest +envtest: $(ENVTEST) ## Download envtest-setup locally if necessary. +$(ENVTEST): $(LOCALBIN) + test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest # Builds all binaries (manager and kubectl) and manifests build: generate fmt vet staticcheck manifests