我想遍历文件中定义的Yaml列表,并在Job中使用它。例如我有
test.yaml
list:
- first element
- second element
In _helpers.tpl i can define
something like
{{- define "mychart.list" -}}
{{ .Files.Get "test.yaml"| toYaml }}
{{- end }}
And then in Job i want do something like
{{- $lists := include "mychart.list" . }}
{{- range $element := $lists.list}}
apiVersion: batch/v1
kind: Job
metadata:
and then use the $element.
But when i am trying to do the dry-run with --debug it complains about
at <$lists.list>: can't evaluate field list in type string.
Looks like whole value is coming as string rather than Yaml, does it needs explicit call to Yaml parser ? If yes, is there a way to do that ?
BTW i have also tried various combinations of
{{- $lists := include "mychart.list" . | toYaml }}
或内联加载文件,但没有帮助。
我可以将列表放在Values.yaml中,但不希望这样做。
非常感谢您的帮助。
如果有人来看看,请仅供参考。
有fromYaml函数,未记录。我发现很难,但这解决了问题。
{{-$ lists:=包括“ mychart.list”。 | fromYaml}}