40 lines
1.9 KiB
Smarty
40 lines
1.9 KiB
Smarty
{{/*
|
||
获取 K8s 标准标签。
|
||
调用:
|
||
{{ include "common.labels.standard" (dict "customLabels" .Values.commonLabels "context" $) -}}
|
||
*/}}
|
||
{{- define "common.labels.standard" -}}
|
||
{{- if and (hasKey . "customLabels") (hasKey . "context") -}}
|
||
{{- $default := dict "app.kubernetes.io/name" (include "common.names.name" .context) "helm.sh/chart" (include "common.names.chart" .context) "app.kubernetes.io/instance" .context.Release.Name "app.kubernetes.io/managed-by" .context.Release.Service -}}
|
||
{{- with .context.Chart.AppVersion -}}
|
||
{{- $_ := set $default "app.kubernetes.io/version" . -}}
|
||
{{- end -}}
|
||
{{ template "common.tplvalues.merge" (dict "values" (list .customLabels $default) "context" .context) }}
|
||
{{- else -}}
|
||
app.kubernetes.io/name: {{ include "common.names.name" . }}
|
||
helm.sh/chart: {{ include "common.names.chart" . }}
|
||
app.kubernetes.io/instance: {{ .Release.Name }}
|
||
app.kubernetes.io/managed-by: {{ .Release.Service }}
|
||
{{- with .Chart.AppVersion }}
|
||
app.kubernetes.io/version: {{ . | quote }}
|
||
{{- end -}}
|
||
{{- end -}}
|
||
{{- end -}}
|
||
|
||
{{/*
|
||
获取不可变标签,如:`deploy.spec.selector.matchLabels`、 `svc.spec.selector`
|
||
调用:
|
||
{{ include "common.labels.matchLabels" (dict "customLabels" .Values.podLabels "context" $) -}}
|
||
|
||
为了防止破坏部署、服务,规避将所有自定义标签遍历的添加到选择器。仅当用户在 metadata.labels
|
||
字段中覆盖了标准标签时,才进行覆盖。
|
||
*/}}
|
||
{{- define "common.labels.matchLabels" -}}
|
||
{{- if and (hasKey . "customLabels") (hasKey . "context") -}}
|
||
{{ merge (pick (include "common.tplvalues.render" (dict "value" .customLabels "context" .context) | fromYaml) "app.kubernetes.io/name" "app.kubernetes.io/instance") (dict "app.kubernetes.io/name" (include "common.names.name" .context) "app.kubernetes.io/instance" .context.Release.Name ) | toYaml }}
|
||
{{- else -}}
|
||
app.kubernetes.io/name: {{ include "common.names.name" . }}
|
||
app.kubernetes.io/instance: {{ .Release.Name }}
|
||
{{- end -}}
|
||
{{- end -}}
|