@@ -26,8 +26,7 @@ IMAGE_TAG ?= $(GOLANG_VERSION)
2626BUILDIMAGE ?= $(IMAGE ) :$(IMAGE_TAG ) -devel
2727
2828# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
29- ENVTEST_K8S_VERSION = 1.24.2
30- ENVTEST_ASSETS_DIR =$(shell pwd) /testbin
29+ ENVTEST_K8S_VERSION = 1.32.x
3130
3231TARGETS := all check lint go-check generate test cov-report controller-gen golangci-lint gcov2lcov
3332DOCKER_TARGETS := $(patsubst % , docker-% , $(TARGETS ) )
@@ -41,9 +40,11 @@ TOOLSDIR=$(CURDIR)/bin
4140GOLANGCILINT ?= $(TOOLSDIR ) /golangci-lint
4241CONTROLLER_GEN ?= $(TOOLSDIR ) /controller-gen
4342GCOV2LCOV ?= $(TOOLSDIR ) /gcov2lcov
43+ SETUP_ENVTEST ?= $(TOOLSDIR ) /setup-envtest
4444GOLANGCILINT_VERSION ?= v1.62.2
4545CONTROLLER_GEN_VERSION ?= v0.16.5
4646GCOV2LCOV_VERSION ?= v1.1.1
47+ SETUP_ENVTEST_RELEASE ?= release-0.19
4748
4849# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
4950ifeq (,$(shell go env GOBIN) )
@@ -72,11 +73,9 @@ generate: controller-gen ## Generate code
7273 $(CONTROLLER_GEN ) object:headerFile=" hack/boilerplate.go.txt" paths=" ./api/..."
7374 go generate $(MODULE ) /...
7475
75- test : generate; $(info running $(NAME:%=% ) tests...) @ # # Run tests
76- mkdir -p ${ENVTEST_ASSETS_DIR}
77- 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.0/hack/setup-envtest.sh
78- ENVTEST_K8S_VERSION=${ENVTEST_K8S_VERSION} ; . ${ENVTEST_ASSETS_DIR} /setup-envtest.sh; \
79- fetch_envtest_tools $(ENVTEST_ASSETS_DIR ) ; setup_envtest_env $(ENVTEST_ASSETS_DIR ) ; go test ./... -coverprofile cover.out
76+ test : setup-envtest generate; $(info running $(NAME:%=% ) tests...) @ # # Run tests
77+ export KUBEBUILDER_ASSETS=" $( shell $( SETUP_ENVTEST) use -p path $( ENVTEST_K8S_VERSION) ) " && \
78+ go test ./... -coverprofile cover.out
8079
8180cov-report : gcov2lcov test # # Build test coverage report in lcov format
8281 $(GCOV2LCOV ) -infile cover.out -outfile lcov.info
@@ -90,6 +89,9 @@ golangci-lint: ## Download golangci-lint locally if necessary.
9089gcov2lcov : # # Download gcov2lcov locally if necessary.
9190 $(call go-install-tool,$(GCOV2LCOV ) ,github.com/jandelgado/gcov2lcov@$(GCOV2LCOV_VERSION ) )
9291
92+ setup-envtest : # # Download setup-envtest locally if necessary
93+ $(call go-install-tool,$(SETUP_ENVTEST ) ,sigs.k8s.io/controller-runtime/tools/setup-envtest@$(SETUP_ENVTEST_RELEASE ) )
94+
9395# Generate an image for containerized builds
9496# Note: This image is local only
9597.PHONY : .build-image .pull-build-image .push-build-image
0 commit comments