ogbofjnr
ogbofjnr

Reputation: 1988

Empty object don't overwrite in merge?

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?

Upvotes: 3

Views: 2995

Answers (1)

Alex Vorona
Alex Vorona

Reputation: 2265

Found a workaround on open github issue - use

resources: null

It works in my tests with helm 2.16.3

Upvotes: 3

Related Questions