diff --git a/pkg/chartutil/create.go b/pkg/chartutil/create.go index dc309713f..ee0ebbdb8 100644 --- a/pkg/chartutil/create.go +++ b/pkg/chartutil/create.go @@ -93,20 +93,19 @@ const defaultValues = `# Default values for %s. # Default values for images used in the chart; all these values can be overridden in the # 'images' section for individual images global: - imageRegistry: docker.io # Allows for easy re-location of all the images to a private registry - imagePullPolicy: IfNotPresent + # imageRegistry: docker.io # Allows for easy re-location of all the images to a private registry + # imagePullPolicy: IfNotPresent imagePullSecrets: [] replicaCount: 1 - images: nginx: - name: bitnami/nginx + name: nginx + originalNamespace: bitnami tag: 1.16.1-debian-9-r105 digest: sha256:582aa10676417e79995989c0e06ffa8d48ced0cc2b9883669b0379ec9a7f45fb # Optional, to ensure image authenticity - metrics: - name: bitnami/nginx-exporter - tag: 0.4.2-debian-9-r129 + busybox: + name: busybox nameOverride: "" fullnameOverride: "" @@ -249,13 +248,13 @@ spec: labels: {{- include ".selectorLabels" . | nindent 8 }} spec: -{{ include ".imagePullSecrets" . | indent 6 }} + {{- include ".imagePullSecrets" . | indent 6 }} serviceAccountName: {{ include ".serviceAccountName" . }} securityContext: {{- toYaml .Values.podSecurityContext | nindent 8 }} containers: - name: {{ .Chart.Name }} -{{ include ".registryImage" (dict "image" .Values.images.nginx "values" .Values) | indent 10 }} + {{- include ".registryImage" (dict "image" .Values.images.nginx "values" .Values) | nindent 10 }} securityContext: {{- toYaml .Values.securityContext | nindent 12 }} ports: @@ -414,14 +413,49 @@ The most complete image reference, including the registry address, repository, tag and digest when available. */}} {{- define ".imageReference" -}} -{{- $registry := coalesce .image.registry .values.global.imageRegistry "docker.io" -}} -{{- $namespace := coalesce .image.namespace .values.imageNamespace .values.global.imageNamespace "library" -}} -{{- printf "%s/%s/%s:%s" $registry $namespace .image.name .image.tag -}} +{{- $registry := include ".imageRegistry" . -}} +{{- $namespace := include ".imageNamespace" . -}} +{{- printf "%s/%s/%s" $registry $namespace .image.name -}} +{{- if .image.tag -}} +{{- printf ":%s" .image.tag -}} +{{- end -}} {{- if .image.digest -}} {{- printf "@%s" .image.digest -}} {{- end -}} {{- end -}} +{{- define ".imageRegistry" -}} +{{- if or (and .image.useOriginalRegistry (empty .image.registry)) (and .values.useOriginalRegistry (empty .values.imageRegistry)) -}} +{{- include ".originalImageRegistry" . -}} +{{- else -}} +{{- include ".customImageRegistry" . -}} +{{- end -}} +{{- end -}} + +{{- define ".originalImageRegistry" -}} +{{- printf (coalesce .image.originalRegistry .values.originalImageRegistry "docker.io") -}} +{{- end -}} + +{{- define ".customImageRegistry" -}} +{{- printf (coalesce .image.registry .values.imageRegistry .values.global.imageRegistry (include ".originalImageRegistry" .)) -}} +{{- end -}} + +{{- define ".imageNamespace" -}} +{{- if or (and .image.useOriginalNamespace (empty .image.namespace)) (and .values.useOriginalNamespace (empty .values.imageNamespace)) -}} +{{- include ".originalImageNamespace" . -}} +{{- else -}} +{{- include ".customImageNamespace" . -}} +{{- end -}} +{{- end -}} + +{{- define ".originalImageNamespace" -}} +{{- printf (coalesce .image.originalNamespace .values.originalImageNamespace "library") -}} +{{- end -}} + +{{- define ".customImageNamespace" -}} +{{- printf (coalesce .image.namespace .values.imageNamespace .values.global.imageNamespace (include ".originalImageNamespace" .)) -}} +{{- end -}} + {{/* Specify the image pull policy */}} @@ -446,11 +480,11 @@ Use the image pull secrets. All of the specified secrets will be used {{- end -}} {{- end -}} {{- end -}} -{{- if $secrets -}} +{{- if $secrets }} imagePullSecrets: {{- range $secrets }} - name: {{ . }} -{{- end -}} +{{- end }} {{- end -}} {{- end -}}` @@ -465,7 +499,7 @@ metadata: spec: containers: - name: wget - image: busybox + {{- include ".registryImage" (dict "image" .Values.images.busybox "values" .Values) | nindent 6 }} command: ['wget'] args: ['{{ include ".fullname" . }}:{{ .Values.service.port }}'] restartPolicy: Never