Spring Cloud Kubernetes fails setting ConfigMap values

9/4/2019

I am trying to support K8s ConfigMap API using Spring to handle my externalized configuration. I've been using a configuration service without any issues, so I don't believe it is a cloud-config implementation problem. I am using version 1.0.2.RELEASE of spring-cloud-starter-kubernetes-config.

My ConfigMap consists of two configurations: global (application.yml) and app-specific yaml (myapp.yml). Here is what that looks like:

apiVersion: v1
kind: ConfigMap
metadata:
  name: myapp-config
data:
  application.yml: |-
    kafka:
      hosts: kafka:9092

      topics:
        events: myapp-events
        normalized: myapp-normalized
        #...

    storage:
      uri: mongodb://mongo-0.mongo:27017,mongo-1.mongo:27017,mongo-2.mongo:27017
      database: do-stuff-db
      #...

    spring:
      cloud:
        config:
          override-system-properties: false

    #...

  myapp.yml: |-
    myapp:
      broadcast-address: 0.0.0.0:666

      #...

application.yml seems to work just fine. I can see the configuration values in my application but for whatever reason, myapp.yml does not get set. I can see Spring is successfully grabbing the entire result from the ConfigMap API but it does not do anything with myapp.yml.

Turning on debug logging exposed how Spring is interpreting the ConfigMap result. It is treating the entire myapp.yml section as one property and not its own property source. This explains why the application.yml is taking and not the myapp.yml. Here is what that log looks like (I have truncated the message):

2019-09-04 14:01:37.083 [main] INFO  config.PropertySourceBootstrapConfiguration - Located property source: CompositePropertySource {name='composite-configmap', propertySources=[ConfigMapPropertySource@92864491 {name='configmap.myapp-config.default', properties={kafka.hosts=kafka:9092, kafka.topics.events=myapp-events, kafka.topics.normalized=myapp-normalized, myapp.yml=myapp:
  bind-address: 0.0.0.0:666

  #...

    storage.uri: mongodb://mongo-0.mongo:27017,mongo-1.mongo:27017,mongo-2.mongo:27017, storage.database: do-stuff-db}}]}

Do I need to separate these configurations? The examples I've seen from Spring suggest you could consolidate your configuration into a single YAML ConfigMap file. I am stumped.

-- user0000001
configmap
java
kubernetes
spring
yaml

0 Answers