helm-microservices-example
helm-microservices-example copied to clipboard
Merge strategy not working for booleans
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?
There's a related issue in the sprig library project.
A temporary solution (until they fix their bug) would be to specifically inject the 'falsy' value during the install/upgrade phase via flag.
Hi @CodeJjang, could you please clarify the above temporary solution?
PS: Your example was very useful to me.
Thanks.
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 @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.
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?
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.
common/template/_ingress.yamlshould 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
- 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
- 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 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"