From 571a6b88915ec35c2cf26d7d41e7c408d6c31fa4 Mon Sep 17 00:00:00 2001 From: shunki-fujita Date: Mon, 25 Nov 2024 05:39:31 +0000 Subject: [PATCH] issue-759: wip --- charts/moco/templates/_helpers.tpl | 11 +++++++++++ charts/moco/templates/generated/generated.yaml | 4 ++-- config/webhook/validate_preventdelete.yaml | 4 ++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/charts/moco/templates/_helpers.tpl b/charts/moco/templates/_helpers.tpl index e98b299b6..dde7eb384 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 based on Kubernetes minor version. +*/}} +{{- 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/webhook/validate_preventdelete.yaml b/config/webhook/validate_preventdelete.yaml index a5ab99aa4..769502706 100644 --- a/config/webhook/validate_preventdelete.yaml +++ b/config/webhook/validate_preventdelete.yaml @@ -1,4 +1,4 @@ -apiVersion: admissionregistration.k8s.io/v1beta1 +apiVersion: '{{ include "admissionregistration.apiVersion" . }}' kind: ValidatingAdmissionPolicy metadata: name: delete-validator @@ -17,7 +17,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: name: delete-validator