1
votes

I have the following variable JVM_ARGS

base-values.yaml

app:
  env:
    PORT: 8080
    ...
    JVM_ARGS: >
      -Dspring.profiles.active=$(SPRING_PROFILE),test
      -Dspring.config.additional-location=/shared
      -javaagent:/app/dd-java-agent.jar

service-x-values.yaml

app:
  env:
    SPRING_PROFILE: my-local-profile

Values file are evaluated is the order:

  • base-values.yaml
  • service-x-values.yaml

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?

I'm new to helm and Kubernetes and have a feeling that I'm missing something basic.

What I tried: defining JVM_ARGS surrounded with double quotes and without them.

UPD: 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.

I wanted the property to be resolved by helm to

-Dspring.profiles.active=my-local-profile,vault

At the end I decided to see how Spring Boot itself resolves properties and came up with the following:

-Dspring.profiles.active=${SPRING_PROFILE},vault

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.

1

1 Answers

2
votes
  1. I'm a bit confused: are you referring to an environment variable (as in the title of the question) or to a helm value?
  2. Helm does not evaluate environment variables in the value files. $(SPRING_PROFILE) is treated as a literal string, it's not eveluated.
  3. Actually Helm does not evaluate ANYTHING in the value files. They are source of data, not templates. Placeholders (actually GO templates) are evaluated only inside template files.
  4. As a consequence of the point 3., you cannot reference one helm variable from another.

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):

helm install --set app.env.spring_profile=$SPRING_PROFILE ...

Although even than, app.env.spring_profile couldn't be evaluated inside base-values.yaml. You would need to move it directly to your template file, e.g.:

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