【问题标题】:Variable value as yaml key in helm chart变量值作为 helm 图表中的 yaml 键
【发布时间】:2019-02-23 18:01:42
【问题描述】:

我想通过在 helm 命令行中设置变量来从 values.yaml 中选择配置部分。

values.yaml 的示例部分:

aaa:
  x1: "az1"
  x2: "az2"
bbb:
  x1: "bz1" 
  x2: "bz2"

configmap.yaml 的示例部分

data: 
  {{ .Values.outsideVal.x1 }}

预期的结果应该是这样的

   data:
     az1

测试 helm 输出

helm template --set outsideVal=aaa mychart

得到了这个错误

Error: render error in "./templates/configmap.yaml": template: ./templates/configmap.yaml:21:12: executing "./templates/configmap.yaml" at <.Values.outsideVal.x...>: can't evaluate field x1 in type interface {}

那么问题是如何得到预期的结果?

【问题讨论】:

    标签: kubernetes kubernetes-helm go-templates


    【解决方案1】:

    我怀疑您正在寻找 text/template index 函数,它可以通过变量键在映射中查找值。

    {{ (index .Values .Values.outsideVal).x1 }}
    

    【讨论】:

      猜你喜欢
      • 2021-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-20
      • 2022-08-13
      • 2020-02-25
      • 2019-03-26
      • 1970-01-01
      相关资源
      最近更新 更多