Hello Spring Boot Team,

Many thanks for the release of 2.5.0-RC1.

I was using 2.5.0-M3 fine with spring.profiles.active=mycustomeprofile,vault,kubernetes, nothing wrong, very happy.

INFO [myservice,,] 10 --- [           main] Application  : The following profiles are active: mycustomeprofile,vault,kubernetes

Just upgraded to 2.5.0-RC1, no code change, just a pom bump.

now, I get from the log:

The following profiles are active: kubernetes

It seems there is an issue with the profile.

Thank you

Comment From: wilkinsona

This works for me with a basic project generated on start.spring.io and spring.profiles.active=mycustomeprofile,vault,kubernetes added to application.properties:


  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::            (v2.5.0-RC1)

2021-04-18 08:58:28.331  INFO 81906 --- [           main] com.example.demo.Gh26151Application      : Starting Gh26151Application using Java 1.8.0_282 on wilkinsona-a01.vmware.com with PID 81906 (…/gh-26151/target/classes started by awilkinson in …/gh-26151)
2021-04-18 08:58:28.333  INFO 81906 --- [           main] com.example.demo.Gh26151Application      : The following profiles are active: mycustomeprofile,vault,kubernetes

If you would like us to spend some more time investigating, please spend some time providing a complete yet minimal sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.

Comment From: patpatpat123

Hello Andy,

Many thanks for your time looking at this. While preparing the minimal example, I had some technical findings I would like to share with you.

I believe it might be related to a Spring Cloud Kubernetes Issue. You are correct, on a local machine, it is behaving correctly, cannot reproduce the issue. However, when the app in deployed in Kubernetes, I am observing the following:

With version 2.5.0-M3, the profile "kubernetes" will be appended to the existing profile at the end. I configure mycustomeprofile,vault and inside the container log, I see The following profiles are active: mycustomeprofile,vault,kubernetes

On the over hand, with version 2.5.0.RC1, the profile "kubernetes" overrides whatever is there. I configure mycustomeprofile,vault and inside the container, I see The following profiles are active: kubernetes

Could you please help suggest what would be the next step please? Because the minimal example on the app layer as nothing specific. Yet, it needs a Kubernetes setup, and I will not be able to provide the Kubernetes manifest that is specific to our private cloud provider.

Would you recommend me to follow up the issue with Spring Cloud Kubernetes Team? Knowing the only change I made was the bump of Spring Boot from 2.5.0-M3 -> 2.5.0.RC1, nothing changed on Spring Cloud Kubernetes.

Thank you

Comment From: wilkinsona

Thanks for the additional information. This is why a minimal sample is useful. Your initial report didn't mention Spring Cloud Kubernetes and also stated that you were setting spring.profiles.active=mycustomeprofile,vault,kubernetes. As I now understand it, you're setting spring.profiles.active=mycustomeprofile,vault and relying on Spring Cloud Kubernetes to append the kubernetes profile.

With this information, I can reproduce the problem in a minimal application that depends upon spring-cloud-starter-kubernetes-client when run with KUBERNETES_SERVICE_HOST environment variable set. This is enough for it to believe that it is running in Kubernetes. The active profiles are then set to just kubernetes:


  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::             (v2.5.0-RC1)

2021-04-19 08:29:23.451  INFO 93896 --- [           main] ubernetesProfileEnvironmentPostProcessor : Did not find service account namespace at: [/var/run/secrets/kubernetes.io/serviceaccount/namespace]. Ignoring.
2021-04-19 08:29:23.459  INFO 93896 --- [           main] com.example.demo.Gh26151Application      : Starting Gh26151Application using Java 1.8.0_282 on wilkinsona-a01.vmware.com with PID 93896 (…/gh-26151/target/classes started by awilkinson in …/gh-26151)
2021-04-19 08:29:23.460  INFO 93896 --- [           main] com.example.demo.Gh26151Application      : The following profiles are active: kubernetes

However, unlike the situation you have described, I see the same behaviour with Spring Boot 2.5.0-M3:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::             (v2.5.0-M3)

2021-04-19 08:35:47.930  INFO 95068 --- [           main] ubernetesProfileEnvironmentPostProcessor : Did not find service account namespace at: [/var/run/secrets/kubernetes.io/serviceaccount/namespace]. Ignoring.
2021-04-19 08:35:47.937  INFO 95068 --- [           main] com.example.demo.Gh26151Application      : Starting Gh26151Application using Java 1.8.0_282 on wilkinsona-a01.vmware.com with PID 95068 (…/gh-26151/target/classes started by awilkinson in …/gh-26151)
2021-04-19 08:35:47.938  INFO 95068 --- [           main] com.example.demo.Gh26151Application      : The following profiles are active: kubernetes

I also see the same behaviour with 2.4.5:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.4.5)

2021-04-19 08:39:05.813  INFO 95115 --- [           main] ubernetesProfileEnvironmentPostProcessor : Did not find service account namespace at: [/var/run/secrets/kubernetes.io/serviceaccount/namespace]. Ignoring.
2021-04-19 08:39:05.820  INFO 95115 --- [           main] com.example.demo.Gh26151Application      : Starting Gh26151Application using Java 1.8.0_282 on wilkinsona-a01.vmware.com with PID 95115 (…/gh-26151/target/classes started by awilkinson in …/gh-26151)
2021-04-19 08:39:05.821  INFO 95115 --- [           main] com.example.demo.Gh26151Application      : The following profiles are active: kubernetes

