Override value in list with helm override file
Asked Answered
L

2

8

I want to override values between prod and dev deployments.

The default values look like:

apps:
  myapp:
    replicaCount: 2
    containers:
      - name: foo
        env:
          MODE: "dev"

I can override this in command line with:

--set apps.myapp.containers[0].env.mode="prod"

However I want to keep all the overrides in a file and run helm upgrade passing in an override file as well. Adding the override in the file like:

apps:
  myapp:
    containers[0]:
      env:
        MODE: "prod"

does NOT work. How do I override values inside a list?

Lusitania answered 10/9, 2020 at 16:24 Comment(0)
L
3

It is weird to say the least.

This worked:

apps:
  myapp:
    containers[1]:
      env:
        MODE: "prod"

So the index for containers is 1 when overridden in a file, however 0 when done using command line:

--set apps.myapp.containers[0].env.mode="prod"
Lusitania answered 10/9, 2020 at 16:36 Comment(4)
When using helm better try to achieve this while using a template in deployment.yaml and define these overrides in values.yamlMisspend
Yes, these go in values.yaml. However we want override for values in values.yaml for different envs. We dont want to duplicate values.yaml for each env, so we have a base values.yaml + dev.yaml or prod.yaml with overrides that changes only relevant fields.Lusitania
@Lusitania With helm version v3.14.2 your values.yaml example doesn't work. For me it creates a new key containers[1] and does not overwrites an item in the original containers list. And your command line example overwrites the whole containers, isn't it? So in example name: foo is gone. You used Helm 2?Benge
I confirm what @Benge said, that this doesn't seem to work with helm v3.15 (in my case), neither the 0 nor the 1 index seems to work unfortunately.Paralyze
P
1

It appears that changing just a subpath in an array while leaving the rest of the array untouched doesn't work anymore in Helm v3.15 (possibly already for much longer) - in contrast to the answer by @Barath.

The only way that works at this time is to use --set, i.e.

--set apps.myapp.containers[0].env.mode="prod"

Workaround using dict instead of list

A workraound is to convert the array to a dict where you use increasing integers as keys. Then you can use the override values.yaml again.

Replace this values.yaml:

apps:
  myapp:
    replicaCount: 2
    containers:
      - name: foo
        env:
          MODE: "dev"

With this values.yaml:

apps:
  myapp:
    replicaCount: 2
    containers:
      1:
        name: foo
        env:
          MODE: "dev"

Then you can override with:

apps:
  myapp:
    containers:
      1:
        env:
          MODE: "dev"
Paralyze answered 29/5 at 11:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.