【发布时间】:2018-10-13 10:44:01
【问题描述】:
在 helm-template 中,我尝试按键检索地图的值。
我尝试使用 go-templates 中的 index,如下所示:
Access a map value using a variable key in a Go template
但是它对我不起作用(见后面的测试)。对替代解决方案有任何想法吗?
Chart.yaml:
apiVersion: v1
appVersion: "1.0"
description: A Helm chart for Kubernetes
name: foochart
version: 0.1.0
values.yaml:
label:
- name: foo
value: foo1
- name: bar
value: bar2
templates/test.txt
label: {{ .Values.label }}
helm template . 工作正常:
---
# Source: foochart/templates/test.txt
label: [map[value:foo1 name:foo] map[name:bar value:bar2]]
但是一旦尝试使用index:
templates/test.txt
label: {{ .Values.label }}
foolabel: {{ index .Values.label "foo" }}
它不起作用 - helm template .:
Error: render error in "foochart/templates/test.txt": template: foochart/templates/test.txt:2:13: executing "foochart/templates/test.txt" at <index .Values.label ...>: error calling index: cannot index slice/array with type string
【问题讨论】:
标签: kubernetes-helm