[英]Helm _helpers.tpl: Calling defined templates in other template definitions
Helm允许在Kubernetes的资源文件中使用Go模板 。
名为_helpers.tpl
的文件通常用于使用以下语法定义Go模板助手:
{{- define "yourFnName" -}}
{{- printf "%s-%s" .Values.name .Values.version | trunc 63 -}}
{{- end -}}
然后您可以在*.yaml
资源文件中使用它,如下所示:
{{ template "yourFnName" . }}
如何在其他帮助程序定义中使用我定义的帮助程序?
例如,如果我有一个应用程序名称的帮助程序,并希望在定义中使用它来确定入口主机名?
我尝试过几种不同的方式在其他定义中调用助手。 鉴于此基本辅助功能:
{{- define "host" -}}
{{- printf "%.example.com" <Somehow get result of "name" helper here> -}}
{{- end -}}
我尝试过以下方法:
{{- printf "%.example.com" {{ template "name" . }} -}}
{{- printf "%.example.com" {{- template "name" . -}} -}}
{{- printf "%.example.com" ( template "name" . ) -}}
{{- printf "%.example.com" template "name" . -}}
# Separator
{{- $name := {{ template "environment" . }} -}}
{{- printf "%.example.com" $name -}}
# Separator
{{- $name := template "environment" . -}}
{{- printf "%.example.com" $name -}}
# Separator
{{- $name := environment -}}
{{- printf "%.example.com" $name -}}
有可能做到这一点吗? 如果是这样,怎么样?
您可以使用(include ... )
语法。 包含先前定义的模板foo
示例:
{{- define "bar" -}}
{{- printf "%s-%s" (include "foo" .) .Release.Namespace | trunc 63 | trimSuffix "-" -}}
{{- end -}}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.