Can you please provide a minimal sample that reproduces different behaviour with different versions of Spring Boot? It doesn't have be your complete application, and ideally would not be, just the bare minimum to reproduce the behaviour. It also doesn't need to include a K8S deployment manifest. Setting the KUBERNETES_SERVICE_HOST environment variable should be sufficient.

Comment From: wilkinsona

There does appear to be a change in behaviour between 2.3.x and 2.4.x. Here's a minimal example that illustrates the problem:

package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.core.env.StandardEnvironment;

@SpringBootApplication
public class Gh26151Application {

    public static void main(String[] args) {
        StandardEnvironment environment = new StandardEnvironment();
        environment.addActiveProfile("kubernetes");
        SpringApplication app = new SpringApplication(Gh26151Application.class);
        app.setEnvironment(environment);
        app.run("--spring.profiles.active=alpha,bravo");
    }

}

It's adding an active profile to the environment before config file processing begins which is what Spring Cloud Kubernetes does.

With Spring Boot 2.3.x, all three profiles are active:

09:48:09.276 [main] DEBUG org.springframework.core.env.StandardEnvironment - Activating profile 'kubernetes'

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::       (v2.3.10.RELEASE)

2021-04-19 09:48:09.615  INFO 5726 --- [           main] com.example.demo.Gh26151Application      : Starting Gh26151Application on wilkinsona-a01.vmware.com with PID 5726 (…/gh-26151/target/classes started by awilkinson in …/gh-26151)
2021-04-19 09:48:09.615  INFO 5726 --- [           main] com.example.demo.Gh26151Application      : The following profiles are active: kubernetes,alpha,bravo
2021-04-19 09:48:09.928  INFO 5726 --- [           main] com.example.demo.Gh26151Application      : Started Gh26151Application in 0.534 seconds (JVM running for 0.797)

With 2.4.5, only kubernetes is active:

09:49:11.587 [main] DEBUG org.springframework.core.env.StandardEnvironment - Activating profile 'kubernetes'

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.4.5)

2021-04-19 09:49:11.953  INFO 5741 --- [           main] com.example.demo.Gh26151Application      : Starting Gh26151Application using Java 1.8.0_282 on wilkinsona-a01.vmware.com with PID 5741 (…/gh-26151/target/classes started by awilkinson in …/gh-26151)
2021-04-19 09:49:11.953  INFO 5741 --- [           main] com.example.demo.Gh26151Application      : The following profiles are active: kubernetes
2021-04-19 09:49:12.271  INFO 5741 --- [           main] com.example.demo.Gh26151Application      : Started Gh26151Application in 0.559 seconds (JVM running for 0.831)

If we enable legacy config processing (app.run("--spring.profiles.active=alpha,bravo", "--spring.config.use-legacy-processing=true");), then all three profiles are active with Spring Boot 2.4.5 as well:

09:50:09.956 [main] DEBUG org.springframework.core.env.StandardEnvironment - Activating profile 'kubernetes'

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.4.5)

2021-04-19 09:50:10.317  INFO 5753 --- [           main] com.example.demo.Gh26151Application      : Starting Gh26151Application using Java 1.8.0_282 on wilkinsona-a01.vmware.com with PID 5753 (…/gh-26151/target/classes started by awilkinson in …/gh-26151)
2021-04-19 09:50:10.318  INFO 5753 --- [           main] com.example.demo.Gh26151Application      : The following profiles are active: kubernetes,alpha,bravo
2021-04-19 09:50:10.647  INFO 5753 --- [           main] com.example.demo.Gh26151Application      : Started Gh26151Application in 0.567 seconds (JVM running for 0.834)

@patpatpat123 Due to the differences in what I am seeing and what you have described, I'm not sure if I have reproduced your problem so a minimal sample would still be really useful.

Comment From: patpatpat123

Many thanks Andy for your time and help on this.

I am observing the same behavior, but between 2.5.0-M3 and 2.5.0-RC1. I tried anything prior to 2.5.0-M3, still getting all my profiles. Only 2.5.0-RC1 will get "kubernetes" only.

That aside, I am also going to give it a go for --spring.config.use-legacy-processing=true

Finally, still trying to provide the minimum example. We are having a very big and sensitive project, and we are removing layer by layer to try to make it minimal and reproducible.

Comment From: patpatpat123

Confirmed, with --spring.config.use-legacy-processing=true the apps are now having all the profiles mycustomeprofile,vault,kubernetes even, with 2.5.0-RC1.

The app then fail to start because I am using Spring Cloud Config, and setting this flag will make the app not connect connect to Vault to retrieve the properties. But that is another story.

Removing this flag only will revert back to 2.5.0-M3 having all the profiles, and 2.5.0-RC1 having only kubernetes as profile.

I understand I need to provide the reproducible example, but it is very difficult to remove layer by layer.

Thank you

Comment From: mbhave

There seems to be a test case for this behavior so it is seemingly intentional but I'm not sure why if that wasn't the case in previous versions. Flagging for team meeting.

Comment From: patpatpat123

Many thanks all for looking into this.

If possible, would it be possible to let the profiles being appended please?

For instance, I create mycustomprofile, and projects such as Vault or Kubernetes will only append their profile to it, and not override everything.

In the end, to have something such as mycustomprofile,vault,kubernetes, and what is observed now, which is kubernetes will override everything.

Thank you!

Comment From: patpatpat123

Hello Team,

Just wanted to say thanks for the fix. Tried with the GA 2.5.0 that just went live, it is now correct.

Wishing you a very good day