diff --git a/Makefile b/Makefile index aabdccbe..709e513e 100644 --- a/Makefile +++ b/Makefile @@ -24,6 +24,10 @@ else GOBIN=$(shell go env GOBIN) endif +# KUBEBUILDER_ASSETS path is set as environment variable when running envtest. +ENVTEST_BIN_VERSION = 1.21.4 +KUBEBUILDER_ASSETS = $(shell $(SETUP_ENVTEST) use -i -p path $(ENVTEST_BIN_VERSION)) + # Setting SHELL to bash allows bash commands to be executed by recipes. # This is a requirement for 'setup-envtest.sh' in the test target. # Options are set to exit when a recipe line exits non-zero or a piped command fails. @@ -65,11 +69,9 @@ fmt: ## Run go fmt against code. vet: ## Run go vet against code. go vet ./... -ENVTEST_ASSETS_DIR=$(shell pwd)/testbin -test: manifests generate fmt vet ## Run tests. - mkdir -p ${ENVTEST_ASSETS_DIR} - test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.8.3/hack/setup-envtest.sh - source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out +test: manifests generate fmt vet setup-envtest ## Run tests. + KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) \ + go test ./... -coverprofile cover.out update-kind-nodes: ifndef LATEST_KIND_NODE @@ -120,7 +122,11 @@ deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. $(KUSTOMIZE) build config/default | kubectl delete -f - - +SETUP_ENVTEST = $(shell pwd)/bin/setup-envtest +setup-envtest: + $(call go-get-tool,$(SETUP_ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest) + $(SETUP_ENVTEST) use $(ENVTEST_BIN_VERSION) + CONTROLLER_GEN = $(shell pwd)/bin/controller-gen controller-gen: ## Download controller-gen locally if necessary. $(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.9.0)