I've a helm chart with attribute 2darrayIPs. This attribute takes value from values.yaml file which inturn is given via helm installation command
helm-chart/templates/main.yaml
2darrayIPs: {{ .Values.2darrayIPs }}
helm-chart/values.yaml
2darrayIPs: [[]] -- empty array, this value is given via installation command
I'm passing 2d array via helm command while installing helm chart.
helm install ..... -f val.yaml
val.yaml
2darrayIPs:
- - 1.1.1.1
- 2.2.2.2
- - 3.3.3.3
- 4.4.4.4
I'm getting this error while installing helm chart:
Error: YAML parse error on templates/main.yaml: error converting YAML to JSON: yaml: did not find expected ',' or ']'
If I give one array as given below, the installation is successful but in my logs I get a single array with only one value instead of two:
[[1.1.1.1 2.2.2.2]]
val.yaml
2darrayIPs:
- - 1.1.1.1
- 2.2.2.2
Where am I going wrong?
CodePudding user response:
This is valid yaml. If possible, you should raise an issue on the repository of the yaml parser used here. In the meantime, Yaml is a superset of JSON, so you can use plain JSON 2D arrays:
2darrayIPs: [["1.1.1.1","2.2.2.2"]]
CodePudding user response:
If your templates are trying to write out something more complex than a simple string, the default {{ .Values.name }}
serialization is something Go-native that's not especially useful. Helm includes a toJson
template function, and also an undocumented toYaml
, which can write these out in more useful formats.
# as an array of arrays, in JSON syntax
2darrayIPs: {{ .Values.2darrayIPs | toJson }}
# as an array of arrays, in expanded YAML syntax
# (identical to the previous, but `helm template` output will be
# easier to read)
2darrayIPs: {{- .Values.2darrayIPs | toYaml | nindent 2 }}
# as a YAML-encoded string; for example in a ConfigMap
2darrayIPs: |-
{{ .Values.2darrayIPs | toYaml | indent 2 }}