Helm 模板变量为零

rof*_*101 4 templates go go-templates kubernetes kubernetes-helm

我正在尝试使用模板从 value.yaml 中提取值,将它们连接到 CSV 列表中。这是我的解决方案的示例。

值.yaml:

testValue1: "string1"
testValue2: "String2"
credentials: 
- c1: "string3"
- c2: "string4"
Run Code Online (Sandbox Code Playgroud)

_helpers.tpl:

{{- define "test.template" -}}
{{- $value1 := .Values.testValue1 -}}
{{- $value2 := .Values.testValue2 -}}
{{- $credentials := "" -}}
{{- range $index, $cred := .Values.credentials -}}
{{- $credentials = $cred "," $credentials -}}
{{- end -}}
{{- printf "%s,%s,%s" $value1 $value2 $credentials -}}
{{- end -}}
Run Code Online (Sandbox Code Playgroud)

测试.yaml

templatedValue: {{ template "test.template" }}
Run Code Online (Sandbox Code Playgroud)

当我跑步时helm template --output-dir outputs chart我得到:

测试.yaml

templatedValue: %!s(<nil>),%!s(<nil>),
Run Code Online (Sandbox Code Playgroud)

我设置的两个变量值都是 nil,而且credentials只是一个空字符串。如果我将values.yaml中的值直接放入文件中,test.yaml它就可以正常工作。所以我不确定为什么我从模板中获取这些零值。其中还有其他模板_helpers.tpl从values.yaml 文件中获取值,所以我不确定为什么我的模板不起作用。任何帮助是极大的赞赏。

helm version: 
Client: &version.Version{SemVer:"v2.14.3", GitCommit:"0e7f3b6637f7af8fcfddb3d2941fcc7cbebb0085", GitTreeState:"clean"}
Server: &version.Version{SemVer:"v2.14.3", GitCommit:"0e7f3b6637f7af8fcfddb3d2941fcc7cbebb0085", GitTreeState:"clean"}
Run Code Online (Sandbox Code Playgroud)

icz*_*cza 5

{{ template "test.template" }}操作执行"test.template"模板但不向其传递任何参数。所以test.template管道里面会<nil>这样所以.Values是无效的。

引用自text/template

{{template "name"}}
  The template with the specified name is executed with nil data.

{{template "name" pipeline}}
  The template with the specified name is executed with dot set
  to the value of the pipeline.
Run Code Online (Sandbox Code Playgroud)

你必须传递一些东西进去{{template}}。如果您没有其他信息要传递什么,请尝试传递.当前管道的点。

{{ template "test.template" . }}
Run Code Online (Sandbox Code Playgroud)