Home > Software design >  Nested arrays in Helm Yaml
Nested arrays in Helm Yaml

Time:11-05

Im using Helm.

I have a settings.json file containing the following configuration:

"CustomSetting": {
  "ArrayOfArrays": {{ .Values.customSetting.arrayOfArrays | toJson }}
}

And my values.yaml file contains the following values:

customSetting:
  arrayOfArrays: [
      [ "someValue1", "someValue2" ],
      [ "anotherValue3", "anotherValue4" ]
  ]

My problem is that I cannot run my chart with this setup since I get the following error:

unable to parse YAML: error converting YAML to JSON: yaml: line X: did not find expected key

How do I get this nested array in my settings.json file?

CodePudding user response:

I have had same issue, found following way that works for me:

  ArrayExample: |
    [
      [
        "asdf1",
        "asdf2"
      ],
      [
        "asdf3",
        "asdf4"
      ]
    ]

then the var is called via helm:"foo": {{ .Values.custom.ArrayExample | toPrettyJson }}

Best of luck

CodePudding user response:

Turn the settings into a multiline string by using | in yaml. This way your json config isn't processed by helm.

customSetting:  
  arrayOfArrays: |
    [
      [ "someValue1", "someValue2" ],
      [ "anotherValue3", "anotherValue4" ]
    ]

Now your variable is a string and can be used without any modifiers

"CustomSetting": {
  "ArrayOfArrays": {{ .Values.customSetting.arrayOfArrays }}
}
  • Related