Praveen Kumar
Praveen Kumar

Reputation: 11

Is it possible to do parameter substitution in k8s configMaps?

I have configMap that are loading properties files for my spring boot application. My configMap is mounted as a volume and my springboot app is reading from that volume.

my typical property files are:

application-dev1.yml has
integrations-queue-name=integration-dev1
search-queue-name=searchindex-dev1

application-dev2.yml
integrations-queue-name=integration-dev2
search-queue-name=searchindex-dev1

application-dev3.yml
integrations-queue-name=integration-dev3
search-queue-name=searchindex-dev1

My goal is to have 1 properties file

application-env.yml 
integrations-queue-name=integration-{env}
search-queue-name=searchindex-{env}

I want to do parameter substitution of env with the profile that is active for my service.

Is it possible to do parameter substitution in configMaps from my spring boot application running in the pod? I am lookin for something similar to maven-resource-plugin that can be done run time.

Upvotes: 1

Views: 1515

Answers (1)

mdaniel
mdaniel

Reputation: 33231

If it's just those two, then likely you will get more mileage out of using the SPRING_APPLICATION_JSON environment variable, which should supersede anything in the configmap:

containers:
- name: my-spring-app
  image: whatever
  env:
  - name: ENV_NAME
    value: dev2
  - name: SPRING_APPLICATION_JSON
    value: |
      {"integrations-queue-name": "integration-$(ENV_NAME)",
       "search-queue-name": "searchindex-$(ENV_NAME)"}

materializes as:

$ kubectl exec my-spring-pod -- printenv
ENV_NAME=dev2
SPRING_APPLICATION_JSON={"integrations-queue-name": "integration-dev2",
  "search-queue-name": "searchindex-dev2"}

Upvotes: 2

Related Questions