Skip to content

Commit 1214dab

Browse files
author
tazhate
committed
feat(helm): optional cert-manager integration for validating webhook
Chart shipped a ValidatingWebhookConfiguration but had no way to provide TLS certs to the operator, so the webhook silently no-op'd ("TLS certs not found, running without admission validation") and any kubectl create of a ChainInstance failed with "connection refused" against the webhook service. Adds webhook.certManager.enabled flag that provisions a self-signed Issuer + Certificate, mounts the resulting Secret, passes --webhook-cert-path/--webhook-cert-name/--webhook-cert-key to the manager, and annotates the webhook with cert-manager.io/inject-ca-from so the caBundle is populated automatically. Context: tried to apply a small bitcoin ChainInstance against a freshly installed v0.2.3 release and hit the webhook connection refused error, inspected the manager logs (cert-dir empty), checked cert-manager was present in the cluster (it was) and wired up the standard self-signed flow used by kubebuilder/operator-sdk projects. Verified end-to-end by upgrading the release with the new flag, confirming the cert/issuer went Ready and the bitcoin-test instance reconciled into a Running StatefulSet with PVC and started syncing block headers. Took ~30min.
1 parent 067e9dd commit 1214dab

4 files changed

Lines changed: 75 additions & 4 deletions

File tree

charts/chainplane/templates/deployment.yaml

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ spec:
6060
- --webhook-cert-path={{ .Values.webhook.certDir }}
6161
- --webhook-cert-name={{ .Values.webhook.certName }}
6262
- --webhook-cert-key={{ .Values.webhook.certKey }}
63+
{{- else if .Values.webhook.certManager.enabled }}
64+
- --webhook-cert-path=/tmp/k8s-webhook-server/serving-certs
65+
- --webhook-cert-name=tls.crt
66+
- --webhook-cert-key=tls.key
6367
{{- end }}
6468
{{- with .Values.extraArgs }}
6569
{{- toYaml . | nindent 12 }}
@@ -121,13 +125,27 @@ spec:
121125
{{- toYaml . | nindent 12 }}
122126
{{- end }}
123127
{{- end }}
124-
{{- if .Values.extraVolumeMounts }}
128+
{{- if or .Values.extraVolumeMounts .Values.webhook.certManager.enabled }}
125129
volumeMounts:
126-
{{- toYaml .Values.extraVolumeMounts | nindent 12 }}
130+
{{- if .Values.webhook.certManager.enabled }}
131+
- name: webhook-cert
132+
mountPath: /tmp/k8s-webhook-server/serving-certs
133+
readOnly: true
134+
{{- end }}
135+
{{- with .Values.extraVolumeMounts }}
136+
{{- toYaml . | nindent 12 }}
137+
{{- end }}
127138
{{- end }}
128-
{{- if .Values.extraVolumes }}
139+
{{- if or .Values.extraVolumes .Values.webhook.certManager.enabled }}
129140
volumes:
130-
{{- toYaml .Values.extraVolumes | nindent 8 }}
141+
{{- if .Values.webhook.certManager.enabled }}
142+
- name: webhook-cert
143+
secret:
144+
secretName: {{ include "chainplane.fullname" . }}-webhook-cert
145+
{{- end }}
146+
{{- with .Values.extraVolumes }}
147+
{{- toYaml . | nindent 8 }}
148+
{{- end }}
131149
{{- end }}
132150
{{- with .Values.nodeSelector }}
133151
nodeSelector:
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{{- if and .Values.webhook.enabled .Values.webhook.certManager.enabled }}
2+
{{- if not .Values.webhook.certManager.issuerRef }}
3+
apiVersion: cert-manager.io/v1
4+
kind: Issuer
5+
metadata:
6+
name: {{ include "chainplane.fullname" . }}-selfsigned
7+
namespace: {{ .Release.Namespace }}
8+
labels:
9+
{{- include "chainplane.labels" . | nindent 4 }}
10+
spec:
11+
selfSigned: {}
12+
---
13+
{{- end }}
14+
apiVersion: cert-manager.io/v1
15+
kind: Certificate
16+
metadata:
17+
name: {{ include "chainplane.fullname" . }}-webhook-cert
18+
namespace: {{ .Release.Namespace }}
19+
labels:
20+
{{- include "chainplane.labels" . | nindent 4 }}
21+
spec:
22+
secretName: {{ include "chainplane.fullname" . }}-webhook-cert
23+
dnsNames:
24+
- {{ include "chainplane.webhookServiceName" . }}.{{ .Release.Namespace }}.svc
25+
- {{ include "chainplane.webhookServiceName" . }}.{{ .Release.Namespace }}.svc.cluster.local
26+
{{- with .Values.webhook.certManager.duration }}
27+
duration: {{ . }}
28+
{{- end }}
29+
{{- with .Values.webhook.certManager.renewBefore }}
30+
renewBefore: {{ . }}
31+
{{- end }}
32+
issuerRef:
33+
{{- if .Values.webhook.certManager.issuerRef }}
34+
{{- toYaml .Values.webhook.certManager.issuerRef | nindent 4 }}
35+
{{- else }}
36+
name: {{ include "chainplane.fullname" . }}-selfsigned
37+
kind: Issuer
38+
group: cert-manager.io
39+
{{- end }}
40+
{{- end }}

charts/chainplane/templates/webhook-configuration.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ metadata:
55
name: {{ include "chainplane.fullname" . }}-validating
66
labels:
77
{{- include "chainplane.labels" . | nindent 4 }}
8+
{{- if .Values.webhook.certManager.enabled }}
9+
annotations:
10+
cert-manager.io/inject-ca-from: {{ .Release.Namespace }}/{{ include "chainplane.fullname" . }}-webhook-cert
11+
{{- end }}
812
webhooks:
913
- admissionReviewVersions:
1014
- v1

charts/chainplane/values.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,15 @@ webhook:
123123
certDir: ""
124124
certName: tls.crt
125125
certKey: tls.key
126+
# -- Provision a self-signed cert via cert-manager and inject CA bundle into
127+
# the ValidatingWebhookConfiguration. Requires cert-manager installed in the cluster.
128+
certManager:
129+
enabled: false
130+
# -- Issuer reference. By default a chart-managed self-signed Issuer is created.
131+
issuerRef: {}
132+
# -- Certificate duration / renewBefore (cert-manager defaults if empty)
133+
duration: ""
134+
renewBefore: ""
126135

127136
prometheus:
128137
# -- Base URL of the Prometheus server used for node health checks

0 commit comments

Comments
 (0)