0

我想遍历文件中定义的 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 中,但不想故意这样做。

非常感谢任何帮助。

4

1 回答 1

0

只是为了将来参考,如果有人来看看。

有 fromYaml 函数,该函数未记录。我发现它很难,但这解决了这个问题。

{{- $lists := 包括 "mychart.list" 。| 来自Yaml}}

于 2020-03-13T01:08:45.053 回答