sprig icon indicating copy to clipboard operation
sprig copied to clipboard

Add safeEmpty, safeDefault, and safeCoalesce functions which don't consider 0 or false to be empty

Open tculp opened this issue 5 years ago • 2 comments

As explained in #111, the current implementation of empty, and therefore default and coalesce, fails when attempting to use booleans or certain integers. However, there are many cases where an override value may be a legitimate 'false' or '0'.

For example, in helm charts, a paradigm such as follows is common:

values.yaml

global:
  doThing: true

doThingOverride: null

deployment.yaml

{{- if .Values.doThingOverride | default .Values.global.doThing }}

In this case, even if doThingOverride is set to false, the global.doThing will always be used.

Adding a new set of functions would allow this paradigm to work without unfortunate workarounds like {{- if eq (coalesce (.Values.enableIngressOverride | quote) (.Values.global.enableIngress | quote)) (true | quote) }} and maintain backwards-compatabiity

tculp avatar Jun 03 '20 18:06 tculp

Is this still open? Can I pick this?

govindbalaji-s avatar Oct 21 '23 04:10 govindbalaji-s

Is this still open? Can I pick this?

Sure, glad to see something done with this!

tculp avatar Oct 23 '23 17:10 tculp