From 01c8ff719ad801c3b19d914341bf529e152d3ab3 Mon Sep 17 00:00:00 2001 From: Timo Riski Date: Thu, 25 Jan 2024 09:50:54 +0200 Subject: [PATCH] feat(makefile): install kubebuilder assets in 'envtest' target This commit makes it easier to point IDE KUBEBUILDER_ASSETS env vars to the correct path. Previously, one would have to uncomment the `go test...` line in the `test` target to get kubebuilder assets installed in $LOCALBIN. --- Makefile | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 099620fd..f78a7827 100644 --- a/Makefile +++ b/Makefile @@ -51,6 +51,7 @@ IMG ?= aivenoy/aiven-operator:${IMG_TAG} IMG_TAG ?= $(shell git rev-parse HEAD) # ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary. ENVTEST_K8S_VERSION = "1.26.*" +KUBEBUILDER_ASSETS_CMD = '$(ENVTEST) use "$(ENVTEST_K8S_VERSION)" --bin-dir $(LOCALBIN) -p path' # Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) ifeq (,$(shell go env GOBIN)) @@ -126,7 +127,7 @@ test-e2e-preinstalled: kubectl kuttl test --config test/e2e/kuttl-test.preinstalled.yaml test: envtest ## Run tests. - KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" \ + export KUBEBUILDER_ASSETS=$(shell eval ${KUBEBUILDER_ASSETS_CMD}); \ go test ./tests/... -race -run=$(run) -v -timeout 42m -parallel 10 -cover -coverpkg=./controllers -covermode=atomic -coverprofile=coverage.out ##@ Build @@ -211,10 +212,13 @@ controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessar $(CONTROLLER_GEN): $(LOCALBIN) $(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen,$(CONTROLLER_TOOLS_VERSION)) +# KUBEBUILDER_ASSETS is installed in this target so that it can be used by e.g. IDE test integrations. .PHONY: envtest envtest: $(ENVTEST) ## Download setup-envtest locally if necessary. $(ENVTEST): $(LOCALBIN) - $(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest,$(ENVTEST_VERSION)) + $(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest,$(ENVTEST_VERSION)) ;\ + echo -e "\n>>Installing kubebuilder assets to path:"; \ + eval $(KUBEBUILDER_ASSETS_CMD) .PHONY: golangci-lint golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.