I would like to pass array as property in yaml (values file) in Helm. What I tried:
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|...
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
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.
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.
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
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.
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.
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 }}
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With