Skip to content

Commit

Permalink
Updating the caBundle for the controller webhook
Browse files Browse the repository at this point in the history
Signed-off-by: ytimocin <[email protected]>
  • Loading branch information
ytimocin committed Jan 11, 2024
1 parent be2bc0c commit e9b47ff
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
22 changes: 22 additions & 0 deletions deploy/Chart/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,25 @@
{{- end -}}
{{- print $version }}
{{- end -}}

{{/*
Define a function to extract the caBundle for a given webhook name
from a *WebhookConfiguration object
*/}}
{{- define "controller.getWebhookCaBundle" -}}
{{- $existingWebhook := .existingWebhook -}}
{{- $webhookName := .webhookName -}}
{{- $fallbackCa := .fallbackCa -}}
{{- $caBundle := "" -}}
{{- if $fallbackCa -}}
{{- $caBundle = b64enc $fallbackCa.Cert -}}
{{- end -}}
{{- if $existingWebhook -}}
{{- range $webhook := $existingWebhook.webhooks -}}
{{- if eq $webhook.name $webhookName -}}
{{- $caBundle = $webhook.clientConfig.caBundle -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $caBundle -}}
{{- end -}}
3 changes: 2 additions & 1 deletion deploy/Chart/templates/controller/webhook.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
{{- $altName3 := printf "controller.%s.svc.cluster" .Release.Namespace }}
{{- $altName4 := printf "controller.%s.svc.cluster.local" .Release.Namespace }}
{{- $cert := genSignedCert $cn nil (list $altName1 $altName2 $altName3 $altName4) 3650 $ca }}
{{- $validatingWebhookCaBundle := include "controller.getWebhookCaBundle" (dict "existingWebhook" $existingWebhook "webhookName" "recipe-webhook.radapp.io" "fallbackCa" $ca) }}
apiVersion: v1
kind: Secret
metadata:
Expand All @@ -32,7 +33,7 @@ webhooks:
- admissionReviewVersions:
- v1
clientConfig:
caBundle: {{ b64enc $ca.Cert }}
caBundle: {{ $validatingWebhookCaBundle }}
service:
name: controller
namespace: {{ .Release.Namespace }}
Expand Down

0 comments on commit e9b47ff

Please sign in to comment.