@@ -32,6 +32,20 @@ export IMAGE_TAG
3232OPCON_IMG := $(OPCON_IMAGE_REPO ) :$(IMAGE_TAG )
3333CATD_IMG := $(CATD_IMAGE_REPO ) :$(IMAGE_TAG )
3434
35+ # Extract Kubernetes client-go version used to set the version to the PSA labels, for ENVTEST and KIND
36+ ifeq ($(origin K8S_VERSION ) , undefined)
37+ K8S_VERSION := $(shell go list -m k8s.io/client-go | cut -d" " -f2 | sed -E 's/^v0\.([0-9]+) \.[0-9]+$$/1.\1/')
38+ endif
39+
40+ # Ensure ENVTEST_VERSION follows correct "X.Y.x" format
41+ ENVTEST_VERSION := $(K8S_VERSION ) .x
42+
43+ # 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.)
44+ # The K8S_VERSION is set by getting the version of the k8s.io/client-go dependency from the go.mod
45+ # and sets major version to "1" and the patch version to "0". For example, a client-go version of v0.28.5
46+ # will map to a K8S_VERSION of 1.28.0
47+ KIND_CLUSTER_IMAGE := kindest/node:v$(K8S_VERSION ) .0
48+
3549# Define dependency versions (use go.mod if we also use Go code from dependency)
3650export CERT_MGR_VERSION := v1.15.3
3751export WAIT_TIMEOUT := 60s
@@ -54,12 +68,6 @@ ifeq ($(origin KIND_CLUSTER_NAME), undefined)
5468KIND_CLUSTER_NAME := operator-controller
5569endif
5670
57- # 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.)
58- # The KIND_NODE_VERSION is set by getting the version of the k8s.io/client-go dependency from the go.mod
59- # and sets major version to "1" and the patch version to "0". For example, a client-go version of v0.28.5
60- # will map to a KIND_NODE_VERSION of 1.28.0
61- KIND_NODE_VERSION := $(shell go list -m k8s.io/client-go | cut -d" " -f2 | sed 's/^v0\.\([[:digit:]]\{1,\}\) \.[[:digit:]]\{1,\}$$/1.\1.0/')
62- KIND_CLUSTER_IMAGE := kindest/node:v$(KIND_NODE_VERSION )
6371
6472ifneq (, $(shell command -v docker 2>/dev/null) )
6573CONTAINER_RUNTIME := docker
@@ -143,9 +151,15 @@ generate: $(CONTROLLER_GEN) #EXHELP Generate code containing DeepCopy, DeepCopyI
143151 $(CONTROLLER_GEN ) object:headerFile=" hack/boilerplate.go.txt" paths=" ./..."
144152
145153.PHONY : verify
146- verify : tidy fmt generate manifests crd-ref-docs # HELP Verify all generated code is up-to-date.
154+ verify : tidy fmt generate manifests crd-ref-docs update-k8s-values # HELP Verify all generated code is up-to-date.
147155 git diff --exit-code
148156
157+ .PHONY : update-k8s-values # HELP Update PSA labels in config manifests with Kubernetes version
158+ update-k8s-values :
159+ find config -type f -name ' *.yaml' -exec \
160+ sed -i.bak -E ' s/(pod-security.kubernetes.io\/[a-zA-Z-]+-version:).*/\1 "v$(K8S_VERSION)"/g' {} +;
161+ find config -type f -name ' *.yaml.bak' -delete
162+
149163.PHONY : fix-lint
150164fix-lint : $(GOLANGCI_LINT ) # EXHELP Fix lint issues
151165 $(GOLANGCI_LINT ) run --fix --build-tags $(GO_BUILD_TAGS ) $(GOLANGCI_LINT_ARGS )
@@ -194,7 +208,6 @@ test-ext-dev-e2e: $(OPERATOR_SDK) $(KUSTOMIZE) $(KIND) #HELP Run extension creat
194208 test/extension-developer-e2e/setup.sh $(OPERATOR_SDK ) $(CONTAINER_RUNTIME ) $(KUSTOMIZE ) $(KIND ) $(KIND_CLUSTER_NAME ) $(E2E_REGISTRY_NAMESPACE )
195209 go test -count=1 -v ./test/extension-developer-e2e/...
196210
197- ENVTEST_VERSION := $(shell go list -m k8s.io/client-go | cut -d" " -f2 | sed 's/^v0\.\([[:digit:]]\{1,\}\) \.[[:digit:]]\{1,\}$$/1.\1.x/')
198211UNIT_TEST_DIRS := $(shell go list ./... | grep -v /test/)
199212COVERAGE_UNIT_DIR := $(ROOT_DIR ) /coverage/unit
200213
0 commit comments