Skip to content

Commit 1e39ffe

Browse files
committed
feat(charts): use flag to define image pull secrets
Updates the kubewarden-controller Helm chart to use the new controller CLI flag that allow users to define a list of secrets with the data to allowing container image download from private registries. Signed-off-by: José Guilherme Vanz <jguilhermevanz@suse.com> Assisted-by: Github Copilot
1 parent 8a3c84f commit 1e39ffe

4 files changed

Lines changed: 63 additions & 1 deletion

File tree

charts/kubewarden-controller/templates/_helpers.tpl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,24 @@ Create the name of the service account to use for kubewarden-controller
112112
{{- end -}}
113113
{{- end -}}
114114

115+
{{/*
116+
Build a comma-separated list of Secret names from .Values.imagePullSecrets,
117+
for use with the controller --image-pull-secrets flag. Handles both string
118+
entries and {name: ...} objects. Returns an empty string when no secrets
119+
are configured.
120+
*/}}
121+
{{- define "policyServerImagePullSecretNames" -}}
122+
{{- $names := list -}}
123+
{{- range .Values.imagePullSecrets -}}
124+
{{- if kindIs "string" . -}}
125+
{{- $names = append $names . -}}
126+
{{- else -}}
127+
{{- $names = append $names .name -}}
128+
{{- end -}}
129+
{{- end -}}
130+
{{- join "," $names -}}
131+
{{- end -}}
132+
115133
{{- define "audit-scanner.command" -}}
116134
{{- $parallelNamespaces := .Values.auditScanner.parallelNamespaces | int -}}
117135
{{- $parallelResources := .Values.auditScanner.parallelResources | int -}}

charts/kubewarden-controller/templates/deployment.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ spec:
5858
{{- if .Values.mTLS.enable }}
5959
- --client-ca-configmap-name={{ .Values.mTLS.configMapName }}
6060
{{- end }}
61+
{{- $imagePullSecretNames := include "policyServerImagePullSecretNames" . }}
62+
{{- if $imagePullSecretNames }}
63+
- --image-pull-secrets={{ $imagePullSecretNames }}
64+
{{- end }}
6165
{{- if or .Values.telemetry.metrics .Values.telemetry.tracing }}
6266
{{- if eq .Values.telemetry.mode "sidecar" }}
6367
- --enable-otel-sidecar
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
suite: image-pull-secrets flag
2+
templates:
3+
- deployment.yaml
4+
tests:
5+
- it: "should not include --image-pull-secrets when imagePullSecrets is empty (default)"
6+
asserts:
7+
- notContains:
8+
path: spec.template.spec.containers[0].args
9+
content: "--image-pull-secrets"
10+
any: true
11+
12+
- it: "should include --image-pull-secrets when imagePullSecrets contains a string entry"
13+
set:
14+
imagePullSecrets:
15+
- my-registry-secret
16+
asserts:
17+
- contains:
18+
path: spec.template.spec.containers[0].args
19+
content: "--image-pull-secrets=my-registry-secret"
20+
21+
- it: "should include --image-pull-secrets when imagePullSecrets contains an object entry"
22+
set:
23+
imagePullSecrets:
24+
- name: my-registry-secret
25+
asserts:
26+
- contains:
27+
path: spec.template.spec.containers[0].args
28+
content: "--image-pull-secrets=my-registry-secret"
29+
30+
- it: "should include multiple imagePullSecrets as a comma-separated list"
31+
set:
32+
imagePullSecrets:
33+
- secret-one
34+
- secret-two
35+
asserts:
36+
- contains:
37+
path: spec.template.spec.containers[0].args
38+
content: "--image-pull-secrets=secret-one,secret-two"

charts/kubewarden-controller/values.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ global:
109109
nameOverride: ""
110110
# fullnameOverride completely replaces the generated release name
111111
fullnameOverride: ""
112-
# Secrets to pull container images from private registries
112+
# Secrets to pull container images from private registries. When set, the
113+
# secret names are passed to the controller via --image-pull-secrets and added
114+
# to the spec.template.spec.imagePullSecrets of every policy-server Deployment.
113115
imagePullSecrets: []
114116
# -- Additional labels to add to all resources
115117
additionalLabels: {}

0 commit comments

Comments
 (0)