我正在使用helmfile进行我的helm版本。
我有一个 yaml 文件项目.yaml
# projects.yaml
- yako
- pera
- okta
在values.yaml.gotmpl中,我想遍历projects.yaml的内容:
# values.yaml.gotmpl
{{ $projects := readFile 'projects.yaml' }}
{{ range $_, $project := $projects }}
# do something with $project . e.g: tpl (readFile 'proj-config.yaml') (dict $name $project)
{{ end}}
不幸的是,我得到了这个错误:
failed to render [values.yaml.gotmpl], because of template: stringTemplate:60:41:
executing "stringTemplate" at <$projects>: range can't iterate over projects:
- yako
- pera
- okta
我做了很多盲目的尝试来让它工作:
{{ range $_, $project := $projects | fromYaml }}
{{ range $_, $project := $projects | toYaml }}
{{ range $_, $project := $projects | list }}
不可能 😩
{{ $projects := readFile "./projects.yaml"}}
{{ range $_, $project := get "projects" $projects }}
{{ $project.attr1 }}
{{end}}