<p>I have the following variable JVM_ARGS</p>
<p><em>base-values.yaml</em></p>
<pre><code>app:
  env:
    PORT: 8080
    ...
    JVM_ARGS: &gt;
      -Dspring.profiles.active=$(SPRING_PROFILE),test
      -Dspring.config.additional-location=/shared
      -javaagent:/app/dd-java-agent.jar
</code></pre>
<p><em>service-x-values.yaml</em></p>
<pre><code>app:
  env:
    SPRING_PROFILE: my-local-profile
</code></pre>
<p>Values file are evaluated is the order:</p>
<ul>
<li>base-values.yaml</li>
<li>service-x-values.yaml</li>
</ul>
<p>I need JVM_ARGS to be evaluated against SPRING_PROFILE and so far I cannot make it work.
What is the best way to do something like that?</p>
<p>I'm new to helm and Kubernetes and have a feeling that I'm missing something basic.</p>
<p>What I tried:
defining JVM_ARGS surrounded with double quotes and without them.</p>
<p><strong>UPD:</strong>
The problem was that I had some custom Helm charts built by the other devs and I had little knowledge how those charts worked. I only worked with values files which were applied against the chart templates.</p>
<p>I wanted the property to be resolved by helm to</p>
<pre><code>-Dspring.profiles.active=my-local-profile,vault
</code></pre>
<p>At the end I decided to see how Spring Boot itself resolves properties and came up with the following:</p>
<pre><code>-Dspring.profiles.active=${SPRING_PROFILE},vault
</code></pre>
<p>Since spring.profiles.active is a regular property, env variables are allowed there and Spring will resolve the property at the runtime which worked for me.</p>

Vitaly Chura
<ol>
<li>I'm a bit confused: are you referring to an environment variable (as in the title of the question) or to a helm value?</li>
<li>Helm does not evaluate environment variables in the value files. <code>$(SPRING_PROFILE)</code> is treated as a literal string, it's not eveluated.</li>
<li>Actually Helm does not evaluate ANYTHING in the value files. They are source of data, not templates. Placeholders (actually <a href="https://golang.org/pkg/text/template/" rel="nofollow noreferrer">GO templates</a>) are evaluated only inside template files.</li>
<li>As a consequence of the point 3., you cannot reference one helm variable from another.</li>
</ol>
<p>If you really need to get Spring Profiles from a Linux environment variable, you could achieve it by setting Helm variable when calling helm install and the like (although using --set is considered a bad practice):</p>
<pre class="lang-sh prettyprint-override"><code>helm install --set app.env.spring_profile=$SPRING_PROFILE ...
</code></pre>
<p>Although even than, <code>app.env.spring_profile</code> couldn't be evaluated inside <code>base-values.yaml</code>. You would need to move it directly to your template file, e.g.:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
spec:
  ...
  template:
    ...
    spec:
      containers:
        - name: my-app
          ...
          env:
            SPRING_PROFILES_ACTIVE: {{- .Values.app.env.spring_profile }},test

</code></pre>
