我正在嘗試使用模板從 values.yaml 中提取值,將它們連接到 CSV 列表中。這是我的解決方案的一個例子。值.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 -}}測試.yamltemplatedValue: {{ template "test.template" }}當我跑步時,helm template --output-dir outputs chart我得到:測試.yamltemplatedValue: %!s(<nil>),%!s(<nil>),我設置為值的兩個變量都是 nil,credentials它們只是一個空字符串。如果我將 values.yaml 中的值直接放入test.yaml文件中,它可以正常工作。所以我不確定為什么要從模板中獲取這些 nil 值。從 values.yaml 文件中獲取值的還有其他模板_helpers.tpl,所以我不確定為什么我的模板不起作用。任何幫助是極大的贊賞。helm version: Client: &version.Version{SemVer:"v2.14.3", GitCommit:"0e7f3b6637f7af8fcfddb3d2941fcc7cbebb0085", GitTreeState:"clean"}Server: &version.Version{SemVer:"v2.14.3", GitCommit:"0e7f3b6637f7af8fcfddb3d2941fcc7cbebb0085", GitTreeState:"clean"}
1 回答

至尊寶的傳說
TA貢獻1789條經驗 獲得超10個贊
該{{ 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}}。如果您沒有其他信息要傳遞什么,請嘗試傳遞 dot .,即當前管道。
{{ template "test.template" . }}
- 1 回答
- 0 關注
- 148 瀏覽
添加回答
舉報
0/150
提交
取消