kots icon indicating copy to clipboard operation
kots copied to clipboard

HelmChart KOTS kind optionalValues overwrites values

Open aj-jester opened this issue 6 years ago • 7 comments

When multi-level nested optionalValues are used, the values: get overwritten by the values.yaml. It looks like KOTS is only merging the first level under values and not recursively for the nested/multi-level fields.

Below are details how I reproduced it….

I have the following in my HelmChart KOTS kind.

apiVersion: kots.io/v1beta1
kind: HelmChart
metadata:
  name: toocoolforskool
spec:
  chart:
    name: toocoolforskool
    chartVersion: 0.0.1
  values:
    favorite:
      drink:
        hot: rasam
    pizza:
      toppings:
        veggie: jalapeno

  optionalValues:
    - when: '{{repl ConfigOptionEquals "toocool_sub" "1" }}'
      values:
        toocool_sub:
          enabled: true
        favorite:
          drink:
            cold: badam milk
        pizza:
          toppings:
            meat: mutton

This is my config.yaml (removed cruft to focus on just this field)

        - name: toocool_sub
          title: Too Cool Sub chart
          help_text: Set up Too Cool Sub Chart
          type: bool
          default: "0"

This is my values.yaml

favorite:
  drink:
    hot: coffee
    cold: iced tea
pizza:
  toppings:
    veggie: peppers
    meat: pepperoni

toocool_sub:
  enabled: true
  dessert: ice cream

global:
  salad: caesar

and this is my templates/configmap.yaml

apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Release.Name }}-configmap
data:
  salad: {{ .Values.global.salad }}
  favorite_drink_cold: {{ .Values.favorite.drink.cold }}
  favorite_drink_hot: {{ .Values.favorite.drink.hot }}
  pizza_topping_veggie: {{ .Values.pizza.toppings.veggie }}
  pizza_topping_meat: {{ .Values.pizza.toppings.meat }}

This is what I actually see on my configmap

Data
====
favorite_drink_cold:
----
badam milk
favorite_drink_hot:
----
coffee
pizza_topping_meat:
----
mutton
pizza_topping_veggie:
----
peppers
salad:
----
caesar
Events:  <none>

I expected to see

favorite_drink_hot:
----
rasam
pizza_topping_veggie:
----
jalapeno

But I’m seeing the defaults from values.yaml and not the ones I set in values: HelmChart KOTS Kind.

favorite_drink_hot:
----
coffee
pizza_topping_veggie:
----
peppers

When I uncheck the toocool_sub checkbox, then I see

favorite_drink_hot:
----
rasam
pizza_topping_veggie:
----
jalapeno

toocoolforskool-0.0.1_helm_v2.tgz.zip

aj-jester avatar Jul 28 '20 00:07 aj-jester

Any idea on the priority of this ticket? We just ran into an issue where we need to configure two sets over overlapping optionalValues, which is impossible with this bug.

glentakahashi avatar Jan 12 '21 08:01 glentakahashi

We have a ticket for this: ch32325, but it's unscheduled thus far

laverya avatar Mar 26 '21 22:03 laverya

In order for the HelmChart KOTS Kind :values and :optionalValues to take effect instead of values.yaml. we need to have them defined in the :values or :optionalValues in the chart. For ex., I added “hot: rasam” and “veggie: jalapeno” in the optionalValues and Deployed the app. After deploy, the configmap looks as expected.

apiVersion: kots.io/v1beta1
kind: HelmChart
metadata:
  name: toocoolforskool
spec:
  chart:
    name: toocoolforskool
    chartVersion: 0.0.1
  values:
    favorite:
      drink:
        hot: rasam
    pizza:
      toppings:
        veggie: jalapeno

  optionalValues:
    - when: '{{repl ConfigOptionEquals "toocool_sub" "1" }}'
      values:
        toocool_sub:
          enabled: true
        favorite:
          drink:
            cold: badam milk
            hot: rasam
        pizza:
          toppings:
            meat: mutton
            veggie: jalapeno

jala-dx avatar Apr 07 '21 06:04 jala-dx

@jala-dx that's only a workaround and we're already doing that. This becomes impossible to manage if you have more than one set of optional values. e.g.

apiVersion: kots.io/v1beta1
kind: HelmChart
metadata:
  name: toocoolforskool
spec:
  chart:
    name: toocoolforskool
    chartVersion: 0.0.1
  values:
    colors:
      blue: false
      red: false
      green: false

  optionalValues:
    - when: '{{repl ConfigOptionEquals "enableBlue" "1" }}'
      values:
        colors:
          blue: true
          red: false
          green: false
    - when: '{{repl ConfigOptionEquals "enableRed" "1" }}'
      values:
        colors:
          blue: false
          red: true
          green: false
    - when: '{{repl ConfigOptionEquals "enableGreen" "1" }}'
      values:
        colors:
          blue: false
          red: false
          green: true

That works if I ever only want to do one of enableBlue/Red/Green, but in our case we support any permutation of red/blue/green. This is not how Helm itself works either, by default all values in helm are merged from the default values unless you set blue: null which explicitly says to remove it from the values.

glentakahashi avatar Apr 07 '21 16:04 glentakahashi

@AmberAlston

jala-dx avatar Apr 07 '21 16:04 jala-dx

@glentakahashi let me work on fixing this. Will update soon

jala-dx avatar Apr 07 '21 18:04 jala-dx

Closing this. This was resolved in KOTS 1.38.0 https://kots.io/release-notes/1.38.0/

AmberAlston avatar May 11 '21 16:05 AmberAlston