【问题标题】:Can i refer entire section from values file in the helm template?我可以从 helm 模板中的值文件中引用整个部分吗?
【发布时间】:2020-02-13 20:18:40
【问题描述】:

我的 values.yaml 如下

account:
  - name: abc
    value: value1
  - name: xyz
    value: value2

我想在我的 helm 模板中引用它们。而不是将它们称为

accounts:
  - name: acount1
    value: "{{ .Values.account.abc }}"
  - name: account2
    value: "{{ .Values.account.xyz }}"

有没有办法可以将模板中的整个块引用为

accounts:
      {{ .Values.account }}

它会遍历 values.yaml 文件中传递的所有值?

【问题讨论】:

    标签: kubernetes-helm


    【解决方案1】:

    Helm 有一个文档最少的 toYaml 函数,可以将任意结构编写为 YAML。您还需要在输出结构中将其缩进到 accounts: 之下,而 sprig indentnindent 函数可以帮助解决这个问题。

    accounts: {{- .Values.account | toYaml | trim | nindent 2 }}
    

    【讨论】:

    • 谢谢大卫。我确实尝试过accounts: {{ toYaml .Values.account | nindent 2 }} 但得到did not find expected key 错误。
    【解决方案2】:

    能想办法。这行得通。

    accounts:
       {{- range $account := .Values.account }}
       - name: {{ $account.name }}
         value: {{ $account.value | quote }}
       {{- end }}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-12-01
      • 2022-06-10
      • 1970-01-01
      • 2020-05-09
      • 2017-08-07
      • 2021-09-02
      • 2021-11-01
      相关资源
      最近更新 更多