【问题标题】:Expand helm template variables to lookup named-template/sub-template in _helpers.tpl展开 helm 模板变量以在 _helpers.tpl 中查找命名模板/子模板
【发布时间】:2022-11-15 02:23:39
【问题描述】:

尝试在 helm 模板中执行以下操作,但它没有扩展 $key 并给出错误找不到 template $key .

这甚至可能吗?

值.yaml

app:
  env:
  - AAAA

_helpers.tpl

{{- define "AAAA" }}
  {{- printf "BBBB" }}
{{- end }}

部署.yaml

...
container:
- name: xxxx
  env:
  {{- range $key := .Values.app.env }}
  - name: {{ $key }}
    value: {{ template "$key" . }} 
  {{ end }}

【问题讨论】:

    标签: kubernetes kubernetes-helm go-templates


    【解决方案1】:

    看起来像使用 include 而不是 template 的作品

    值.yaml

    app:
      env:
      - AAAA
    

    _helpers.tpl

    {{- define "AAAA" }}
      {{- printf "BBBB" }}
    {{- end }}
    

    部署.yaml

    ...
    container:
    - name: xxxx
      env:
      {{- range $key := .Values.app.env }}
      - name: {{ $key }}
        value: {{ include $key . }} 
      {{ end }}
    

    【讨论】:

      猜你喜欢
      • 2018-03-24
      • 2020-05-16
      • 2020-10-16
      • 2019-09-21
      • 1970-01-01
      • 2017-08-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多