Skip to content

Commit

Permalink
feature: imagePullSecrets from string array. (hashicorp#576)
Browse files Browse the repository at this point in the history
* allow configuring imagePullSecrets from an array of strings in
  addition to the already supported array of maps
  • Loading branch information
benashz authored and illegalnumbers committed Mar 16, 2022
1 parent 4b652a6 commit 69bc23a
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 12 deletions.
17 changes: 17 additions & 0 deletions templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}
5 changes: 1 addition & 4 deletions templates/csi-daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
5 changes: 1 addition & 4 deletions templates/injector-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
5 changes: 1 addition & 4 deletions templates/server-statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
27 changes: 27 additions & 0 deletions test/unit/csi-daemonset.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
Expand Down
26 changes: 26 additions & 0 deletions test/unit/server-statefulset.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
Expand Down
1 change: 1 addition & 0 deletions values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 69bc23a

Please sign in to comment.