{{/* 渲染一个可能包含模板的值,如果存在作用域,则可能会使用该作用域进行渲染。 调用: {{ include "common.tplvalues.render" ( dict "value" .Values.path.to.the.Value "context" $ ) }} {{ include "common.tplvalues.render" ( dict "value" .Values.path.to.the.Value "context" $ "scope" $app ) }} */}} {{- define "common.tplvalues.render" -}} {{- $value := typeIs "string" .value | ternary .value (.value | toYaml) }} {{- if contains "{{" (toJson .value) }} {{- if .scope }} {{- tpl (cat "{{- with $.RelativeScope -}}" $value "{{- end }}") (merge (dict "RelativeScope" .scope) .context) }} {{- else }} {{- tpl $value .context }} {{- end }} {{- else }} {{- $value }} {{- end }} {{- end -}} {{/* 渲染包含模板的一系列值。 调用: {{ include "common.tplvalues.merge" ( dict "values" (list .Values.path.to.the.Value1 .Values.path.to.the.Value2) "context" $ ) }} */}} {{- define "common.tplvalues.merge" -}} {{- $dst := dict -}} {{- range .values -}} {{- $dst = include "common.tplvalues.render" (dict "value" . "context" $.context "scope" $.scope) | fromYaml | merge $dst -}} {{- end -}} {{ $dst | toYaml }} {{- end -}} {{/* 渲染包含模板的一系列值,并进行值覆盖。 调用: {{ include "common.tplvalues.merge-overwrite" ( dict "values" (list .Values.path.to.the.Value1 .Values.path.to.the.Value2) "context" $ ) }} */}} {{- define "common.tplvalues.merge-overwrite" -}} {{- $dst := dict -}} {{- range .values -}} {{- $dst = include "common.tplvalues.render" (dict "value" . "context" $.context "scope" $.scope) | fromYaml | mergeOverwrite $dst -}} {{- end -}} {{ $dst | toYaml }} {{- end -}}