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.

CloudSqlEnvironmentPostProcessor not compatible with Spring Cloud Bootstrap PropertySourceLocator mechanism

See original GitHub issue

I discovered that the new CloudSqlEnvironmentPostProcessor within Spring Cloud GCP 2.x causes issues when you combine it with properties that are being loaded via a PropertySource that is created via the Spring Cloud Bootstrap PropertySourceLocator. The reason is that the properties loaded via a PropertySource that is created by a PropertySourceLocator are loaded after the CloudSqlEnvironmentPostProcessor is executed.

The case in which we discovered this is as follows:

  • In the application.yml, on the classpath, the property spring.cloud.gcp.sql.enabled is set to false
  • When the application is deployed to a GKE environment, Spring Cloud Kubernetes is used to load a Kubernetes ConfigMap, via the Kubernetes API so the ConfigMap is not mounted in the container, and this ConfigMap contains the same spring.cloud.gcp.sql.enabled property but it set to true
  • The intention is to have CloudSQL disabled when developing locally, but it is used when running the application within GKE.
  • When deploying in GKE with the ConfigMap, the spring.cloud.gcp.sql.enabled=true is never picked up by the CloudSqlEnvironmentPostProcessor and thus it doesn’t do its thing to setup the required correct Datasource for CloudSQL. The application fails to startup.
  • The issue is that Spring Cloud Kubernetes uses the Spring Cloud Bootstrap PropertySourceLocator mechanism to create a PropertySource for the ConfigMap but this happens when the ApplicationContextInitializers are executed, which is after the EnvironmentPostProcessor have been executed in the normal application context startup phase (so the PropertySourceLocator is only created in the bootstrap contact startup phase and executed in the application context startup phase). Because of that the CloudSqlEnvironmentPostProcessor never sees the properties from the ConfigMap PropertySource.

To figure out what was going on took some time. In the end, there are plenty workaround like simply mounting the ConfigMap and loading via one of the ways that Spring Boot has to load configuration, but it would be best if the CloudSQL support mechanism in Spring Cloud GCP would simply be compatible with Spring Cloud Bootstrap and it all works as expected.

I am not sure what a good solution is. Maybe go back to the mechanism from Spring Cloud GCP 1.x?

Sample I have not provided a code sample, as this is requires fairly complicated setup to demonstrate the issue. I hope that the explanation above suffices to make the issue clear.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:21 (18 by maintainers)

github_iconTop GitHub Comments

1reaction
mzeijencommented, Apr 15, 2021

Indeed, but in this case it is not the Spring Cloud Config Server but a Spring Cloud Kubernetes ConfigMap PropertySource, but the mechanism is the same.

0reactions
JoeWang1127commented, Nov 14, 2022

Close this issue as no response, please reopen the issue if needed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spring Boot 2.6.12 compatibility with Spring Cloud (Config ...
I'm trying to update my project Spring Boot version from 2.4.13 to 2.6.12 ... about spring.config.import or spring-cloud-starter-bootstrap.
Read more >
Spring Cloud Config
Spring Cloud Config provides server-side and client-side support for externalized configuration in a distributed system. With the Config Server, ...
Read more >
Spring Cloud GCP
It handles the work of generating the Maven or Gradle build file so you do not have to manually add the dependencies yourself....
Read more >
Spring Cloud - Bootstrapping - Baeldung
This article shows how to bootstrap spring cloud application by employing ... Externalizing configuration so that is flexible and does not ...
Read more >
Spring Cloud - Indico
Integrating your Spring Cloud application with the AWS Parameter Store . ... with a default value to avoid bootstrap errors if the properties...
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