Skip to content

Commit

Permalink
Merge pull request #760 from cybozu-go/issue-759
Browse files Browse the repository at this point in the history
issue-759: Select the appropriate apiVersion
  • Loading branch information
shunki-fujita authored Nov 29, 2024
2 parents 389ae12 + 71f6a54 commit 13895b1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
11 changes: 11 additions & 0 deletions charts/moco/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
4 changes: 2 additions & 2 deletions charts/moco/templates/generated/generated.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
11 changes: 11 additions & 0 deletions config/kustomize-to-helm/overlays/templates/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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" . }}'

0 comments on commit 13895b1

Please sign in to comment.