From 9c2f2951c931ae9e606396c19a87f7984526ced6 Mon Sep 17 00:00:00 2001 From: Konstantin Semenov Date: Sun, 16 Feb 2020 18:06:34 +0000 Subject: [PATCH] Add chart-level pull secrets Signed-off-by: Konstantin Semenov --- pkg/chartutil/create.go | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/pkg/chartutil/create.go b/pkg/chartutil/create.go index ee0ebbdb8..1c17df3c1 100644 --- a/pkg/chartutil/create.go +++ b/pkg/chartutil/create.go @@ -405,7 +405,10 @@ Includes the 'image' and 'imagePullPolicy' keys. */}} {{- define ".registryImage" -}} image: {{ include ".imageReference" . }} -{{ include ".imagePullPolicy" . }} +{{- $pullPolicy := include ".imagePullPolicy" . -}} +{{- if $pullPolicy }} +{{ $pullPolicy }} +{{- end -}} {{- end -}} {{/* @@ -413,9 +416,7 @@ The most complete image reference, including the registry address, repository, tag and digest when available. */}} {{- define ".imageReference" -}} -{{- $registry := include ".imageRegistry" . -}} -{{- $namespace := include ".imageNamespace" . -}} -{{- printf "%s/%s/%s" $registry $namespace .image.name -}} +{{ include ".imagePath" . }} {{- if .image.tag -}} {{- printf ":%s" .image.tag -}} {{- end -}} @@ -424,6 +425,12 @@ registry address, repository, tag and digest when available. {{- end -}} {{- end -}} +{{- define ".imagePath" -}} +{{- $registry := include ".imageRegistry" . -}} +{{- $namespace := include ".imageNamespace" . -}} +{{- printf "%s/%s/%s" $registry $namespace .image.name -}} +{{- end -}} + {{- define ".imageRegistry" -}} {{- if or (and .image.useOriginalRegistry (empty .image.registry)) (and .values.useOriginalRegistry (empty .values.imageRegistry)) -}} {{- include ".originalImageRegistry" . -}} @@ -460,9 +467,9 @@ registry address, repository, tag and digest when available. Specify the image pull policy */}} {{- define ".imagePullPolicy" -}} -{{ $policy := coalesce .image.pullPolicy .values.global.imagePullPolicy }} +{{- $policy := coalesce .image.pullPolicy .values.imagePullPolicy .values.global.imagePullPolicy -}} {{- if $policy -}} -imagePullPolicy: "{{ printf "%s" $policy -}}" +imagePullPolicy: "{{- $policy -}}" {{- end -}} {{- end -}} @@ -471,12 +478,19 @@ Use the image pull secrets. All of the specified secrets will be used */}} {{- define ".imagePullSecrets" -}} {{- $secrets := .Values.global.imagePullSecrets -}} +{{- range $_, $chartSecret := .Values.imagePullSecrets -}} +{{- if $secrets -}} +{{- $secrets = append $secrets $chartSecret -}} +{{- else -}} +{{- $secrets = list $chartSecret -}} +{{- end -}} +{{- end -}} {{- range $_, $image := .Values.images -}} {{- range $_, $s := $image.pullSecrets -}} -{{- if not $secrets -}} -{{- $secrets = list $s -}} -{{- else -}} +{{- if $secrets -}} {{- $secrets = append $secrets $s -}} +{{- else -}} +{{- $secrets = list $s -}} {{- end -}} {{- end -}} {{- end -}}