Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spring.config.import reading incorrect data when profiles are involved #1874

Open
wind57 opened this issue Feb 11, 2025 · 4 comments
Open

spring.config.import reading incorrect data when profiles are involved #1874

wind57 opened this issue Feb 11, 2025 · 4 comments

Comments

@wind57
Copy link
Contributor

wind57 commented Feb 11, 2025

Sorry upfront for the bad title, I could not figure out of a better one.

It looks a bit related to this issue what I am going to describe next.

If I have an application.yaml:

spring:
  cloud:
    kubernetes:
      config:
        enable-api: true
        sources:
          - namespace: default
            name: sample-configmap

and application-dev.yaml:

spring:
  cloud:
    kubernetes:
      config:
        enable-api: true
        sources:
          - namespace: default
            name: sample-configmap-dev

and I do two things 1) use spring.cloud.import:kubernetes 2) make dev an active profile.

In this case, our code will bind sample-configmap as the name. This was un-expected for me, as I really thought it should be sample-configmap-dev. The logic happens in KubernetesConfigDataLocationResolver::resolveProfileSpecific and, although that method accepts a Profiles profiles I did not find any way to use that profile when binding (using Binder) happens.

Looking around a little and reading some of the threads on the matter (though I vaguely understand the idea), it seems that this is normal? And there is not much we can do, but suggest to users in such cases to use the bootstrap?

Thank you.

@ryanjbaxter
Copy link
Contributor

I did not find any way to use that profile when binding (using Binder) happens.

Can you elaborate on what you mean by this? I am not sure I understand what you mean by using the profile when binding happens.

@wind57
Copy link
Contributor Author

wind57 commented Feb 13, 2025

sorry, should have been more verbose.

At the moment, we do something like this:

binder.bindOrCreate("spring.cloud.kubernetes.config", ConfigMapConfigProperties.class);

which binds the property : spring.cloud.kubernetes.config.sources.name to sample-configmap; even if dev is an active profile and it should have bind it to sample-configmap-dev.

My point about profile, is that the above happens in a method definition that looks like this:

	public final List<KubernetesConfigDataResource> resolveProfileSpecific(
			ConfigDataLocationResolverContext resolverContext, ConfigDataLocation location, Profiles profiles)

notice that Profiles profiles argument. I do know that dev is an active profile, so I thought that may be there is a way to tell the "binder" that it should bind profile specific in this case; but such a thing does not exist it seems

@ryanjbaxter
Copy link
Contributor

So I am trying to wrap my head around this so sorry if I am asking what seems like obvious questions...

application.yaml and application-dev.yaml are not in a configmap they are configuration files in the application itself?

If that is a correct assumption, you are activating the profile dev but when we call binder.bindOrCreate("spring.cloud.kubernetes.config", ConfigMapConfigProperties.class); the value of spring.cloud.kubernetes.config.sources[0].name is sample-configmap instead of sample-configmap-dev?

@wind57
Copy link
Contributor Author

wind57 commented Feb 14, 2025

Yes, correct.

Here is a sample that proves this. I had to alter the names a bit in the sample compared to what we have above because of includeProfileSpecificSources that is true by default.

wind57/spring-k8s-samples#3

You will have to clone the repo and switch to that branch, there are README instructions there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants