Skip to content

Commit 221c3e7

Browse files
consolidate go list -m k8s.io/client-go calls for ENVTEST_VERSION, KUBE_VERSION, and KIND_NODE_VERSION
Avoid multiple redundant shell executions by extracting the client-go version once and deriving ENVTEST_VERSION, KUBE_VERSION (for PSA label), and KIND_NODE_VERSION from it. This improves efficiency and prevents unnecessary re-evaluations in Makefile.
1 parent bde4f4e commit 221c3e7

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

Makefile

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ export IMAGE_TAG
3232
OPCON_IMG := $(OPCON_IMAGE_REPO):$(IMAGE_TAG)
3333
CATD_IMG := $(CATD_IMAGE_REPO):$(IMAGE_TAG)
3434

35+
# Extract the Kubernetes client-go version to set K8S_VERSION used in the manifests.
36+
ifeq ($(origin K8S_CLIENT_GO_VERSION), undefined)
37+
K8S_VERSION := $(shell go list -m k8s.io/client-go | cut -d" " -f2 | sed 's/^v0\.\([[:digit:]]\{1,\}\)\.[[:digit:]]\{1,\}$$/1.\1/')
38+
endif
39+
3540
# Define dependency versions (use go.mod if we also use Go code from dependency)
3641
export CERT_MGR_VERSION := v1.15.3
3742
export WAIT_TIMEOUT := 60s
@@ -55,11 +60,10 @@ KIND_CLUSTER_NAME := operator-controller
5560
endif
5661

5762
# 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
63+
# The K8S_VERSION is set by getting the version of the k8s.io/client-go dependency from the go.mod
5964
# 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)
65+
# will map to a K8S_VERSION of 1.28.0
66+
KIND_CLUSTER_IMAGE := kindest/node:v$(K8S_VERSION).0
6367

6468
ifneq (, $(shell command -v docker 2>/dev/null))
6569
CONTAINER_RUNTIME := docker
@@ -146,13 +150,10 @@ generate: $(CONTROLLER_GEN) #EXHELP Generate code containing DeepCopy, DeepCopyI
146150
verify: tidy fmt generate manifests crd-ref-docs update-k8s-values #HELP Verify all generated code is up-to-date.
147151
git diff --exit-code
148152

149-
# Minor Kubernetes version to build against derived from the client-go dependency version
150-
KUBE_MINOR ?= $(shell go list -m k8s.io/client-go | cut -d" " -f2 | sed 's/^v0\.\([[:digit:]]\{1,\}\)\.[[:digit:]]\{1,\}$$/1.\1/')
151-
152153
.PHONY: update-k8s-values # HELP Update PSA labels in config manifests with Kubernetes version
153154
update-k8s-values:
154155
find config -type f -name '*.yaml' -exec \
155-
sed -i.bak -E 's/(pod-security.kubernetes.io\/[a-zA-Z-]+-version:).*/\1 "v$(KUBE_MINOR)"/g' {} +;
156+
sed -i.bak -E 's/(pod-security.kubernetes.io\/[a-zA-Z-]+-version:).*/\1 "v$(K8S_VERSION)"/g' {} +;
156157
find config -type f -name '*.yaml.bak' -delete
157158

158159
.PHONY: fix-lint
@@ -203,14 +204,13 @@ test-ext-dev-e2e: $(OPERATOR_SDK) $(KUSTOMIZE) $(KIND) #HELP Run extension creat
203204
test/extension-developer-e2e/setup.sh $(OPERATOR_SDK) $(CONTAINER_RUNTIME) $(KUSTOMIZE) $(KIND) $(KIND_CLUSTER_NAME) $(E2E_REGISTRY_NAMESPACE)
204205
go test -count=1 -v ./test/extension-developer-e2e/...
205206

206-
ENVTEST_VERSION := $(shell go list -m k8s.io/client-go | cut -d" " -f2 | sed 's/^v0\.\([[:digit:]]\{1,\}\)\.[[:digit:]]\{1,\}$$/1.\1.x/')
207207
UNIT_TEST_DIRS := $(shell go list ./... | grep -v /test/)
208208
COVERAGE_UNIT_DIR := $(ROOT_DIR)/coverage/unit
209209

210210
.PHONY: envtest-k8s-bins #HELP Uses setup-envtest to download and install the binaries required to run ENVTEST-test based locally at the project/bin directory.
211211
envtest-k8s-bins: $(SETUP_ENVTEST)
212212
mkdir -p $(ROOT_DIR)/bin
213-
$(SETUP_ENVTEST) use -p env $(ENVTEST_VERSION) $(SETUP_ENVTEST_BIN_DIR_OVERRIDE)
213+
$(SETUP_ENVTEST) use -p env $(KUBE_MINOR).x $(SETUP_ENVTEST_BIN_DIR_OVERRIDE)
214214

215215
.PHONY: test-unit
216216
test-unit: $(SETUP_ENVTEST) envtest-k8s-bins #HELP Run the unit tests

0 commit comments

Comments
 (0)