Skip to content

Commit 1b5d517

Browse files
committed
feat: auto detect presence of cert-manager CRDs
1 parent d1b6a69 commit 1b5d517

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
@@ -1479,6 +1479,7 @@
14791479
"timeoutSeconds",
14801480
"namespaceSelector",
14811481
"objectSelector",
1482+
"certificateSource",
14821483
"certManager",
14831484
"autoGenerateCert",
14841485
"certFile",
@@ -1582,12 +1583,21 @@
15821583
{}
15831584
]
15841585
},
1586+
"certificateSource": {
1587+
"type": "string",
1588+
"default": {},
1589+
"title": "The certificateSource Schema",
1590+
"required": [],
1591+
"properties": {},
1592+
"examples": [
1593+
{}
1594+
]
1595+
},
15851596
"certManager": {
15861597
"type": "object",
15871598
"default": {},
15881599
"title": "The certManager Schema",
15891600
"required": [
1590-
"enabled",
15911601
"issuerRef",
15921602
"certificateAnnotations",
15931603
"issuerAnnotations"
@@ -1665,7 +1675,6 @@
16651675
"default": {},
16661676
"title": "The autoGenerateCert Schema",
16671677
"required": [
1668-
"enabled",
16691678
"recreate"
16701679
],
16711680
"additionalProperties": false,

charts/opentelemetry-operator/values.yaml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -294,11 +294,16 @@ admissionWebhooks:
294294
namespaceSelector: {}
295295
objectSelector: {}
296296

297+
## Choose the certificate approach to take
298+
## - prefer-cert-manager (default): Uses cert manager if available, falls back to generated certificates
299+
## - cert-manager: Use cert-manager to generate certificates
300+
## - helm-generated: Generate certificates with helm
301+
## - self-signed: Provide your own certificate
302+
certificateSource: 'prefer-cert-manager'
303+
297304
## https://github.com/open-telemetry/opentelemetry-helm-charts/blob/main/charts/opentelemetry-operator/README.md#tls-certificate-requirement
298305
## TLS Certificate Option 1: Use certManager to generate self-signed certificate.
299-
## certManager must be enabled. If enabled, always takes precedence over options 2 and 3.
300306
certManager:
301-
enabled: true
302307
## Provide the issuer kind and name to do the cert auth job.
303308
## By default, OpenTelemetry Operator will use self-signer issuer.
304309
issuerRef: {}
@@ -315,17 +320,14 @@ admissionWebhooks:
315320
renewBefore: ""
316321

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

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

0 commit comments

Comments
 (0)