question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ConfigMap with multiple yaml files and bootstrap.yaml one of them

See original GitHub issue

Describe the bug Hello, I’m trying to find out the way how to provide local development and also configure application for kubernetes. So for local development we are using something like this structure:

application/
├── config/
│   ├── application.yaml
│   ├── bootstrap.yaml
└── src/
    └── main/
        └── resources/ 
            ├── application.yaml
            └── bootstrap.yaml

so in config/ folder we have configuration for our local development in resources/ folder we have configuration with defaults which we don’t want to override

and in configmap I’d like to use something like this:

kind: ConfigMap
apiVersion: v1
metadata:
  name: {{ template "chart.fullname" . }}
data:
  application-kubernetes.yaml: |-
    ...
  bootstrap-kubernetes.yaml: |-
    ...

where I’d like to provide only the configs that I want to change for kubernetes.

However it looks like the bootstrap-kubernetes.yaml file didn’t took effect.

Is such patter available or what whould be the best option to provide also configuration for boostrap.yaml?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
wind57commented, Jun 13, 2022

I could take a stab at this one, but imo, we need to establish some (documented) rules here.

here is my proposal:

  • if there is a single key in the configmap and it ends in yaml/yml/properties - treat it as a “file”, we don’t care about its name. (this is the current behavior)
  • there are more than one entries in the configmap. Search for ones that have <SPRING_APPLICATION_NAME>.yaml/yml/properties (or application.yaml/yml/properties if SPRING_APPLICATION_NAME is missing) + all their profile based ones. For example, let’s suppose that

spring.application.name=my-name and active profiles = k8s; a config like:

kind: ConfigMap
apiVersion: v1
metadata:
  name: my-configmap
data:
  my-name.yaml: |-
    ...
  my-name-k8s.yaml: |-
    ..
my-name-dev.yaml: |-
   ..

someProp: someValue

This will result in three entries being read:

  • my-name.yaml treated as a file
  • my-name-k8s.yaml treated as a file
  • my-name-dev.yaml ignored since there is no such profile dev active
  • someProp: someValue plain property

If you agree, or have any other suggestions, do let me know; when I get a green light, I will implement this. thank you

1reaction
ryanjbaxtercommented, Oct 16, 2020

This is kind of an interesting problem. The problem is here

https://github.com/spring-cloud/spring-cloud-kubernetes/blob/master/spring-cloud-kubernetes-config/src/main/java/org/springframework/cloud/kubernetes/config/ConfigMapPropertySource.java#L161

When there are multiple files defined in a single configmap they need to be named application.yaml application.yml or application.properties. Since you have -kubernetes appended and you also have bootstrap-kubernetes we just make the file name the key and the content the value.

If you hit /actuator/env I am sure you will see that in the output.

I dont see a reason why the file name really matters in the case of using the API to read the ConfigMap and we wouldnt head down this path when reading from a path. I think the fix is really just to check that the file extension in the configmap is either yaml yml or properties.

The interesting problem has to do with profiles…I am not sure how to do that at the moment. You could have application-dev.yaml and application-production.yaml for example and right now that would all be combined into one property source.

The best workout I can offer at the moment would be to separate the files into different configmaps.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is it possible to configure spring.cloud.config to use multiple ...
yaml file. For example, one configMap may contain the config server URI, and the second configMap may contain overrideSystemProperties property.
Read more >
Best practices on Spring Cloud Kubernetes bootstrap ...
On purpose to externalise application's properties there are two most commons ways to implement this: k8s configmap; Spring Cloud Config ...
Read more >
2. ConfigMap PropertySource - Spring Cloud
properties|yaml files. The Spring Cloud Kubernetes Config project makes Kubernetes `ConfigMap`s available during application bootstrapping and triggers hot ...
Read more >
Using Kubernetes ConfigMaps to Manage Spring Application ...
In the Java and Spring ecosystems, there are multiple ways to pass the configuration data to the application, like providing command line ...
Read more >
Chapter 7. Integrate Spring Boot with Kubernetes
properties file (or bootstrap.yaml file), set the spring.application.name property to match the name of the ConfigMap. Enable the view ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found