@@ -28,8 +28,6 @@ export GO111MODULE=on
2828YQ_INTERNAL := go run $(MOD_FLAGS ) ./vendor/github.com/mikefarah/yq/v3/
2929HELM := go run $(MOD_FLAGS ) ./vendor/helm.sh/helm/v3/cmd/helm
3030KIND := go run $(MOD_FLAGS ) ./vendor/sigs.k8s.io/kind
31- KUBEBUILDER_ASSETS := $(or $(or $(KUBEBUILDER_ASSETS ) ,$(dir $(shell command -v kubebuilder) ) ) ,/usr/local/kubebuilder/bin)
32- export KUBEBUILDER_ASSETS
3331GO := GO111MODULE=on GOFLAGS="$(MOD_FLAGS ) " go
3432GINKGO := $(GO ) run github.com/onsi/ginkgo/v2/ginkgo
3533BINDATA := $(GO ) run github.com/go-bindata/go-bindata/v3/go-bindata
4139ARCH := amd64
4240endif
4341
42+ # Track the minor version of kubernetes we are building against by looking at the client-go dependency version
43+ # For example, a client-go version of v0.28.5 will map to kube version 1.28
44+ KUBE_MINOR ?= $(shell go list -m k8s.io/client-go | cut -d" " -f2 | sed 's/^v0\.\([[:digit:]]\{1,\}\) \.[[:digit:]]\{1,\}$$/1.\1/')
45+
46+ # Unit test against the latest available version for the minor version of kubernetes we are building against e.g. 1.30.x
47+ ENVTEST_KUBE_VERSION ?= $(KUBE_MINOR ) .x
48+
49+ # Not guaranteed to have patch releases available and node image tags are full versions (i.e v1.28.0 - not v1.28, v1.29, etc.)
50+ KIND_NODE_VERSION ?= $(KUBE_MINOR ) .0
4451KIND_CLUSTER_NAME ?= kind-olmv0
45- # Not guaranteed to have patch releases available and node image tags are full versions (i.e v1.28.0 - no v1.28, v1.29, etc.)
46- # The KIND_NODE_VERSION is set by getting the version of the k8s.io/client-go dependency from the go.mod
47- # and sets major version to "1" and the patch version to "0". For example, a client-go version of v0.28.5
48- # will map to a KIND_NODE_VERSION of 1.28.0
49- KIND_NODE_VERSION := $(shell go list -m k8s.io/client-go | cut -d" " -f2 | sed 's/^v0\.\([[:digit:]]\{1,\}\) \.[[:digit:]]\{1,\}$$/1.\1.0/')
5052KIND_CLUSTER_IMAGE := kindest/node:v$(KIND_NODE_VERSION )
5153
5254# Phony prerequisite for targets that rely on the go build cache to determine staleness.
6466all : test build
6567
6668test : clean cover.out
67-
68- unit : kubebuilder
69+ .PHONY : unit
70+ KUBEBUILDER_ASSETS ?= $(shell $(SETUP_ENVTEST ) use -p path $(ENVTEST_KUBE_VERSION ) )
71+ unit :
72+ @echo " Running unit tests with kubebuilder assets at $( KUBEBUILDER_ASSETS) "
73+ @echo " Running kube version: $( shell ${KUBEBUILDER_ASSETS} /kubectl version) "
6974 KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS ) go test $(MOD_FLAGS ) $(SPECIFIC_UNIT_TEST ) -tags " json1" -race -count=1 ./pkg/... ./test/e2e/split/...
7075
71- # Ensure kubectl installed before continuing
72- KUBEBUILDER_ASSETS_ERR := not detected in $(KUBEBUILDER_ASSETS ) , to override the assets path set the KUBEBUILDER_ASSETS environment variable, for install instructions see https://pkg.go.dev/sigs.k8s.io/controller-runtime/tools/setup-envtest
73- KUBECTL_ASSETS_ERR := kubectl not detected.
74- kubebuilder :
75- ifeq (, $(shell which kubectl) )
76- $(error $(KUBECTL_ASSETS_ERR))
77- endif
78- ifeq (, $(wildcard $(KUBEBUILDER_ASSETS ) /etcd) )
79- $(error etcd $(KUBEBUILDER_ASSETS_ERR))
80- endif
81- ifeq (, $(wildcard $(KUBEBUILDER_ASSETS ) /kube-apiserver) )
82- $(error kube-apiserver $(KUBEBUILDER_ASSETS_ERR))
83- endif
84-
8576cover.out :
8677 go test $(MOD_FLAGS ) -tags " json1" -race -coverprofile=cover.out -covermode=atomic \
8778 -coverpkg ./pkg/controller/... ./pkg/...
0 commit comments