<p>In my final <code>deployment.yaml</code> created from helm template I would like to have liveness and readiness blocks only if in <code>values.yaml</code> the block <code>.Values.livenessReadinessProbe</code> <strong>doesn't exist</strong> or if <code>.Values.livenessReadinessProbe.enabled</code> <strong>is true</strong>.</p>
<p>I tried to do it so:</p>
<pre><code>  {{- if or (not .Values.livenessReadinessProbe) (.Values.livenessReadinessProbe.enabled) }}
  livenessProbe:
    httpGet:
      path: /actuator/health/liveness
      port: 8080
    initialDelaySeconds: 300
    failureThreshold: 5
    periodSeconds: 10
  readinessProbe:
    httpGet:
      path: /actuator/health/readiness
      port: 8080
    initialDelaySeconds: 200
    failureThreshold: 5
    periodSeconds: 10
  {{- end }}
</code></pre>
<p>But I'm getting <code>nil pointer evaluating interface {}.enabled</code>, if <code>livenessReadinessProbe</code> is absent in <code>values.yaml</code>, so it seems like the second OR condition is being executed, even though the first condition is <code>true</code> (i.e. <code>.Values.livenessReadinessProbe</code> is absent).</p>
<p>How can I achieve it?</p>
<p>My <code>values.yaml</code> with existing <code>livenessReadinessProbe</code> value:</p>
<pre><code>livenessReadinessProbe:
  enabled: true
</code></pre>
<p>Thank you in advance!</p>

Georgii Lvov
<p>In the <a href="https://pkg.go.dev/text/template" rel="nofollow noreferrer">Go <code>text/template</code> language</a>, <code>and</code> and <code>or</code> are <em>functions</em>, not built-in operators, so they don't have the usual &quot;short-circuiting&quot; semantics: first they evaluate all of their arguments, and then <code>or</code> returns the first that is true.</p>
<p>What I'd do here is use <code>default</code> to provide an empty dictionary as a default value.  That is still &quot;false&quot; so you can use it in conditionals, but now since it's a dictionary, you can do an index lookup in it.</p>
<pre class="lang-yaml prettyprint-override"><code>{{- $lrp := .Values.livenessReadinessProbe | default dict }}
{{- if or (not $lrp) $lrp.enabled }}
livenessProbe: { ... }
readinessProbe: { ... }
{{- end }}
</code></pre>
