80 lines
3.0 KiB
Smarty
80 lines
3.0 KiB
Smarty
|
||
{{/*
|
||
返回正确的镜像名称。
|
||
如果镜像 Tag 或 Digest 未定义,使用图表的 appVersion 作为版本标签。
|
||
调用:
|
||
{{ include "common.images.image" ( dict "imageRoot" .Values.path.to.the.image "global" .Values.global "chart" .Chart ) }}
|
||
*/}}
|
||
{{- define "common.images.image" -}}
|
||
{{- $registryName := default .imageRoot.registry ((.global).imageRegistry) -}}
|
||
{{- $repositoryName := .imageRoot.repository -}}
|
||
{{- $separator := ":" -}}
|
||
{{- $termination := .imageRoot.tag | toString -}}
|
||
|
||
{{- if not .imageRoot.tag }}
|
||
{{- if .chart }}
|
||
{{- $termination = .chart.AppVersion | toString -}}
|
||
{{- end -}}
|
||
{{- end -}}
|
||
{{- if .imageRoot.digest }}
|
||
{{- $separator = "@" -}}
|
||
{{- $termination = .imageRoot.digest | toString -}}
|
||
{{- end -}}
|
||
{{- if $registryName }}
|
||
{{- printf "%s/%s%s%s" $registryName $repositoryName $separator $termination -}}
|
||
{{- else -}}
|
||
{{- printf "%s%s%s" $repositoryName $separator $termination -}}
|
||
{{- end -}}
|
||
{{- end -}}
|
||
|
||
{{/*
|
||
返回正确的镜像库登陆信息。
|
||
调用:
|
||
{{ include "common.images.renderPullSecrets" ( dict "images" (list .Values.path.to.the.image1, .Values.path.to.the.image2) "context" $) }}
|
||
*/}}
|
||
{{- define "common.images.renderPullSecrets" -}}
|
||
{{- $pullSecrets := list }}
|
||
{{- $context := .context }}
|
||
|
||
{{- range (($context.Values.global).imagePullSecrets) -}}
|
||
{{- if kindIs "map" . -}}
|
||
{{- $pullSecrets = append $pullSecrets (include "common.tplvalues.render" (dict "value" .name "context" $context)) -}}
|
||
{{- else -}}
|
||
{{- $pullSecrets = append $pullSecrets (include "common.tplvalues.render" (dict "value" . "context" $context)) -}}
|
||
{{- end -}}
|
||
{{- end -}}
|
||
|
||
{{- range .images -}}
|
||
{{- range .pullSecrets -}}
|
||
{{- if kindIs "map" . -}}
|
||
{{- $pullSecrets = append $pullSecrets (include "common.tplvalues.render" (dict "value" .name "context" $context)) -}}
|
||
{{- else -}}
|
||
{{- $pullSecrets = append $pullSecrets (include "common.tplvalues.render" (dict "value" . "context" $context)) -}}
|
||
{{- end -}}
|
||
{{- end -}}
|
||
{{- end -}}
|
||
|
||
{{- if (not (empty $pullSecrets)) -}}
|
||
imagePullSecrets:
|
||
{{- range $pullSecrets | uniq }}
|
||
- name: {{ . }}
|
||
{{- end }}
|
||
{{- end }}
|
||
{{- end -}}
|
||
|
||
{{/*
|
||
返回正确的镜像版本信息(忽略 revision/prerelease 信息;若无效,使用图表的 appVersion 作为版本标签)。
|
||
调用:
|
||
{{ include "common.images.version" ( dict "imageRoot" .Values.path.to.the.image "chart" .Chart ) }}
|
||
*/}}
|
||
{{- define "common.images.version" -}}
|
||
{{- $imageTag := .imageRoot.tag | toString -}}
|
||
{{/* regexp from https://github.com/Masterminds/semver/blob/23f51de38a0866c5ef0bfc42b3f735c73107b700/version.go#L41-L44 */}}
|
||
{{- if regexMatch `^([0-9]+)(\.[0-9]+)?(\.[0-9]+)?(-([0-9A-Za-z\-]+(\.[0-9A-Za-z\-]+)*))?(\+([0-9A-Za-z\-]+(\.[0-9A-Za-z\-]+)*))?$` $imageTag -}}
|
||
{{- $version := semver $imageTag -}}
|
||
{{- printf "%d.%d.%d" $version.Major $version.Minor $version.Patch -}}
|
||
{{- else -}}
|
||
{{- print .chart.AppVersion -}}
|
||
{{- end -}}
|
||
{{- end -}}
|