Skip to content

Commit 05db469

Browse files
committed
Revert "Override CloudPlatform auto-detection with property"
This reverts commit 4b7ed5e. See gh-20553
1 parent 3cc0ab1 commit 05db469

File tree

3 files changed

+9
-46
lines changed

3 files changed

+9
-46
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/cloud/CloudPlatform.java

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public enum CloudPlatform {
3838
CLOUD_FOUNDRY {
3939

4040
@Override
41-
public boolean isAutoDetected(Environment environment) {
41+
public boolean isActive(Environment environment) {
4242
return environment.containsProperty("VCAP_APPLICATION") || environment.containsProperty("VCAP_SERVICES");
4343
}
4444

@@ -50,7 +50,7 @@ public boolean isAutoDetected(Environment environment) {
5050
HEROKU {
5151

5252
@Override
53-
public boolean isAutoDetected(Environment environment) {
53+
public boolean isActive(Environment environment) {
5454
return environment.containsProperty("DYNO");
5555
}
5656

@@ -62,7 +62,7 @@ public boolean isAutoDetected(Environment environment) {
6262
SAP {
6363

6464
@Override
65-
public boolean isAutoDetected(Environment environment) {
65+
public boolean isActive(Environment environment) {
6666
return environment.containsProperty("HC_LANDSCAPE");
6767
}
6868

@@ -82,14 +82,14 @@ public boolean isAutoDetected(Environment environment) {
8282
private static final String SERVICE_PORT_SUFFIX = "_SERVICE_PORT";
8383

8484
@Override
85-
public boolean isAutoDetected(Environment environment) {
85+
public boolean isActive(Environment environment) {
8686
if (environment instanceof ConfigurableEnvironment) {
87-
return isAutoDetected((ConfigurableEnvironment) environment);
87+
return isActive((ConfigurableEnvironment) environment);
8888
}
8989
return false;
9090
}
9191

92-
private boolean isAutoDetected(ConfigurableEnvironment environment) {
92+
private boolean isActive(ConfigurableEnvironment environment) {
9393
PropertySource<?> environmentPropertySource = environment.getPropertySources()
9494
.get(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME);
9595
if (environmentPropertySource != null) {
@@ -98,13 +98,13 @@ private boolean isAutoDetected(ConfigurableEnvironment environment) {
9898
return true;
9999
}
100100
if (environmentPropertySource instanceof EnumerablePropertySource) {
101-
return isAutoDetected((EnumerablePropertySource<?>) environmentPropertySource);
101+
return isActive((EnumerablePropertySource<?>) environmentPropertySource);
102102
}
103103
}
104104
return false;
105105
}
106106

107-
private boolean isAutoDetected(EnumerablePropertySource<?> environmentPropertySource) {
107+
private boolean isActive(EnumerablePropertySource<?> environmentPropertySource) {
108108
for (String propertyName : environmentPropertySource.getPropertyNames()) {
109109
if (propertyName.endsWith(SERVICE_HOST_SUFFIX)) {
110110
String serviceName = propertyName.substring(0,
@@ -124,31 +124,7 @@ private boolean isAutoDetected(EnumerablePropertySource<?> environmentPropertySo
124124
* @param environment the environment
125125
* @return if the platform is active.
126126
*/
127-
public boolean isActive(Environment environment) {
128-
return isEnforced(environment) || isAutoDetected(environment);
129-
}
130-
131-
/**
132-
* Detemines if the platform is enforced by looking at the
133-
* {@code "spring.main.cloud-platform"} configuration property.
134-
* @param environment the environment
135-
* @return if the platform is enforced
136-
*/
137-
public boolean isEnforced(Environment environment) {
138-
String platform = environment.getProperty("spring.main.cloud-platform");
139-
if (platform != null) {
140-
return this.name().equalsIgnoreCase(platform);
141-
}
142-
return false;
143-
}
144-
145-
/**
146-
* Determines if the platform is auto-detected by looking for platform-specific
147-
* environment variables.
148-
* @param environment the environment
149-
* @return if the platform is auto-detected.
150-
*/
151-
public abstract boolean isAutoDetected(Environment environment);
127+
public abstract boolean isActive(Environment environment);
152128

153129
/**
154130
* Returns if the platform is behind a load balancer and uses

spring-boot-project/spring-boot/src/main/resources/META-INF/additional-spring-configuration-metadata.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -640,11 +640,6 @@
640640
"description": "Mode used to display the banner when the application runs.",
641641
"defaultValue": "console"
642642
},
643-
{
644-
"name": "spring.main.cloud-platform",
645-
"type": "org.springframework.boot.cloud.CloudPlatform",
646-
"description": "Override the Cloud Platform auto-detection."
647-
},
648643
{
649644
"name": "spring.main.lazy-initialization",
650645
"type": "java.lang.Boolean",

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/cloud/CloudPlatformTests.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,6 @@ void getActiveWhenHasServiceHostAndNoServicePortShouldNotReturnKubernetes() {
129129
assertThat(platform).isNull();
130130
}
131131

132-
@Test
133-
void getActiveWhenHasEnforcedCloudPlatform() {
134-
Environment environment = getEnvironmentWithEnvVariables(
135-
Collections.singletonMap("spring.main.cloud-platform", "kubernetes"));
136-
CloudPlatform platform = CloudPlatform.getActive(environment);
137-
assertThat(platform).isEqualTo(CloudPlatform.KUBERNETES);
138-
}
139-
140132
private Environment getEnvironmentWithEnvVariables(Map<String, Object> environmentVariables) {
141133
MockEnvironment environment = new MockEnvironment();
142134
PropertySource<?> propertySource = new SystemEnvironmentPropertySource(

0 commit comments

Comments
 (0)