Helm _helpers.tpl?
Helm允许在Kubernetes的资源文件中使用Go templating.
名为_helpers.tpl
的文件通常用于定义具有以下语法的GO模板帮助器:
{{- define "yourFnName" -}}
{{- printf "%s-%s" .Values.name .Values.version | trunc 63 -}}
{{- end -}}
然后您可以在您的*.yaml
个资源文件中使用它,如下所示:
{{ template "yourFnName" . }}
The Question
如何使用我在其他帮助器定义中定义的帮助器?
例如,如果我有一个用于应用程序名称的帮助器,并且希望在确定入口主机名的帮助器的定义中使用该帮助器,该怎么办?
我try 过用其他几种不同的方式给助手打电话.鉴于这一基本辅助功能:
{{- 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 -}}
有没有可能做到这一点呢?如果是这样的话,是如何做到的呢?