pass array in Helm values property

9/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|...

  2. 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

  3. 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

1 Answer

9/20/2019

You pass an array of values by using either the old fashioned json way:

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

or the way introduced by yaml:

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