helm-microservices-example icon indicating copy to clipboard operation
helm-microservices-example copied to clipboard

Merge strategy not working for booleans

Open hnicke opened this issue 6 years ago • 8 comments

I really like your approach, thanks for sharing.

At first everything seemed to work. However, I've found a problem with merging booleans.

See this truth table:

case common specialized result correct?
1 false true true yes
2 true true true yes
3 false false false yes
4 true false true no

Case no. 4 is incorrect. It seems like the merge function uses or semantics. However, the correct behaviour for our use case would be: Specialized value always wins.

Does anyone know how we could make this work?

hnicke avatar Jan 27 '19 22:01 hnicke

There's a related issue in the sprig library project.

hnicke avatar Jan 27 '19 23:01 hnicke

A temporary solution (until they fix their bug) would be to specifically inject the 'falsy' value during the install/upgrade phase via flag.

CodeJjang avatar Jan 29 '19 22:01 CodeJjang

Hi @CodeJjang, could you please clarify the above temporary solution?

PS: Your example was very useful to me.

Thanks.

macedonia3 avatar May 17 '19 07:05 macedonia3

They've added the function mergeOverwrite to the sprig library - which does the deep merge as desired. So just swap merge with mergeOverwrite and you should be ready to go.

hnicke avatar May 17 '19 08:05 hnicke

@hnicke @macedonia3 Did it work for you? I've changed common ingress template to:

{{- define "common.ingress" -}}
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "common.fullname" . -}}
{{- $ingressPath := .Values.ingress.path -}}
{{- $common := dict "Values" .Values.common -}} 
{{- $noCommon := omit .Values "common" -}} 
{{- $overrides := dict "Values" $noCommon -}} 
{{- $noValues := omit . "Values" -}} 
{{- with mergeOverwrite $noValues $overrides $common -}}

and set values of common chart to

ingrress:
  enabled: true

and values of frontend chart to

ingress:
  enabled: false

and still getting the ingress configuration after templating frontend chart. I tough it may be related to wrong order of "if" and "merge" statements - i tought "if" should be placed after "merge", but it didn't help.

jdomag avatar Jun 29 '20 14:06 jdomag

Have the same issue. Tried to use both: https://github.com/Masterminds/sprig/blob/master/docs/dicts.md#mergeoverwrite-mustmergeoverwrite but didn't help. Also tried to reverse changes like that:

{{- with mergeOverwrite $common $overrides $noValues -}}

no success.

@jdomag don't you remember how did you fix that?

ghost avatar Apr 29 '21 14:04 ghost

Have the same issue. Tried to use both: https://github.com/Masterminds/sprig/blob/master/docs/dicts.md#mergeoverwrite-mustmergeoverwrite but didn't help. Also tried to reverse changes like that:

{{- with mergeOverwrite $common $overrides $noValues -}}

no success.

@jdomag don't you remember how did you fix that?

@AmetDevops This is how I did it. I will take ingress as an example.

  1. common/template/_ingress.yaml should start with below lines:
{{- define "common.ingress" -}}
{{- $fullName := include "common.fullname" . -}}
{{- $ingressPath := .Values.ingress.path -}}
{{- $common := dict "Values" .Values.common -}} 
{{- $noCommon := omit .Values "common" -}} 
{{- $overrides := dict "Values" $noCommon -}} 
{{- $noValues := omit . "Values" -}} 
{{- with mergeOverwrite $noValues $overrides $common -}}
  {{- if .Values.ingress.enabled -}}
apiVersion: extensions/v1beta1
kind: Ingress

  1. I wrapped all values in common/values.yaml in "common" block, so it looks like this:
common:
  replicaCount: 3
  
  image:
    repository: av10docker
    pullPolicy: IfNotPresent
  
  nameOverride: ""
  fullnameOverride: ""
  
  service:
    type: ClusterIP
    port: 80
  
  ingress:
    enabled: true
  1. I set the same "common" block in frontend-chart/values.yaml and only set values that I want to change e.g. disable ingress:
common:
  ingress:
    enabled: false

Hope this helps.

jdomag avatar Apr 30 '21 12:04 jdomag

@jdomag thank you.

I also found hacks :D, like inverting

# instead of
{{- if .Values.configmap.enabled }}
...
configmap:
  enabled: true
# use
{{- if not .Values.configmap.disabled }}
...
configmap
  disabled: false

and replacing boolean with string:

# instead of
{{- if .Values.configmap.enabled }}
...
configmap:
  enabled: true
# use
{{- if eq .Values.configmap.enabled "true" }}
...
configmap:
  enabled: "true"

ghost avatar Apr 30 '21 12:04 ghost