Skip to content

Commit

Permalink
issue-759: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
shunki-fujita committed Nov 25, 2024
1 parent 389ae12 commit efc1c66
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 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 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 }}
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

patchesJson6902:
- target:
group: admissionregistration.k8s.io
version: v1beta1
kind: 'ValidatingAdmissionPolicy|ValidatingAdmissionPolicyBinding'
name: '.*'
patch: |-
- op: replace
path: "/apiVersion"
value: '{{ include "admissionregistration.apiVersion" . }}'
4 changes: 2 additions & 2 deletions config/webhook/validate_preventdelete.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: admissionregistration.k8s.io/v1beta1
apiVersion: '{{ include "admissionregistration.apiVersion" . }}'
kind: ValidatingAdmissionPolicy
metadata:
name: delete-validator
Expand All @@ -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
Expand Down

0 comments on commit efc1c66

Please sign in to comment.