diff --git a/templates/_helpers.tpl b/templates/_helpers.tpl index 72b0e68..29364aa 100644 --- a/templates/_helpers.tpl +++ b/templates/_helpers.tpl @@ -623,3 +623,20 @@ Inject extra environment populated by secrets, if populated {{ "https" }} {{- end -}} {{- end -}} + +{{/* +imagePullSecrets generates pull secrets from either string or map values. +A map value must be indexable by the key 'name'. +*/}} +{{- define "imagePullSecrets" -}} +{{- with .Values.global.imagePullSecrets -}} +imagePullSecrets: +{{- range . -}} +{{- if typeIs "string" . }} + - name: {{ . }} +{{- else if index . "name" }} + - name: {{ .name }} +{{- end }} +{{- end -}} +{{- end -}} +{{- end -}} diff --git a/templates/csi-daemonset.yaml b/templates/csi-daemonset.yaml index 75bde9a..66fe055 100644 --- a/templates/csi-daemonset.yaml +++ b/templates/csi-daemonset.yaml @@ -77,8 +77,5 @@ spec: {{- if .Values.csi.volumes }} {{- toYaml .Values.csi.volumes | nindent 8}} {{- end }} - {{- if .Values.global.imagePullSecrets }} - imagePullSecrets: - {{- toYaml .Values.global.imagePullSecrets | nindent 8 }} - {{- end }} + {{- include "imagePullSecrets" . | nindent 6 }} {{- end }} diff --git a/templates/injector-deployment.yaml b/templates/injector-deployment.yaml index c063a87..261be1c 100644 --- a/templates/injector-deployment.yaml +++ b/templates/injector-deployment.yaml @@ -174,8 +174,5 @@ spec: secret: secretName: "{{ .Values.injector.certs.secretName }}" {{- end }} - {{- if .Values.global.imagePullSecrets }} - imagePullSecrets: - {{- toYaml .Values.global.imagePullSecrets | nindent 8 }} - {{- end }} + {{- include "imagePullSecrets" . | nindent 6 }} {{ end }} diff --git a/templates/server-statefulset.yaml b/templates/server-statefulset.yaml index 718c9a0..031b179 100644 --- a/templates/server-statefulset.yaml +++ b/templates/server-statefulset.yaml @@ -202,10 +202,7 @@ spec: {{- if .Values.server.extraContainers }} {{ toYaml .Values.server.extraContainers | nindent 8}} {{- end }} - {{- if .Values.global.imagePullSecrets }} - imagePullSecrets: - {{- toYaml .Values.global.imagePullSecrets | nindent 8 }} - {{- end }} + {{- include "imagePullSecrets" . | nindent 6 }} {{ template "vault.volumeclaims" . }} {{ end }} {{ end }} diff --git a/test/unit/csi-daemonset.bats b/test/unit/csi-daemonset.bats index d7152c6..c546d0a 100644 --- a/test/unit/csi-daemonset.bats +++ b/test/unit/csi-daemonset.bats @@ -72,6 +72,33 @@ load _helpers . | tee /dev/stderr | yq -r '.spec.template.spec.imagePullSecrets' | tee /dev/stderr) + local actual=$(echo $object | + yq -r '. | length' | tee /dev/stderr) + [ "${actual}" = "2" ] + + local actual=$(echo $object | + yq -r '.[0].name' | tee /dev/stderr) + [ "${actual}" = "foo" ] + + local actual=$(echo $object | + yq -r '.[1].name' | tee /dev/stderr) + [ "${actual}" = "bar" ] +} + +@test "csi/daemonset: Custom imagePullSecrets - string array" { + cd `chart_dir` + local object=$(helm template \ + --show-only templates/csi-daemonset.yaml \ + --set "csi.enabled=true" \ + --set 'global.imagePullSecrets[0]=foo' \ + --set 'global.imagePullSecrets[1]=bar' \ + . | tee /dev/stderr | + yq -r '.spec.template.spec.imagePullSecrets' | tee /dev/stderr) + + local actual=$(echo $object | + yq -r '. | length' | tee /dev/stderr) + [ "${actual}" = "2" ] + local actual=$(echo $object | yq -r '.[0].name' | tee /dev/stderr) [ "${actual}" = "foo" ] diff --git a/test/unit/server-statefulset.bats b/test/unit/server-statefulset.bats index 62f2529..b939051 100755 --- a/test/unit/server-statefulset.bats +++ b/test/unit/server-statefulset.bats @@ -146,6 +146,32 @@ load _helpers . | tee /dev/stderr | yq -r '.spec.template.spec.imagePullSecrets' | tee /dev/stderr) + local actual=$(echo $object | + yq -r '. | length' | tee /dev/stderr) + [ "${actual}" = "2" ] + + local actual=$(echo $object | + yq -r '.[0].name' | tee /dev/stderr) + [ "${actual}" = "foo" ] + + local actual=$(echo $object | + yq -r '.[1].name' | tee /dev/stderr) + [ "${actual}" = "bar" ] +} + +@test "server/standalone-StatefulSet: Custom imagePullSecrets - string array" { + cd `chart_dir` + local object=$(helm template \ + --show-only templates/server-statefulset.yaml \ + --set 'global.imagePullSecrets[0]=foo' \ + --set 'global.imagePullSecrets[1]=bar' \ + . | tee /dev/stderr | + yq -r '.spec.template.spec.imagePullSecrets' | tee /dev/stderr) + + local actual=$(echo $object | + yq -r '. | length' | tee /dev/stderr) + [ "${actual}" = "2" ] + local actual=$(echo $object | yq -r '.[0].name' | tee /dev/stderr) [ "${actual}" = "foo" ] diff --git a/values.yaml b/values.yaml index 7287696..908e332 100644 --- a/values.yaml +++ b/values.yaml @@ -5,6 +5,7 @@ global: # will enable or disable all the components within this chart by default. enabled: true # Image pull secret to use for registry authentication. + # Alternatively, the value may be specified as an array of strings. imagePullSecrets: [] # imagePullSecrets: # - name: image-pull-secret