Helm 模板变量为 nil
Helm template variables are nil
我正在尝试使用模板从 values.yaml 中提取值,并将它们连接到 CSV 列表中。这是我的解决方案的示例。
values.yaml:
testValue1: "string1"
testValue2: "String2"
credentials:
- c1: "string3"
- c2: "string4"
_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 -}}
test.yaml
templatedValue: {{ template "test.template" }}
当我 运行 helm template --output-dir outputs chart
我得到:
test.yaml
templatedValue: %!s(<nil>),%!s(<nil>),
我设置为值的两个变量都是零,credentials
只是一个空字符串。如果我将 values.yaml 中的值直接放入 test.yaml
文件中,它就可以正常工作。所以我不确定为什么要从模板中获取这些 nil 值。 _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"}
{{ 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.
您必须在 {{template}}
中传递一些内容。如果您没有其他信息要传递什么,请尝试传递点 .
,当前管道。
{{ template "test.template" . }}
我正在尝试使用模板从 values.yaml 中提取值,并将它们连接到 CSV 列表中。这是我的解决方案的示例。
values.yaml:
testValue1: "string1"
testValue2: "String2"
credentials:
- c1: "string3"
- c2: "string4"
_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 -}}
test.yaml
templatedValue: {{ template "test.template" }}
当我 运行 helm template --output-dir outputs chart
我得到:
test.yaml
templatedValue: %!s(<nil>),%!s(<nil>),
我设置为值的两个变量都是零,credentials
只是一个空字符串。如果我将 values.yaml 中的值直接放入 test.yaml
文件中,它就可以正常工作。所以我不确定为什么要从模板中获取这些 nil 值。 _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"}
{{ 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.
您必须在 {{template}}
中传递一些内容。如果您没有其他信息要传递什么,请尝试传递点 .
,当前管道。
{{ template "test.template" . }}