how to create a toml array usng helm template?

9/26/2019

I have a configmap which contains a toml file

something like

apiVersion: v1
kind: ConfigMap
data:
  burrow.toml: |
    [zookeeper]
    servers=[abc.2181, cde.2181]
    timeout=6
    root-path="/burrow"

When I am trying to create a helm chart to generate this configmap, I was putting something like:

apiVersion: v1
kind: ConfigMap
data:
  burrow.toml: |
    [zookeeper]
    servers={{ .Values.config.zookeeperServers }}
    timeout=6
    root-path="/burrow"

and in the values.yaml, I put:

  zookeeperServers: [ "abc.2181", "cde.2181"]

However, the rendered value became:

apiVersion: v1
kind: ConfigMap
data:
  burrow.toml: |
    [zookeeper]
    servers=[abc.2181 cde.2181]
    timeout=6
    root-path="/burrow"

The comma is missing. Is there a good way to template this correctly? Thanks!

-- ustcyue
kubernetes
kubernetes-helm

2 Answers

9/26/2019

Here is one solution, in the values.yaml put

zookeeperServers: |
[ "abc.2181", "cde.2181"]

solves the problem.

-- ustcyue
Source: StackOverflow

9/26/2019

Try this, servers=[{{ .Values.config.zookeeperServers | join "," }}]. Quoting could get weird if you put TOML metachars in those values, but for simple things it should work.

-- coderanger
Source: StackOverflow