0

我正在使用进行 helm 发布。

我有一个 yaml 文件projects.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 }}

没门

4

1 回答 1

0
{{ $projects := readFile "./projects.yaml"}}
{{ range $_, $project := get "projects" $projects }}
    {{ $project.attr1 }}
{{end}}
于 2021-03-07T11:01:11.033 回答