<p>Assuming I have this values.yaml under my helm chart -</p>
<pre class="lang-yaml prettyprint-override"><code>tasks:
  - name: test-production-dev
    env:
      - production
      - dev
  - name: test-dev
    env:
      - dev
  - name: test-all

environment_variables:
  STAGE: dev
</code></pre>
<p>I would like to run my cronjob based on these values -</p>
<ul>
<li>if <code>.env</code> doesn't exist - run any time.</li>
<li>if <code>.env</code> exists - run only if <code>environment_variables.STAGE</code> is in the <code>.env</code> list.</li>
</ul>
<p>This is what I've done so far ( with no luck ) -</p>
<pre class="lang-yaml prettyprint-override"><code>{{- range $.Values.tasks}}
# check if $value.env not exists OR contains stage
{{if or .env (hasKey .env &quot;$.Values.environment_variables.STAGE&quot;)  }}
apiVersion: batch/v1
kind: CronJob
...
{{- end}}
---
{{- end}}
</code></pre>

Amit Baranes
<p>values.yaml</p>
<pre class="lang-yaml prettyprint-override"><code>tasks:
  - name: test-production-dev
    env:
      - production
      - dev
  - name: test-dev
    env:
      - dev
  - name: test-all
  - name: test-production
    env:
      - production

environment_variables:
  STAGE: dev
</code></pre>
<p>template/xxx.yaml</p>
<p>plan a</p>
<pre class="lang-yaml prettyprint-override"><code>...
{{- range $.Values.tasks }}
{{- $flag := false }}
{{- if .env }}
{{- range .env }}
{{- if eq . $.Values.environment_variables.STAGE }}
{{- $flag = true }}
{{- end }}
{{- end }}
{{- else }}
{{- $flag = true }}
{{- end }}
{{- if $flag }}
apiVersion: batch/v1
kind: CronJob
meta:
  name: {{ .name }}
{{- end }}
{{- end }}
...
</code></pre>
<p>plan b</p>
<pre class="lang-yaml prettyprint-override"><code>...
{{- range $.Values.tasks }}
{{- if or (not .env) (has $.Values.environment_variables.STAGE .env) }}
apiVersion: batch/v1
kind: CronJob
meta:
  name: {{ .name }}
{{- end }}
{{- end }}
...
</code></pre>
<p>output</p>
<pre class="lang-yaml prettyprint-override"><code>...
apiVersion: batch/v1
kind: CronJob
meta:
  name: test-production-dev
apiVersion: batch/v1
kind: CronJob
meta:
  name: test-dev
apiVersion: batch/v1
kind: CronJob
meta:
  name: test-all
...
</code></pre>
