From 8a090b1cb15bb6a3aced74b5bc30a46581e4d54d Mon Sep 17 00:00:00 2001 From: shunki-fujita Date: Mon, 25 Nov 2024 05:39:31 +0000 Subject: [PATCH 1/2] issue-759: Select the appropriate admissionregistration.apiVersion --- charts/moco/templates/_helpers.tpl | 11 +++++++++++ charts/moco/templates/generated/generated.yaml | 4 ++-- .../overlays/templates/kustomization.yaml | 11 +++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/charts/moco/templates/_helpers.tpl b/charts/moco/templates/_helpers.tpl index e98b299b6..6ea3c31bf 100644 --- a/charts/moco/templates/_helpers.tpl +++ b/charts/moco/templates/_helpers.tpl @@ -23,3 +23,14 @@ app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} {{- end }} app.kubernetes.io/managed-by: {{ .Release.Service }} {{- end }} + +{{/* +Return the appropriate apiVersion for admissionregistration. +*/}} +{{- define "admissionregistration.apiVersion" -}} +{{- if .Capabilities.APIVersions.Has "admissionregistration.k8s.io/v1" -}} +admissionregistration.k8s.io/v1 +{{- else -}} +admissionregistration.k8s.io/v1beta1 +{{- end }} +{{- end }} diff --git a/charts/moco/templates/generated/generated.yaml b/charts/moco/templates/generated/generated.yaml index ed07e253f..a51b0cbd2 100644 --- a/charts/moco/templates/generated/generated.yaml +++ b/charts/moco/templates/generated/generated.yaml @@ -372,7 +372,7 @@ spec: app.kubernetes.io/component: moco-controller app.kubernetes.io/name: '{{ include "moco.name" . }}' --- -apiVersion: admissionregistration.k8s.io/v1beta1 +apiVersion: '{{ include "admissionregistration.apiVersion" . }}' kind: ValidatingAdmissionPolicy metadata: labels: @@ -400,7 +400,7 @@ spec: !(oldObject.metadata.annotations["moco.cybozu.com/prevent-delete"] == "true") messageExpression: oldObject.metadata.name + ' is protected from deletion' --- -apiVersion: admissionregistration.k8s.io/v1beta1 +apiVersion: '{{ include "admissionregistration.apiVersion" . }}' kind: ValidatingAdmissionPolicyBinding metadata: labels: diff --git a/config/kustomize-to-helm/overlays/templates/kustomization.yaml b/config/kustomize-to-helm/overlays/templates/kustomization.yaml index 296f59960..2943a26b8 100644 --- a/config/kustomize-to-helm/overlays/templates/kustomization.yaml +++ b/config/kustomize-to-helm/overlays/templates/kustomization.yaml @@ -14,3 +14,14 @@ patchesStrategicMerge: transformers: - label-transformer.yaml + +patches: + - target: + group: admissionregistration.k8s.io + version: v1beta1 + kind: 'ValidatingAdmissionPolicy|ValidatingAdmissionPolicyBinding' + name: '.*' + patch: |- + - op: replace + path: "/apiVersion" + value: '{{ include "admissionregistration.apiVersion" . }}' From 71f6a54b85c45a5c9a915562440b51003b20eed2 Mon Sep 17 00:00:00 2001 From: shunki-fujita Date: Thu, 28 Nov 2024 06:43:29 +0000 Subject: [PATCH 2/2] issue-759: Changed version selection logic --- charts/moco/templates/_helpers.tpl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/charts/moco/templates/_helpers.tpl b/charts/moco/templates/_helpers.tpl index 6ea3c31bf..58dddc5af 100644 --- a/charts/moco/templates/_helpers.tpl +++ b/charts/moco/templates/_helpers.tpl @@ -28,9 +28,9 @@ app.kubernetes.io/managed-by: {{ .Release.Service }} Return the appropriate apiVersion for admissionregistration. */}} {{- define "admissionregistration.apiVersion" -}} -{{- if .Capabilities.APIVersions.Has "admissionregistration.k8s.io/v1" -}} -admissionregistration.k8s.io/v1 -{{- else -}} +{{- if (lt (int .Capabilities.KubeVersion.Minor) 30) -}} admissionregistration.k8s.io/v1beta1 +{{- else -}} +admissionregistration.k8s.io/v1 {{- end }} {{- end }}