<p>yaml file and in that below values are defined including one specific value called &quot;environment&quot;</p>
<pre><code>image:
 repository: my_repo_url
 tag: my_tag
 pullPolicy: IfNotPresent

releaseName: cron_script
schedule: &quot;0 10 * * *&quot;
namespace: deploy_cron
rav_admin_password: asdf
environment: testing
testing_forwarder_ip: 10.2.71.21
prod_us_forwarder_ip: 10.2.71.15
</code></pre>
<p>Now in my helm chart based on this environment value i need to assign a value to new variable and for that I have written code like below, but always it is not entering into the if else block itself</p>
<pre><code>{{- $fwip := .Values.prod_us_forwarder_ip }}
  {{- if contains .Values.environment  &quot;testing&quot; }}
    {{- $fwip := .Values.testing_forwarder_ip }}
{{- end }}
---
apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: &quot;{{ .Values.releaseName }}&quot;
  namespace: &quot;{{ .Values.namespace }}&quot;
  labels:
  ....................................
  ....................................
  ....................................
  spec:
      restartPolicy: Never
      containers:
      - name: &quot;{{ .Values.releaseName }}&quot;
        image: &quot;{{ .Values.image.repository }}:{{ .Values.image.tag }}&quot;
        imagePullPolicy: IfNotPresent
        args:
          - python3
          - test.py
          - --data
          - 100
          - {{ $fwip }}
</code></pre>
<p>In the above code always i get $fwip value as 10.2.71.21 what ever environment value is either testing or production for both i am getting same value</p>
<p>And if i don't declare the variable $fwip before the if else statement then it says $fwip variable is not defined error, So i am not sure why exactly if else statement is not getting used at all, How to debug further ?</p>

<p>This is a syntax problem of variables and local variables.</p>
<p>The <code>fwip</code> in <code>if</code> should use <code>=</code> instead of <code>:=</code></p>
<pre class="lang-yaml prettyprint-override"><code>{{- $fwip := .Values.prod_us_forwarder_ip }}
{{- if contains .Values.environment  &quot;testing&quot; }}
  {{- $fwip = .Values.testing_forwarder_ip }}
{{- end }}
</code></pre>
<hr />
<p>I translated it into go code to make it easier for you to understand.</p>
<p>(In the go language, <code>:=</code> means definition and assignment, <code>=</code> means assignment)</p>
<pre class="lang-golang prettyprint-override"><code>// := 
env := &quot;testing&quot;
test := &quot;10.2.71.21&quot;
prod := &quot;10.2.71.15&quot;

fwip := prod
if strings.Contains(env,&quot;testing&quot;){
    fwip := test
    fmt.Println(fwip) // 10.2.71.21
}
fmt.Println(fwip) // 10.2.71.15
</code></pre>
<pre class="lang-golang prettyprint-override"><code>// =
env := &quot;testing&quot;
test := &quot;10.2.71.21&quot;
prod := &quot;10.2.71.15&quot;

fwip := prod
if strings.Contains(env,&quot;testing&quot;){
    fwip = test
    fmt.Println(fwip) // 10.2.71.21
}
fmt.Println(fwip) // 10.2.71.21
</code></pre>
