亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Helm 模板變量為零

Helm 模板變量為零

Go
慕神8447489 2022-05-10 16:16:02
我正在嘗試使用模板從 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" . }}


查看完整回答
反對 回復 2022-05-10
  • 1 回答
  • 0 關注
  • 148 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號