K
Q

pass array in Helm values property

September 20, 2019

I would like to pass array as property in yaml (values file) in Helm. What I tried:

  1. Attempt.

    elasticsearch:
      uri: "[\"127.0.0.1:9200\",\"127.0.0.2:9200\"]"

    Error:

ReadString: expects " or n, but found [, error found in #10 byte of ...|RCH_URL":["127.0.0.1|..., bigger context ...|{"apiVersion":"v1","data":{"ELASTIC_SEARCH_URL": ["127.0.0.1:9200","127.0.0.2:9200"],"LOGS_ENV_PREFI|...

  1. Attempt. According to official helm site how to pass array

    elasticsearch:
      --set uri={127.0.0.1:9200,127.0.0.2:9200}

    With error:

error converting YAML to JSON: yaml: line 15: mapping values are not allowed in this context

  1. Attempt.

     elasticsearch:
       uri: 
       - 127.0.0.1:9200
       - 127.0.0.2:9200

Failed with the same exception as 1.

EDIT: Actually in my case the helm values were not used in YAML file then, so I needed another format and finally solution was to pass uri as string with single quote:

 elasticsearch:
   uri: '["127.0.0.1:9200","127.0.0.2:9200"]'

Nevertheless @Marcin answer was correct.

-- Bartek
kubernetes
kubernetes-helm

2 Answers

February 12, 2021

Helm Rendering of values from values.yaml to config.yaml :

values.yaml:

sites:
  - dataprovider: abcd
  - dataprovider: xyzx

config.yaml:

sites:
  {{ toYaml .Values.sites | indent 10 }}
-- Sandeep Jain
Source: StackOverflow

September 20, 2019

You pass an array of values by using either flow syntax:

elasticsearch:
  uri: ["127.0.0.1:9200", "127.0.0.2:9200"]

or block syntax:

elasticsearch:
  uri: 
  - 127.0.0.1:9200
  - 127.0.0.2:9200

You can then access the values in Helm templates using

range
:

Uris:{{- range .Values.elasticsearch.uri }}
{{.}}{{- end }}

resolves to:

Uris:
127.0.0.1:9200
127.0.0.2:9200
-- Marcin Król
Source: StackOverflow