How can I specify the spring.profiles.active param with a value from an environment variable using fabric8 maven plugin?

codependent picture codependent · Sep 13, 2018 · Viewed 7.3k times · Source

I have a K8s config map that defines an ENVIRONMENT parameter.

That value is mounted as an environment variable on the deployment yaml using an excerpt in src/fabric8/deployment.yml:

spec:
  template:
    spec:
      containers:
      - env:
        - name: "ENVIRONMENT"
          valueFrom:
              configMapKeyRef:
                  name: global-configmap
                  key: ENVIRONMENT

I would like to use that ENVIRONMENT env variable to configure the spring.active.profiles property.

Is it supported in some way by fabric8 maven plugin? If not, can you suggest some workaround?

Answer

codependent picture codependent · Sep 14, 2018

Another way that also worked was explicitly defining it in the JAVA_OPTIONS parameters:

spec:
  template:
    spec:
      containers:
      - env:
        - name: JAVA_OPTIONS
          value: "-Dspring.profiles.active=${ENVIRONMENT}"
        - name: ENVIRONMENT
          valueFrom:
              configMapKeyRef:
                  name: global-configmap
                  key: ENVIRONMENT