Helm Notable Values: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "=Internal= * If/Else =Overview= Numeric zero evaluates as follows:")
 
 
(19 intermediate revisions by the same user not shown)
Line 1: Line 1:
=Internal=
=Internal=
* [[Helm_Template_If/Else#Numeric_Zero|If/Else]]
* [[Helm_Template_If/Else#Numeric_Zero|If/Else]]
* [[Helm_Template_Function_empty#Numeric_Zero|empty()]]
* [[Helm_Templates#Helm_Template_Function_Reference|Functions]]


=Overview=
=Numeric Zero=


Numeric zero evaluates as follows:
For a numeric zero declared as:
 
<syntaxhighlight lang='yaml'>
myValue: 0
</syntaxhighlight>
 
the following expressions evaluate to false:
 
Evaluates to false:
<syntaxhighlight lang='yaml'>
{{ if .Values.myValue }}
</syntaxhighlight>
 
the following expressions evaluate to true:
<syntaxhighlight lang='yaml'>
{{ if empty .Values.myValue }}
{{ if (eq 0 (int .Values.myValue)) }}
</syntaxhighlight>
 
<syntaxhighlight lang='yaml'>
{{ printf "%T" .Values.myValue }}
</syntaxhighlight>
returns <code>float64</code>
<syntaxhighlight lang='yaml'>
{{ typeOf .Values.myValue }}
</syntaxhighlight>
returns <code>float64</code>
 
==Distinguishing between Zero and Empty String==
<syntaxhighlight lang='yaml'>
{{- if kindIs "float64" .Values.myValue -}}
    {{- if .Values.myValue -}}
        {{- .Values.myValue -}}
    {{- else -}}
        0
    {{- end -}}
{{- end -}}
</syntaxhighlight>
 
=Boolean True=
=Boolean False=
 
=Empty Value (nil)=
 
<syntaxhighlight lang='yaml'>
myValue:
</syntaxhighlight>
 
<syntaxhighlight lang='yaml'>
{{ printf "%T" .Values.myValue }}
</syntaxhighlight>
returns <code><nil></code>
<syntaxhighlight lang='yaml'>
{{ typeOf .Values.myValue }}
</syntaxhighlight>
returns <code><nil></code>
 
=Empty String=
=Missing YAML Path Elements=
See: {{Internal|Helm_Template_If/Else#nil_pointer_evaluating_interface|if/else, nil pointer evaluating interface}}

Latest revision as of 02:04, 9 February 2022

Internal

Numeric Zero

For a numeric zero declared as:

myValue: 0

the following expressions evaluate to false:

Evaluates to false:

{{ if .Values.myValue }}

the following expressions evaluate to true:

{{ if empty .Values.myValue }}
{{ if (eq 0 (int .Values.myValue)) }}
{{ printf "%T" .Values.myValue }}

returns float64

{{ typeOf .Values.myValue }}

returns float64

Distinguishing between Zero and Empty String

{{- if kindIs "float64" .Values.myValue -}}
    {{- if .Values.myValue -}}
        {{- .Values.myValue -}}
    {{- else -}}
        0
    {{- end -}}
{{- end -}}

Boolean True

Boolean False

Empty Value (nil)

myValue:
{{ printf "%T" .Values.myValue }}

returns <nil>

{{ typeOf .Values.myValue }}

returns <nil>

Empty String

Missing YAML Path Elements

See:

if/else, nil pointer evaluating interface