diff --git a/charts/moco/templates/_helpers.tpl b/charts/moco/templates/_helpers.tpl index e98b299b6..58dddc5af 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 (lt (int .Capabilities.KubeVersion.Minor) 30) -}} +admissionregistration.k8s.io/v1beta1 +{{- else -}} +admissionregistration.k8s.io/v1 +{{- 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" . }}'