<p>How can I add a default value to shutdownDelay to 50 seconds in my template</p>
<pre><code>        lifecycle:
        
           
            preStop:
{{ toYaml .Values.lifecycleHooks.preStop | indent 14 }}
            {{- else if gt (int .Values.shutdownDelay) 0 }}
            preStop:
              exec:
                command:
                  - sleep
                  - &quot;{{ int .Values.shutdownDelay }}&quot;
</code></pre>
<p>I tried few combinations like but nothing is working</p>
<p>Like if shutdownDelay isn't specified in values.yaml use 50 as default value and should appear like</p>

<p>Ordinarily I'd recommend the <a href="https://docs.helm.sh/docs/chart_template_guide/function_list/#default" rel="nofollow noreferrer"><code>default</code></a> function</p>
<pre class="lang-none prettyprint-override"><code>... (gt (.Values.shutdownDelay | default 50) 0) ...
</code></pre>
<p>The problem here is that <code>0</code> is an expected value, but it's logical &quot;false&quot; for purposes of <code>default</code>, so you won't be able to explicitly specify no delay.  You can't easily tell <code>0</code> and <code>nil</code> or &quot;absent&quot; apart with simple conditionals like this.</p>
<p>The &quot;big hammer&quot; here is the <a href="https://docs.helm.sh/docs/chart_template_guide/function_list/#ternary" rel="nofollow noreferrer"><code>ternary</code></a> function, which acts like the inline <code>condition ? true_expr : false_expr</code> conditional expression in C-like languages.  You can use this to select one value if the value is absent and another if it's present.</p>
<pre class="lang-none prettyprint-override"><code>{{- $delay := hasKey .Values &quot;shutdownDelay&quot; | ternary .Values.shutdownDelay 50 }}
{{- if gt $delay 0 }}
...
{{- end }}
</code></pre>
<p>If you decide to use a more complex expression inside <code>ternary</code>, remember that it is an ordinary function and is not &quot;short-circuiting&quot;; the condition and both values are always evaluated even though only one will actually be returned, so your expression will need to pass the various type constraints even if the value is absent.</p>
