Srinath Ganesh
Srinath Ganesh

Reputation: 2558

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

Upvotes: 2

Views: 3908

Answers (1)

Anna Slastnikova
Anna Slastnikova

Reputation: 1548

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.

Upvotes: 3

Related Questions