Search code examples
kuberneteskubernetes-helm

Helm Set Option (--set) | Update Nth key-value of an Array


My Config Map Template

apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Values.configmap.name }}
binaryData:
  {{- range .Values.configmap.binaryData }}
  {{ .key }}: {{ .value }}
  {{- end }}

My values.yaml that sets configmap looks like this

...
configmap:
    name: foo
    binaryData:
    - key: file1
      value: something_as_base64
    - key: file2
      value: something_as_base64
    - key: file3
      value: something_as_base64
...

What works: I can set ALL the array items

helm upgrade foo_name bar_dir \
--set configmap.binaryData[0].key=file1 --set configmap.binaryData[0].value=xyz \
--set configmap.binaryData[1].key=file2 --set configmap.binaryData[1].value=xyz \
--set configmap.binaryData[N].key=file2 --set configmap.binaryData[N].value=xyz

What does NOT works: Update value of file2 (array[N]), just one item

helm upgrade foo_name bar_dir \
--set configmap.binaryData[1].key=file2 --set configmap.binaryData[1].value=xyz \

Error

Error: UPGRADE FAILED: template: foo-helm/templates/configmap.yaml:x:y: executing "foo-helm/templates/configmap.yaml" at <.key>: nil pointer evaluating interface {}.key
  • Is there any syntax to specifically update Nth item of an array?
  • Also if my values.yaml has 5 items in array, and I set array[0], then [1-4] are getting truncated off

Solution

  • From this helm issue it seems it's not possible. The workaround is to use map instead or have seprate files with different arrays, please see the comment.