Skip to content

Commit 3f7cfdd

Browse files
committed
fix(helm): webhook — template cert/secret names, gate on certManager.enabled, scope rules
1 parent 6da7c94 commit 3f7cfdd

7 files changed

Lines changed: 62 additions & 17 deletions

File tree

charts/imp/templates/operator/deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,5 @@ spec:
7474
volumes:
7575
- name: webhook-tls
7676
secret:
77-
secretName: imp-webhook-tls
77+
secretName: {{ include "imp.fullname" . }}-webhook-tls
7878
terminationGracePeriodSeconds: 10

charts/imp/templates/webhook/certificate.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
apiVersion: cert-manager.io/v1
33
kind: Certificate
44
metadata:
5-
name: imp-webhook-tls
5+
name: {{ include "imp.fullname" . }}-webhook-tls
66
namespace: {{ .Release.Namespace }}
77
labels:
88
{{- include "imp.labels" . | nindent 4 }}
99
spec:
10-
secretName: imp-webhook-tls
11-
duration: 8760h
12-
renewBefore: 720h
10+
secretName: {{ include "imp.fullname" . }}-webhook-tls
11+
duration: {{ .Values.webhook.certManager.duration }}
12+
renewBefore: {{ .Values.webhook.certManager.renewBefore }}
1313
dnsNames:
1414
- {{ include "imp.fullname" . }}-operator.{{ .Release.Namespace }}.svc
1515
- {{ include "imp.fullname" . }}-operator.{{ .Release.Namespace }}.svc.cluster.local
@@ -19,5 +19,6 @@ spec:
1919
{{- else }}
2020
name: {{ include "imp.fullname" . }}-selfsigned
2121
kind: Issuer
22+
group: cert-manager.io
2223
{{- end }}
2324
{{- end }}

charts/imp/templates/webhook/mutatingwebhook.yaml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
{{- if .Values.webhook.certManager.enabled }}
12
apiVersion: admissionregistration.k8s.io/v1
23
kind: MutatingWebhookConfiguration
34
metadata:
4-
name: {{ include "imp.fullname" . }}
5+
name: {{ include "imp.fullname" . }}-mutating-webhooks
56
labels:
67
{{- include "imp.labels" . | nindent 4 }}
78
annotations:
8-
cert-manager.io/inject-ca-from: {{ .Release.Namespace }}/imp-webhook-tls
9+
cert-manager.io/inject-ca-from: {{ .Release.Namespace }}/{{ include "imp.fullname" . }}-webhook-tls
910
webhooks:
1011
- name: mimpvm.kb.io
1112
admissionReviewVersions: ["v1"]
@@ -17,7 +18,11 @@ webhooks:
1718
rules:
1819
- apiGroups: ["imp.dev"]
1920
apiVersions: ["v1alpha1"]
20-
operations: [CREATE, UPDATE]
21+
operations:
22+
- CREATE
23+
- UPDATE
2124
resources: [impvms]
25+
scope: Namespaced
2226
failurePolicy: Fail
2327
sideEffects: None
28+
{{- end }}

