jack
jack

Reputation: 833

Openshift: Configmap not picked up by the application

I have a springboot application deployed in openshift with application.properties having

greeting.constant = HelloWorld.SpringProp

I have also defined the fabric8/configmap.yml

apiVersion: v1
kind: ConfigMap
metadata:
  name: sampleappconfig
data:  
  greeting.constant: Hellowrold.Poc.ConfigMap.Test

and fabric8/deployment.yml

spec:
  template:
    spec:
      containers:
      - name: sampleappcontainer
        env:
        - name: greeting.constant
          valueFrom:
            configMapKeyRef:
              name: sampleappconfig
              key: greeting.constant
        envFrom:
        - configMapRef:
            name: sampleappconfig
        resources:
          requests:
            cpu: "0.2"
#           memory: 256Mi
          limits:
            cpu: "1.0"
#           memory: 256Mi

On deploying the application using fabric8, it creates the Configmap in the Openshift and I also see "greeting.constant" in the "Environment" tab of the Application in openshift webconsole.

The issue is I would expect the application to pick up the values given in the Configmap instead of Spring application.properties as Env variables takes precendence. But, running the application logs "HelloWorld.SpringProp" instead of "Hellowrold.Poc.ConfigMap.Test".

How do I make my application to refer the properties from Configmap?

Upvotes: 0

Views: 3133

Answers (1)

Graham Dumpleton
Graham Dumpleton

Reputation: 58563

ConfigMap changes are only reflected in the container automatically if mounting the ConfigMap as a file and the application can detect changes to the file and re-read it.

If the ConfigMap is used to populate environment variables, it is necessary to trigger a new deployment for the environment variables to be updated. There is no way to update live the values of environment variables that the application sees by changing the ConfigMap.

Upvotes: 1

Related Questions