Skip to content

Commit cefce71

Browse files
committed
feat: auto detect presence of cert-manager CRDs
1 parent 959ff26 commit cefce71

6 files changed

Lines changed: 33 additions & 13 deletions

File tree

charts/opentelemetry-operator/templates/_helpers.tpl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ a cert is loaded from an existing secret or is provided via `.Values`
119119
{{- $caCertEnc := "" }}
120120
{{- $certCrtEnc := "" }}
121121
{{- $certKeyEnc := "" }}
122-
{{- if .Values.admissionWebhooks.autoGenerateCert.enabled }}
122+
{{- if or (eq .Values.admissionWebhooks.certificateSource "helm-generated") (eq .Values.admissionWebhooks.certificateSource "prefer-cert-manager") }}
123123
{{- $prevSecret := (lookup "v1" "Secret" (include "opentelemetry-operator.namespace" .) (default (printf "%s-controller-manager-service-cert" (include "opentelemetry-operator.fullname" .)) .Values.admissionWebhooks.secretName )) }}
124124
{{- if and (not .Values.admissionWebhooks.autoGenerateCert.recreate) $prevSecret }}
125125
{{- $certCrtEnc = index $prevSecret "data" "tls.crt" }}
@@ -140,7 +140,10 @@ a cert is loaded from an existing secret or is provided via `.Values`
140140
{{- $certKeyEnc = b64enc $cert.Key }}
141141
{{- $caCertEnc = b64enc $ca.Cert }}
142142
{{- end }}
143-
{{- else }}
143+
{{- else if eq .Values.admissionWebhooks.certificateSource "self-signed" }}
144+
{{- if or (or (eq .Values.admissionWebhooks.certFile "") (eq .Values.admissionWebhooks.keyFile "")) (eq .Values.admissionWebhooks.caFile "")}}
145+
{{ fail "certFile, keyFile and caFile must be set when using self-signed as certificateSource" }}
146+
{{- end }}
144147
{{- $certCrtEnc = .Files.Get .Values.admissionWebhooks.certFile | b64enc }}
145148
{{- $certKeyEnc = .Files.Get .Values.admissionWebhooks.keyFile | b64enc }}
146149
{{- $caCertEnc = .Files.Get .Values.admissionWebhooks.caFile | b64enc }}

charts/opentelemetry-operator/templates/admission-webhooks/operator-webhook-with-cert-manager.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
{{- if and (.Values.admissionWebhooks.create) (.Values.admissionWebhooks.certManager.enabled) }}
1+
{{- if .Capabilities.APIVersions.Has "cert-manager.io/v1" -}}
2+
{{- if or (eq .Values.admissionWebhooks.certificateSource "cert-manager") (eq .Values.admissionWebhooks.certificateSource "prefer-cert-manager") }}
23
apiVersion: admissionregistration.k8s.io/v1
34
kind: MutatingWebhookConfiguration
45
metadata:
@@ -235,3 +236,8 @@ webhooks:
235236
sideEffects: None
236237
timeoutSeconds: {{ .Values.admissionWebhooks.timeoutSeconds }}
237238
{{- end }}
239+
{{- else -}}
240+
{{ if eq .Values.admissionWebhooks.certificateSource "cert-manager" }}
241+
{{ fail "certificateSource is set to cert-manager but cert manager APIs are not available" }}
242+
{{- end }}
243+
{{- end }}

charts/opentelemetry-operator/templates/admission-webhooks/operator-webhook.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{- if and (.Values.admissionWebhooks.create) (not .Values.admissionWebhooks.certManager.enabled) }}
1+
{{- if or (ne .Values.admissionWebhooks.certificateSource "cert-manager") (and (eq .Values.admissionWebhooks.certificateSource "prefer-cert-manager") (not (.Capabilities.APIVersions.Has "cert-manager.io/v1"))) }}
22
{{- $cert := fromYaml (include "opentelemetry-operator.WebhookCert" .) }}
33
{{- $caCertEnc := $cert.ca }}
44
{{- $certCrtEnc := $cert.crt }}