charts/imp/templates/webhook/validatingwebhook.yaml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
{{- if .Values.webhook.certManager.enabled }}
12
apiVersion: admissionregistration.k8s.io/v1
23
kind: ValidatingWebhookConfiguration
34
metadata:
4-
name: {{ include "imp.fullname" . }}
5+
name: {{ include "imp.fullname" . }}-validating-webhooks
56
labels:
67
{{- include "imp.labels" . | nindent 4 }}
78
annotations:
8-
cert-manager.io/inject-ca-from: {{ .Release.Namespace }}/imp-webhook-tls
9+
cert-manager.io/inject-ca-from: {{ .Release.Namespace }}/{{ include "imp.fullname" . }}-webhook-tls
910
webhooks:
1011
- name: vimpvm.kb.io
1112
admissionReviewVersions: ["v1"]
@@ -17,8 +18,11 @@ webhooks:
1718
rules:
1819
- apiGroups: ["imp.dev"]
1920
apiVersions: ["v1alpha1"]
20-
operations: [CREATE, UPDATE]
21+
operations:
22+
- CREATE
23+
- UPDATE
2124
resources: [impvms]
25+
scope: Namespaced
2226
failurePolicy: Fail
2327
sideEffects: None
2428
- name: vimpvmclass.kb.io
@@ -31,8 +35,11 @@ webhooks:
3135
rules:
3236
- apiGroups: ["imp.dev"]
3337
apiVersions: ["v1alpha1"]
34-
operations: [CREATE, UPDATE]
38+
operations:
39+
- CREATE
40+
- UPDATE
3541
resources: [impvmclasses]
42+
scope: Cluster
3643
failurePolicy: Fail
3744
sideEffects: None
3845
- name: vimpvmtemplate.kb.io
@@ -45,7 +52,11 @@ webhooks:
4552
rules:
4653
- apiGroups: ["imp.dev"]
4754
apiVersions: ["v1alpha1"]
48-
operations: [CREATE, UPDATE]
55+
operations:
56+
- CREATE
57+
- UPDATE
4958
resources: [impvmtemplates]
59+
scope: Namespaced
5060
failurePolicy: Fail
5161
sideEffects: None
62+
{{- end }}

charts/imp/tests/operator-deployment_test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ tests:
3737
content:
3838
name: webhook-tls
3939
secret:
40-
secretName: imp-webhook-tls
40+
secretName: RELEASE-NAME-imp-webhook-tls
4141

4242
- it: renders Service with webhook and metrics ports
4343
template: templates/operator/service.yaml

charts/imp/tests/webhook_test.yaml

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ tests:
3030
of: Certificate
3131
- equal:
3232
path: spec.secretName
33-
value: imp-webhook-tls
33+
value: RELEASE-NAME-imp-webhook-tls
3434
- contains:
3535
path: spec.dnsNames
3636
content: RELEASE-NAME-imp-operator.NAMESPACE.svc
@@ -45,7 +45,7 @@ tests:
4545
of: MutatingWebhookConfiguration
4646
- equal:
4747
path: metadata.annotations["cert-manager.io/inject-ca-from"]
48-
value: NAMESPACE/imp-webhook-tls
48+
value: NAMESPACE/RELEASE-NAME-imp-webhook-tls
4949

5050
- it: ValidatingWebhookConfiguration has cainjector annotation
5151
template: templates/webhook/validatingwebhook.yaml
@@ -54,11 +54,37 @@ tests:
5454
of: ValidatingWebhookConfiguration
5555
- equal:
5656
path: metadata.annotations["cert-manager.io/inject-ca-from"]
57-
value: NAMESPACE/imp-webhook-tls
57+
value: NAMESPACE/RELEASE-NAME-imp-webhook-tls
5858

5959
- it: ValidatingWebhookConfiguration has three webhooks
6060
template: templates/webhook/validatingwebhook.yaml
6161
asserts:
6262
- lengthEqual:
6363
path: webhooks
6464
count: 3
65+
66+
- it: Certificate uses custom issuerRef when provided
67+
template: templates/webhook/certificate.yaml
68+
set:
69+
webhook.certManager.issuerRef.name: my-issuer
70+
webhook.certManager.issuerRef.kind: ClusterIssuer
71+
webhook.certManager.issuerRef.group: cert-manager.io
72+
asserts:
73+
- equal:
74+
path: spec.issuerRef.name
75+
value: my-issuer
76+
- equal:
77+
path: spec.issuerRef.kind
78+
value: ClusterIssuer
79+
80+
- it: MutatingWebhookConfiguration has one webhook with correct path
81+
template: templates/webhook/mutatingwebhook.yaml
82+
asserts:
83+
- isKind:
84+
of: MutatingWebhookConfiguration
85+
- lengthEqual:
86+
path: webhooks
87+
count: 1
88+
- equal:
89+
path: webhooks[0].clientConfig.service.path
90+
value: /mutate-imp-dev-v1alpha1-impvm

charts/imp/values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,5 @@ webhook:
4949
certManager:
5050
enabled: true
5151
issuerRef: {}
52+
duration: 8760h
53+
renewBefore: 720h

0 commit comments

Comments
 (0)