<p>How to tell if a value, more specifically a a boolean typed value is empty in gotpl alias helm template?</p>
<p>How to tell if a simple value is empty?</p>

adam sranko
<p>You have multiple options, how to tell if a normal (not boolean) value is empty.</p>
<p>A very brute force and quite long way is to put an if statement around your node such as</p>
<pre><code>{{ if .Values.simpleText }}
isEmpty: false
{{ end }}
</code></pre>
<p>This will evaulate <code>isEmpty</code> as <code>false</code> only if there is any value inside <code>.Values.simpleText</code></p>
<p>A better way to do this is to use the inbuilt <code>empty</code> function:</p>
<pre><code>isEmpty2: {{ empty .Values.simpleText }}
</code></pre>
<blockquote>
<p>This does the same as the first example just shorter and arguably more
readable</p>
</blockquote>
<p><strong>The issue</strong> with theese methods is that if you have a node which is a bool theese methods wont work.</p>
<pre><code>#values.yaml
myBool: false
#-----------------------------------------
#template.yaml
isBoolEmpty: {{ empty .Values.myBool }}
#-----------------------------------------
#output
isBoolEmpty: true
</code></pre>
<blockquote>
<p>This will claim that <code>.Values.myBool</code> is empty even tho it clearly has
a value which is false.</p>
</blockquote>
<p>Now there is an option to check if a value is nil</p>
<pre><code>isNil: {{ eq nil .Values.nilValue }}
</code></pre>
<blockquote>
<p>This will result as true if the value is indeed nil ( <code>nilValue:</code> ) but as soon as you have a value inside <code>nilValue</code> you will get a type exception.</p>
</blockquote>
<p><strong>The solution</strong> that I found and seemed the easiest to understand and to use is:</p>
<pre><code>{{ if (quote .Values.myBool | empty)  }}
isActuallyEmpty: &quot;.Values.myBool is empty&quot;
{{ else }}
isActuallyEmpty: &quot;.Values.myBool has a false or true value&quot;
{{ end }}
</code></pre>
<p>I am sorry if this is very trivial but I know that I was struggleing with this question for some time.</p>
