Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: imagePullSecrets from string array. #576

Merged
merged 2 commits into from
Jul 23, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: {{ . }}
benashz marked this conversation as resolved.
Show resolved Hide resolved
{{- 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