-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. Use helm generated cert. (Default) 2. Use cert-manager. (Set certManager.enabled to true and make sure that cert-manager has been installed.) 3. Use Specified cert. (Fill in caBundlePEM, crtPEM, keyPEM.)
- Loading branch information
1 parent
36ad807
commit 4729341
Showing
6 changed files
with
177 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{{- define "webhook.caBundleCertPEM" -}} | ||
{{- if .Values.webhook.caBundlePEM -}} | ||
{{- trim .Values.webhook.caBundlePEM -}} | ||
{{- else -}} | ||
{{- /* Generate ca with CN "radondb-ca" and 5 years validity duration if not exists in the current scope.*/ -}} | ||
{{- $caKeypair := .selfSignedCAKeypair | default (genCA "radondb-ca" 1825) -}} | ||
{{- $_ := set . "selfSignedCAKeypair" $caKeypair -}} | ||
{{- $caKeypair.Cert -}} | ||
{{- end -}} | ||
{{- end -}} | ||
|
||
{{- define "webhook.certPEM" -}} | ||
{{- if .Values.webhook.crtPEM -}} | ||
{{- trim .Values.webhook.crtPEM -}} | ||
{{- else -}} | ||
{{- $webhookDomain := printf "%s.%s.svc" (include "webhook.name" .) .Release.Namespace -}} | ||
{{- $webhookDomainLocal := printf "%s.%s.svc.cluster.local" (include "webhook.name" .) .Release.Namespace -}} | ||
{{- $webhookCA := required "self-signed CA keypair is requried" .selfSignedCAKeypair -}} | ||
{{- /* genSignedCert <CN> <IP> <DNS> <Validity duration> <CA> */ -}} | ||
{{- $webhookServerTLSKeypair := .webhookTLSKeypair | default (genSignedCert "radondb-mysql" nil (list $webhookDomain $webhookDomainLocal) 1825 $webhookCA) -}} | ||
{{- $_ := set . "webhookTLSKeypair" $webhookServerTLSKeypair -}} | ||
{{- $webhookServerTLSKeypair.Cert -}} | ||
{{- end -}} | ||
{{- end -}} | ||
|
||
{{- define "webhook.keyPEM" -}} | ||
{{- if .Values.webhook.keyPEM -}} | ||
{{ trim .Values.webhook.keyPEM }} | ||
{{- else -}} | ||
{{- $webhookDomain := printf "%s.%s.svc" (include "webhook.name" .) .Release.Namespace -}} | ||
{{- $webhookDomainLocal := printf "%s.%s.svc.cluster.local" (include "webhook.name" .) .Release.Namespace -}} | ||
{{- $webhookCA := required "self-signed CA keypair is requried" .selfSignedCAKeypair -}} | ||
{{- /* genSignedCert <CN> <IP> <DNS> <Validity duration> <CA> */ -}} | ||
{{- $webhookServerTLSKeypair := .webhookTLSKeypair | default (genSignedCert "radondb-mysql" nil (list $webhookDomain $webhookDomainLocal) 1825 $webhookCA) -}} | ||
{{- $_ := set . "webhookTLSKeypair" $webhookServerTLSKeypair -}} | ||
{{- $webhookServerTLSKeypair.Key -}} | ||
{{- end -}} | ||
{{- end -}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{{- if .Values.webhook.certManager.enabled }} | ||
apiVersion: cert-manager.io/v1 | ||
kind: Issuer | ||
metadata: | ||
name: {{ template "issuer.name" . }} | ||
namespace: {{ .Release.Namespace }} | ||
spec: | ||
selfSigned: {} | ||
--- | ||
apiVersion: cert-manager.io/v1 | ||
kind: Certificate | ||
metadata: | ||
name: {{ template "certificate.name" . }} | ||
namespace: {{ .Release.Namespace }} | ||
spec: | ||
dnsNames: | ||
- {{ printf "%s.%s.svc" (include "webhook.name" .) .Release.Namespace }} | ||
- {{ printf "%s.%s.svc.cluster.local" (include "webhook.name" .) .Release.Namespace }} | ||
issuerRef: | ||
kind: Issuer | ||
name: {{ template "issuer.name" . }} | ||
secretName: "{{ template "webhook.name" . }}-certs" | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
charts/mysql-operator/templates/webhook_configuration.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
{{- $certManagerEnabled := .Values.webhook.certManager.enabled -}} | ||
{{- $caCertPEM := include "webhook.caBundleCertPEM" . -}} | ||
{{- $tlsCertPEM := include "webhook.certPEM" . -}} | ||
{{- $tlsKeyPEM := include "webhook.keyPEM" . -}} | ||
|
||
apiVersion: admissionregistration.k8s.io/v1 | ||
kind: ValidatingWebhookConfiguration | ||
metadata: | ||
creationTimestamp: null | ||
name: {{ template "validating-webhook-configuration.name" . }} | ||
{{- if $certManagerEnabled }} | ||
annotations: | ||
cert-manager.io/inject-ca-from: "{{ .Release.Namespace }}/{{ template "certificate.name" . }}" | ||
{{- end }} | ||
webhooks: | ||
- admissionReviewVersions: | ||
- v1 | ||
clientConfig: | ||
{{- if $certManagerEnabled }} | ||
caBundle: Cg== | ||
{{- else }} | ||
caBundle: {{ ternary (b64enc $caCertPEM) (b64enc (trim $tlsCertPEM)) (empty $tlsKeyPEM) }} | ||
{{- end }} | ||
service: | ||
name: {{ template "webhook.name" .}} | ||
namespace: {{ .Release.Namespace }} | ||
## path is generated by controller-runtime. | ||
## https://github.com/kubernetes-sigs/controller-runtime/blob/master/pkg/builder/webhook.go#L206 | ||
path: /validate-mysql-radondb-com-v1alpha1-mysqlcluster | ||
failurePolicy: Fail | ||
name: vmysqlcluster.kb.io | ||
rules: | ||
- apiGroups: | ||
- mysql.radondb.com | ||
apiVersions: | ||
- v1alpha1 | ||
operations: | ||
- CREATE | ||
- UPDATE | ||
resources: | ||
- mysqlclusters | ||
sideEffects: None | ||
--- | ||
|
||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: {{ template "webhook.name" .}} | ||
namespace: {{ .Release.Namespace }} | ||
spec: | ||
ports: | ||
- port: 443 | ||
protocol: TCP | ||
targetPort: 9443 | ||
selector: | ||
app: {{ template "mysql-operator.name" . }} | ||
|
||
--- | ||
{{- if not $certManagerEnabled }} | ||
kind: Secret | ||
apiVersion: v1 | ||
metadata: | ||
name: {{ template "webhook.name" . }}-certs | ||
namespace: {{ .Release.Namespace | quote }} | ||
labels: | ||
{{- include "mysql-operator.labels" . | nindent 4 }} | ||
app.kubernetes.io/component: webhook-secret | ||
type: Opaque | ||
data: | ||
ca.crt: {{ b64enc $caCertPEM }} | ||
tls.crt: {{ b64enc $tlsCertPEM }} | ||
tls.key: {{ b64enc $tlsKeyPEM }} | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters