头盔_helpers.tpl?
Helm 允许使用进行模板化 https://golang.org/pkg/text/template/在 Kubernetes 的资源文件中。
一个名为_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 -}}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)