Skip to content

Commit 620792e

Browse files
(fix): update PSA versions to match Kubernetes API version
derive Kubernetes minor version from client-go for PSA updates - Add `update-k8s-values` Make target to update PSA (Pod Security Admission) labels in YAML manifests with the correct Kubernetes version. - Ensure PSA version aligns with the supported Kubernetes version, not the latest, to prevent potential breaking changes. - consolidate go list -m k8s.io/client-go calls for ENVTEST_VERSION, KUBE_VERSION, and KIND_NODE_VERSION
1 parent c987cff commit 620792e

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

Makefile

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,20 @@ export IMAGE_TAG
3232
OPCON_IMG := $(OPCON_IMAGE_REPO):$(IMAGE_TAG)
3333
CATD_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)
3650
export CERT_MGR_VERSION := v1.15.3
3751
export WAIT_TIMEOUT := 60s
@@ -54,12 +68,6 @@ ifeq ($(origin KIND_CLUSTER_NAME), undefined)
5468
KIND_CLUSTER_NAME := operator-controller
5569
endif
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

6472
ifneq (, $(shell command -v docker 2>/dev/null))
6573
CONTAINER_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
150164
fix-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/')
198211
UNIT_TEST_DIRS := $(shell go list ./... | grep -v /test/)
199212
COVERAGE_UNIT_DIR := $(ROOT_DIR)/coverage/unit
200213

config/base/common/namespace.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ metadata:
44
labels:
55
app.kubernetes.io/part-of: olm
66
pod-security.kubernetes.io/enforce: baseline
7-
pod-security.kubernetes.io/enforce-version: latest
7+
pod-security.kubernetes.io/enforce-version: "v1.32"
88
name: system

0 commit comments

Comments
 (0)