Templates Helm\u helpers.tpl:在其他模板定义中调用定义的模板 Helm_helpers.tpl?
Helm允许使用Kubernetes的资源文件 名为Templates Helm\u helpers.tpl:在其他模板定义中调用定义的模板 Helm_helpers.tpl?,templates,go,kubernetes,go-templates,kubernetes-helm,Templates,Go,Kubernetes,Go Templates,Kubernetes Helm,Helm允许使用Kubernetes的资源文件 名为\u helpers.tpl的文件通常用于使用以下语法定义Go模板帮助程序: {{- define "yourFnName" -}} {{- printf "%s-%s" .Values.name .Values.version | trunc 63 -}} {{- end -}} 然后可以在*.yaml资源文件中使用,如下所示: {{ template "yourFnName" . }} 问题 如何在其他帮助器定义中使用我定义的帮助器 例
\u 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 -}}
甚至可以这样做吗?如果是,如何使用?您应该使用
在您的特殊情况下,它是:
{{- define "host" -}}
{{ template "name" . }}.example.com
{{- end -}}
您可以使用(include…
语法。包括先前定义的模板foo
的示例:
{{- define "bar" -}}
{{- printf "%s-%s" (include "foo" .) .Release.Namespace | trunc 63 | trimSuffix "-" -}}
{{- end -}}
请同时查看使用
模板
和包含
的区别:
{{- define "bar" -}}
{{- printf "%s-%s" (include "foo" .) .Release.Namespace | trunc 63 | trimSuffix "-" -}}
{{- end -}}