Skip to content

Commit fc4f28a

Browse files
committed
manage external cert
Signed-off-by: kangclzjc <[email protected]>
1 parent e6baae7 commit fc4f28a

File tree

13 files changed

+206
-9
lines changed

13 files changed

+206
-9
lines changed

docs/api-reference/operator-api.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,24 @@ _Appears in:_
801801
| `metrics` _[Server](#server)_ | Metrics is the configuration for serving the metrics endpoint. | | |
802802

803803

804+
#### WebhookCertManagement
805+
806+
807+
808+
WebhookCertManagement defines how webhook certificates are managed.
809+
810+
811+
812+
_Appears in:_
813+
- [WebhookServer](#webhookserver)
814+
815+
| Field | Description | Default | Validation |
816+
| --- | --- | --- | --- |
817+
| `secretName` _string_ | SecretName is the name of the secret containing the webhook server certificate.<br />Default: grove-webhook-server-cert | | |
818+
| `certManagerEnabled` _boolean_ | CertManagerEnabled indicates whether to use cert-manager for certificate management.<br />When true, the operator waits for cert-manager to provide certificates.<br />When false, behavior depends on AutoProvision.<br />This requires cert-manager to be installed in the cluster when set to true.<br />Default: false | | |
819+
| `autoProvision` _boolean_ | AutoProvision indicates whether to use cert-controller for automatic certificate generation.<br />When true, cert-controller generates and manages certificates automatically.<br />When false, certificates are expected to be provided externally (e.g., via Helm chart or manual Secret creation).<br />This field is ignored when CertManagerEnabled is true.<br />Default: true | | |
820+
821+
804822
#### WebhookServer
805823

806824

@@ -817,5 +835,6 @@ _Appears in:_
817835
| `bindAddress` _string_ | BindAddress is the IP address on which to listen for the specified port. | | |
818836
| `port` _integer_ | Port is the port on which to serve requests. | | |
819837
| `serverCertDir` _string_ | ServerCertDir is the directory containing the server certificate and key. | | |
838+
| `certManagement` _[WebhookCertManagement](#webhookcertmanagement)_ | CertManagement defines the certificate management configuration. | | |
820839

821840

operator/api/config/v1alpha1/defaults.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,19 @@ func SetDefaults_ServerConfiguration(serverConfig *ServerConfiguration) {
7979
serverConfig.Webhooks.ServerCertDir = defaultWebhookServerTLSServerCertDir
8080
}
8181

82+
if serverConfig.Webhooks.CertManagement == nil {
83+
serverConfig.Webhooks.CertManagement = &WebhookCertManagement{}
84+
}
85+
if serverConfig.Webhooks.CertManagement.CertManagerEnabled == nil {
86+
serverConfig.Webhooks.CertManagement.CertManagerEnabled = ptr.To(false)
87+
}
88+
if serverConfig.Webhooks.CertManagement.AutoProvision == nil {
89+
serverConfig.Webhooks.CertManagement.AutoProvision = ptr.To(true)
90+
}
91+
if serverConfig.Webhooks.CertManagement.SecretName == "" {
92+
serverConfig.Webhooks.CertManagement.SecretName = "grove-webhook-server-cert"
93+
}
94+
8295
if serverConfig.HealthProbes == nil {
8396
serverConfig.HealthProbes = &Server{}
8497
}

operator/api/config/v1alpha1/types.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,31 @@ type WebhookServer struct {
135135
Server `json:",inline"`
136136
// ServerCertDir is the directory containing the server certificate and key.
137137
ServerCertDir string `json:"serverCertDir"`
138+
// CertManagement defines the certificate management configuration.
139+
// +optional
140+
CertManagement *WebhookCertManagement `json:"certManagement,omitempty"`
141+
}
142+
143+
// WebhookCertManagement defines how webhook certificates are managed.
144+
type WebhookCertManagement struct {
145+
// SecretName is the name of the secret containing the webhook server certificate.
146+
// Default: grove-webhook-server-cert
147+
// +optional
148+
SecretName string `json:"secretName,omitempty"`
149+
// CertManagerEnabled indicates whether to use cert-manager for certificate management.
150+
// When true, the operator waits for cert-manager to provide certificates.
151+
// When false, behavior depends on AutoProvision.
152+
// This requires cert-manager to be installed in the cluster when set to true.
153+
// Default: false
154+
// +optional
155+
CertManagerEnabled *bool `json:"certManagerEnabled,omitempty"`
156+
// AutoProvision indicates whether to use cert-controller for automatic certificate generation.
157+
// When true, cert-controller generates and manages certificates automatically.
158+
// When false, certificates are expected to be provided externally (e.g., via Helm chart or manual Secret creation).
159+
// This field is ignored when CertManagerEnabled is true.
160+
// Default: true
161+
// +optional
162+
AutoProvision *bool `json:"autoProvision,omitempty"`
138163
}
139164

140165
// Server contains information for HTTP(S) server configuration.

operator/api/config/v1alpha1/zz_generated.deepcopy.go

Lines changed: 32 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

operator/charts/templates/_helpers.tpl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ config.yaml: |
1616
server:
1717
webhooks:
1818
port: {{ .Values.config.server.webhooks.port }}
19+
serverCertDir: {{ .Values.config.server.webhooks.serverCertDir }}
20+
certManagement:
21+
secretName: {{ .Values.config.server.webhooks.certManagement.secretName }}
22+
certManagerEnabled: {{ .Values.config.server.webhooks.certManagement.certManagerEnabled }}
23+
autoProvision: {{ if or .Values.config.server.webhooks.certManagement.certManagerEnabled .Values.config.server.webhooks.certManagement.certFilesPath }}false{{ else }}true{{ end }}
1924
healthProbes:
2025
port: {{ .Values.config.server.healthProbes.port }}
2126
metrics:

operator/charts/templates/authorizer-webhook-config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,20 @@ kind: ValidatingWebhookConfiguration
55
metadata:
66
name: authorizer-webhook
77
namespace: {{ .Release.Namespace }}
8+
{{- if .Values.config.server.webhooks.certManagement.certManagerEnabled }}
9+
annotations:
10+
cert-manager.io/inject-ca-from: {{ .Release.Namespace }}/{{ .Values.config.server.webhooks.certManagement.secretName }}
11+
{{- end }}
812
labels:
913
{{- include "operator.authorizer.webhook.labels" . | nindent 4 }}
1014
webhooks:
1115
- admissionReviewVersions:
1216
- v1
1317
clientConfig:
18+
{{- if and .Values.config.server.webhooks.certManagement.certFilesPath (not .Values.config.server.webhooks.certManagement.certManagerEnabled) }}
19+
# CA Bundle from chart files
20+
caBundle: {{ .Files.Get (printf "%s/ca.crt" .Values.config.server.webhooks.certManagement.certFilesPath) | b64enc }}
21+
{{- end }}
1422
service:
1523
name: {{ required ".Values.service.name is required" .Values.service.name }}
1624
namespace: {{ .Release.Namespace }}

operator/charts/templates/deployment.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ spec:
6060
mountPath: /var/run/secrets/kubernetes.io/serviceaccount
6161
readOnly: true
6262
- name: grove-webhook-server-cert
63-
mountPath: /etc/grove-operator/webhook-certs
63+
mountPath: {{ .Values.config.server.webhooks.serverCertDir }}
6464
readOnly: true
6565
env:
6666
- name: GROVE_OPERATOR_SERVICE_ACCOUNT_NAME
@@ -91,6 +91,7 @@ spec:
9191
configMap:
9292
name: {{ include "operator.config.name" . }}
9393
- name: grove-webhook-server-cert
94+
# Always mount the Secret volume (cert-controller manages it in auto-provision mode)
9495
secret:
95-
secretName: grove-webhook-server-cert
96+
secretName: {{ .Values.config.server.webhooks.certManagement.secretName }}
9697
defaultMode: 420

operator/charts/templates/pcs-defaulting-webhook-config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,20 @@ kind: MutatingWebhookConfiguration
44
metadata:
55
name: podcliqueset-defaulting-webhook
66
namespace: {{ .Release.Namespace }}
7+
{{- if .Values.config.server.webhooks.certManagement.certManagerEnabled }}
8+
annotations:
9+
cert-manager.io/inject-ca-from: {{ .Release.Namespace }}/{{ .Values.config.server.webhooks.certManagement.secretName }}
10+
{{- end }}
711
labels:
812
{{- include "operator.pcs.defaulting.webhook.labels" . | nindent 4 }}
913
webhooks:
1014
- admissionReviewVersions:
1115
- v1
1216
clientConfig:
17+
{{- if and .Values.config.server.webhooks.certManagement.certFilesPath (not .Values.config.server.webhooks.certManagement.certManagerEnabled) }}
18+
# CA Bundle from chart files
19+
caBundle: {{ .Files.Get (printf "%s/ca.crt" .Values.config.server.webhooks.certManagement.certFilesPath) | b64enc }}
20+
{{- end }}
1321
service:
1422
name: {{ required ".Values.service.name is required" .Values.service.name }}
1523
namespace: {{ .Release.Namespace }}

operator/charts/templates/pcs-validating-webhook-config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,20 @@ kind: ValidatingWebhookConfiguration
44
metadata:
55
name: podcliqueset-validating-webhook
66
namespace: {{ .Release.Namespace }}
7+
{{- if .Values.config.server.webhooks.certManagement.certManagerEnabled }}
8+
annotations:
9+
cert-manager.io/inject-ca-from: {{ .Release.Namespace }}/{{ .Values.config.server.webhooks.certManagement.secretName }}
10+
{{- end }}
711
labels:
812
{{- include "operator.pcs.validating.webhook.labels" . | nindent 4 }}
913
webhooks:
1014
- admissionReviewVersions:
1115
- v1
1216
clientConfig:
17+
{{- if and .Values.config.server.webhooks.certManagement.certFilesPath (not .Values.config.server.webhooks.certManagement.certManagerEnabled) }}
18+
# CA Bundle from chart files
19+
caBundle: {{ .Files.Get (printf "%s/ca.crt" .Values.config.server.webhooks.certManagement.certFilesPath) | b64enc }}
20+
{{- end }}
1321
service:
1422
name: {{ required ".Values.service.name is required" .Values.service.name }}
1523
namespace: {{ .Release.Namespace }}
Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
1+
{{- if not .Values.config.server.webhooks.certManagement.certManagerEnabled }}
2+
---
13
apiVersion: v1
24
kind: Secret
35
metadata:
4-
name: grove-webhook-server-cert
6+
name: {{ .Values.config.server.webhooks.certManagement.secretName }}
57
namespace: {{ .Release.Namespace }}
68
labels:
79
{{- include "operator.server.secret.labels" . | nindent 4 }}
810
type: kubernetes.io/tls
911
data:
12+
{{- if .Values.config.server.webhooks.certManagement.certFilesPath }}
13+
# Certificate files provided: read from chart directory
14+
tls.crt: {{ .Files.Get (printf "%s/server.crt" .Values.config.server.webhooks.certManagement.certFilesPath) | b64enc }}
15+
tls.key: {{ .Files.Get (printf "%s/server.key" .Values.config.server.webhooks.certManagement.certFilesPath) | b64enc }}
16+
{{- if .Files.Get (printf "%s/ca.crt" .Values.config.server.webhooks.certManagement.certFilesPath) }}
17+
ca.crt: {{ .Files.Get (printf "%s/ca.crt" .Values.config.server.webhooks.certManagement.certFilesPath) | b64enc }}
18+
{{- end }}
19+
{{- else }}
20+
# Auto-provision mode: create empty Secret for operator to populate
1021
tls.crt: ""
1122
tls.key: ""
23+
{{- end }}
24+
{{- end }}

0 commit comments

Comments
 (0)