Empty object don't overwrite in merge?

4/11/2020

I use the following deployment in common chart:

{{- define "common.deployment" -}}
{{- $common := dict "Values" .Values.common -}} 
{{- $noCommon := omit .Values "common" -}} 
{{- $overrides := dict "Values" $noCommon -}} 
{{- $noValues := omit . "Values" -}} 
{{- with merge $noValues $overrides $common -}}
                  ...
        {{- if .Values.resources }}
        resources:
{{ toYaml .Values.resources | indent 12 }}
                  ...
{{- end -}}

It supposed to merge values of the chart using it, and overwrite if the values exists. So far it works ok, except the case, when common/values.yaml has :

resources:
  requests:
    cpu: 20m
    memory: 120Mi

And the chart using it values.yaml has :

resources: {}

So specifying empty object, I expect to remove resources block, but looks like merge don't work that way and still prioritize common values. Why so and how to fix it?

I found that merge function using mergo/merge under the hood and it don't merge empty values. What workaround could be here?

-- ogbofjnr
kubernetes-helm
yaml

1 Answer

4/12/2020

Found a workaround on open github issue - use

resources: null

It works in my tests with helm 2.16.3

-- Alex Vorona
Source: StackOverflow