Masterminds / sprig

Useful template functions for Go templates.
http://masterminds.github.io/sprig/
MIT License
4.07k stars 423 forks source link

`deepCopy`, will not override an integer value with the value `0` #356

Open cunningr opened 1 year ago

cunningr commented 1 year ago

This issue is ported over from helm issues but i am not sure if the issue I am seeing would be in https://github.com/imdario/mergo?

Output of helm version:

version.BuildInfo{Version:"v3.8.2", GitCommit:"6e3701edea09e5d55a8ca2aae03a68917630e91b", GitTreeState:"clean", GoVersion:"go1.18.1"}

Output of kubectl version:

N/A

Cloud Provider/Platform (AKS, GKE, Minikube etc.):

CAPI/Openstack, vanilla k8s.

Issue:

When doing a deepCopy, it is not possible to override an integer value with the value 0. I am not sure if this is a bug or a know behaviour (but it is a little annoying :-)).

We can reproduce this in the helm playground

With values:

---
rolloutStrategy1:
  type: RollingUpdate
  rollingUpdate:
    maxUnavailable: 1
    maxSurge: 1

rolloutStrategy2:
  type: RollingUpdate
  rollingUpdate:
    maxUnavailable: 0
    maxSurge: 1

and template:

---
{{- $nodeGroup := deepCopy $.Values.rolloutStrategy1 | mustMerge $.Values.rolloutStrategy2 }}
{{ toYaml $nodeGroup }}

I would expect the values in rolloutStrategy2 to override the values in rolloutStrategy1, which they do, unless the value is a 0.