charts/opentelemetry-operator/templates/certmanager.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{- if and .Values.admissionWebhooks.create .Values.admissionWebhooks.certManager.enabled }}
1+
{{- if and .Values.admissionWebhooks.create .Values.admissionWebhooks.certManager.enabled (.Capabilities.APIVersions.Has "cert-manager.io/v1") }}
22
apiVersion: cert-manager.io/v1
33
kind: Certificate
44
metadata:

charts/opentelemetry-operator/values.schema.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,6 +1558,7 @@
15581558
"timeoutSeconds",
15591559
"namespaceSelector",
15601560
"objectSelector",
1561+
"certificateSource",
15611562
"certManager",
15621563
"autoGenerateCert",
15631564
"certFile",
@@ -1661,12 +1662,21 @@
16611662
{}
16621663
]
16631664
},
1665+
"certificateSource": {
1666+
"type": "string",
1667+
"default": {},
1668+
"title": "The certificateSource Schema",
1669+
"required": [],
1670+
"properties": {},
1671+
"examples": [
1672+
{}
1673+
]
1674+
},
16641675
"certManager": {
16651676
"type": "object",
16661677
"default": {},
16671678
"title": "The certManager Schema",
16681679
"required": [
1669-
"enabled",
16701680
"issuerRef",
16711681
"certificateAnnotations",
16721682
"issuerAnnotations"
@@ -1744,7 +1754,6 @@
17441754
"default": {},
17451755
"title": "The autoGenerateCert Schema",
17461756
"required": [
1747-
"enabled",
17481757
"recreate"
17491758
],
17501759
"additionalProperties": false,

charts/opentelemetry-operator/values.yaml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -291,11 +291,16 @@ admissionWebhooks:
291291
namespaceSelector: {}
292292
objectSelector: {}
293293

294+
## Choose the certificate approach to take
295+
## - prefer-cert-manager (default): Uses cert manager if available, falls back to generated certificates
296+
## - cert-manager: Use cert-manager to generate certificates
297+
## - helm-generated: Generate certificates with helm
298+
## - self-signed: Provide your own certificate
299+
certificateSource: 'prefer-cert-manager'
300+
294301
## https://github.com/open-telemetry/opentelemetry-helm-charts/blob/main/charts/opentelemetry-operator/README.md#tls-certificate-requirement
295302
## TLS Certificate Option 1: Use certManager to generate self-signed certificate.
296-
## certManager must be enabled. If enabled, always takes precedence over options 2 and 3.
297303
certManager:
298-
enabled: true
299304
## Provide the issuer kind and name to do the cert auth job.
300305
## By default, OpenTelemetry Operator will use self-signer issuer.
301306
issuerRef: {}
@@ -312,17 +317,14 @@ admissionWebhooks:
312317
renewBefore: ""
313318

314319
## TLS Certificate Option 2: Use Helm to automatically generate self-signed certificate.
315-
## certManager must be disabled and autoGenerateCert must be enabled.
316-
## If true and certManager.enabled is false, Helm will automatically create a self-signed cert and secret for you.
317320
autoGenerateCert:
318-
enabled: true
319321
# If set to true, new webhook key/certificate is generated on helm upgrade.
320322
recreate: true
321323
# Cert period time in days. The default is 365 days.
322324
certPeriodDays: 365
323325

324326
## TLS Certificate Option 3: Use your own self-signed certificate.
325-
## certManager and autoGenerateCert must be disabled and certFile, keyFile, and caFile must be set.
327+
## certFile, keyFile, and caFile must be set.
326328
## The chart reads the contents of the file paths with the helm .Files.Get function.
327329
## Refer to this doc https://helm.sh/docs/chart_template_guide/accessing_files/ to understand
328330
## limitations of file paths accessible to the chart.

0 commit comments

Comments
 (0)