Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pass array in Helm values property

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.

like image 798
Bartek Avatar asked Sep 20 '19 12:09

Bartek


People also ask

How do I access the values passed into the helm chart?

Override values passed into the Helm chart through the Values.yaml file. The values.yaml file is available for each service as part of the Helm chart. It is a source of content for the Values built-in object offered by Helm templates. The Values built-in object provides access to the values passed into a chart.

What is the --set argument when installing Helm charts?

When installing Helm charts with the helm install command, the --set argument allows you to define values used in a chart’s templates. The --set argument is an alternative to defining the value in a values.yaml file. A simple usage of --set looks like this: $ helm install codecentric/keycloak --set keycloak.replicas=2

How to override the value of a YAML setting in helm?

You can use a --set flag in your Helm commands to override the value of a setting in the YAML file. Specify the name of the setting and its new value after the --set flag in the Helm command. The --set flag in the above command overrides the value for the <service>.deployment.strategy setting in the values.yaml file and sets it to blue-green.

How to set replicatcount in helm chart?

To learn more about Helm Chart you can visit - Getting Started with Helm Chart To begin with, I would like to take a very basic example with --set where we are going to set the replicatCount=2 Here is the command to install helloworld This command will set the replicaCount to 2.


2 Answers

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 }}
like image 144
Sandeep Jain Avatar answered Oct 08 '22 18:10

Sandeep Jain


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
like image 32
Marcin Król Avatar answered Oct 08 '22 17:10

Marcin Król