Skip to content

Commit

Permalink
fix (#1040)
Browse files Browse the repository at this point in the history
  • Loading branch information
wind57 authored Jul 5, 2022
1 parent 87f6744 commit 74258a8
Show file tree
Hide file tree
Showing 30 changed files with 57 additions and 159 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import io.kubernetes.client.openapi.apis.CoreV1Api;

import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnCloudPlatform;
import org.springframework.boot.cloud.CloudPlatform;
import org.springframework.cloud.kubernetes.client.KubernetesClientAutoConfiguration;
import org.springframework.cloud.kubernetes.commons.ConditionalOnKubernetesConfigEnabled;
import org.springframework.cloud.kubernetes.commons.ConditionalOnKubernetesEnabled;
Expand All @@ -43,7 +41,6 @@
@ConditionalOnKubernetesEnabled
@AutoConfigureAfter(KubernetesBootstrapConfiguration.class)
@Import({ KubernetesCommonsAutoConfiguration.class, KubernetesClientAutoConfiguration.class })
@ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES)
public class KubernetesClientBootstrapConfiguration {

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnCloudPlatform;
import org.springframework.boot.cloud.CloudPlatform;
import org.springframework.cloud.kubernetes.client.KubernetesClientAutoConfiguration;
import org.springframework.cloud.kubernetes.commons.ConditionalOnKubernetesEnabled;
import org.springframework.cloud.kubernetes.commons.KubernetesCommonsAutoConfiguration;
Expand All @@ -44,7 +42,6 @@
@AutoConfigureAfter(KubernetesBootstrapConfiguration.class)
@AutoConfigureBefore(KubernetesClientBootstrapConfiguration.class)
@Import({ KubernetesCommonsAutoConfiguration.class, KubernetesClientAutoConfiguration.class })
@ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES)
@ConditionalOnKubernetesConfigOrSecretsRetryEnabled
public class KubernetesClientRetryBootstrapConfiguration {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void configAndSecretsBeansAreNotPresent() {

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class,
properties = { "spring.cloud.kubernetes.secrets.enabled=true",
"spring.cloud.kubernetes.client.namespace=default", "spring.main.cloud-platform=KUBERNETES" })
"spring.cloud.kubernetes.client.namespace=default" })
@Nested
class KubernetesEnabledOnPurpose {

Expand All @@ -71,8 +71,7 @@ void configAndSecretsBeansArePresent() {
}

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class,
properties = { "spring.cloud.kubernetes.client.namespace=default",
"spring.main.cloud-platform=KUBERNETES" })
properties = { "spring.cloud.kubernetes.client.namespace=default" })
@Nested
class KubernetesEnabled {

Expand All @@ -88,7 +87,7 @@ void configAndSecretsBeansArePresent() {
}

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class,
properties = { "spring.cloud.kubernetes.config.enabled=false", "spring.main.cloud-platform=KUBERNETES" })
properties = { "spring.cloud.kubernetes.config.enabled=false" })
@Nested
class KubernetesEnabledConfigDisabled {

Expand All @@ -105,7 +104,7 @@ void secretsOnlyPresent() {

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class,
properties = { "spring.cloud.kubernetes.secrets.enabled=false",
"spring.cloud.kubernetes.client.namespace=default", "spring.main.cloud-platform=KUBERNETES" })
"spring.cloud.kubernetes.client.namespace=default" })
@Nested
class KubernetesEnabledSecretsDisabled {

Expand All @@ -122,7 +121,7 @@ void secretsOnlyPresent() {

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class,
properties = { "spring.cloud.kubernetes.secrets.enabled=false",
"spring.cloud.kubernetes.config.enabled=false", "spring.main.cloud-platform=KUBERNETES" })
"spring.cloud.kubernetes.config.enabled=false" })
@Nested
class KubernetesEnabledSecretsAndConfigDisabled {

Expand All @@ -137,40 +136,4 @@ void secretsOnlyPresent() {

}

// tests that @ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES) has the desired
// effect, meaning when it is enabled, both property sources are present
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class,
properties = { "spring.main.cloud-platform=KUBERNETES", "spring.cloud.kubernetes.client.namespace=abc" })
@Nested
class KubernetesClientBootstrapConfigurationInsideK8s {

@Autowired
ConfigurableApplicationContext context;

@Test
public void bothPresent() {
assertThat(context.getBeanNamesForType(KubernetesClientConfigMapPropertySourceLocator.class)).hasSize(1);
assertThat(context.getBeanNamesForType(KubernetesClientSecretsPropertySourceLocator.class)).hasSize(1);
}

}

// tests that @ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES) has the desired
// effect, meaning when it is disabled, no property source bean is present
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class,
properties = { "kubernetes.informer.enabled=false" })
@Nested
class KubernetesClientBootstrapConfigurationNotInsideK8s {

@Autowired
ConfigurableApplicationContext context;

@Test
public void bothMissing() {
assertThat(context.getBeanNamesForType(KubernetesClientConfigMapPropertySourceLocator.class)).hasSize(0);
assertThat(context.getBeanNamesForType(KubernetesClientSecretsPropertySourceLocator.class)).hasSize(0);
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
classes = IncludeProfileSpecificSourcesApp.class,
properties = { "spring.cloud.bootstrap.name=include-profile-specific-sources",
"include.profile.specific.sources=true", "spring.main.cloud-platform=KUBERNETES" })
"include.profile.specific.sources=true" })
@AutoConfigureWebTestClient
@ActiveProfiles("dev")
class KubernetesClientConfigMapIncludeProfileSpecificSourcesTests {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@
*/
@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = WithPrefixApp.class,
properties = { "spring.cloud.bootstrap.name=config-map-name-as-prefix", "config.map.name.as.prefix.stub=true",
"spring.main.cloud-platform=KUBERNETES" })
properties = { "spring.cloud.bootstrap.name=config-map-name-as-prefix", "config.map.name.as.prefix.stub=true" })
@AutoConfigureWebTestClient
public class KubernetesClientConfigMapNameAsPrefixTests {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public void afterEach() {
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE,
properties = { "spring.cloud.kubernetes.client.namespace=default",
"spring.cloud.kubernetes.config.fail-fast=true",
"spring.cloud.kubernetes.config.retry.max-attempts=5", "spring.main.cloud-platform=KUBERNETES" },
"spring.cloud.kubernetes.config.retry.max-attempts=5" },
classes = App.class)
class ConfigRetryEnabled {

Expand Down Expand Up @@ -202,7 +202,7 @@ public void locateShouldRetryAndFail() {
@Nested
@SpringBootTest(
webEnvironment = SpringBootTest.WebEnvironment.NONE, properties = {
"spring.cloud.kubernetes.client.namespace=default", "spring.main.cloud-platform=KUBERNETES" },
"spring.cloud.kubernetes.client.namespace=default" },
classes = App.class)
class ConfigFailFastDisabled {

Expand All @@ -227,7 +227,7 @@ public void locateShouldNotRetry() {
properties = { "spring.cloud.kubernetes.client.namespace=default",
"spring.cloud.kubernetes.config.fail-fast=true",
"spring.cloud.kubernetes.config.retry.enabled=false",
"spring.cloud.kubernetes.secrets.fail-fast=true", "spring.main.cloud-platform=KUBERNETES" },
"spring.cloud.kubernetes.secrets.fail-fast=true" },
classes = App.class)
class ConfigRetryDisabledButSecretsRetryEnabled {

Expand Down Expand Up @@ -264,7 +264,7 @@ public void locateShouldFailWithoutRetrying() {
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE,
properties = { "spring.cloud.kubernetes.client.namespace=default",
"spring.cloud.kubernetes.config.fail-fast=true",
"spring.cloud.kubernetes.config.retry.enabled=false", "spring.main.cloud-platform=KUBERNETES" },
"spring.cloud.kubernetes.config.retry.enabled=false" },
classes = App.class)
class ConfigFailFastEnabledButRetryDisabled {

Expand Down Expand Up @@ -321,8 +321,7 @@ public void afterEach() {
@Test
public void doesNotContainRetryableConfigMapPropertySourceLocator() throws Exception {
stubFor(get(API).willReturn(aResponse().withStatus(500).withBody("Internal Server Error")));
setup("debug=true", "spring.main.cloud-platform=KUBERNETES",
"spring.cloud.kubernetes.test.enable-retry=true");
setup("debug=true", "spring.cloud.kubernetes.test.enable-retry=true");
assertThat(context.containsBean("retryableConfigMapPropertySourceLocator")).isFalse();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public void afterEach() {
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, properties = {
"spring.cloud.kubernetes.client.namespace=default", "spring.cloud.kubernetes.secrets.fail-fast=true",
"spring.cloud.kubernetes.secrets.retry.max-attempts=5", "spring.cloud.kubernetes.secrets.name=my-secret",
"spring.cloud.kubernetes.secrets.enable-api=true", "spring.main.cloud-platform=KUBERNETES" },
"spring.cloud.kubernetes.secrets.enable-api=true" },
classes = App.class)
class SecretsRetryEnabled {

Expand Down Expand Up @@ -202,8 +202,7 @@ public void locateShouldRetryAndFail() {
@Nested
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE,
properties = { "spring.cloud.kubernetes.client.namespace=default",
"spring.cloud.kubernetes.secrets.name=my-secret", "spring.cloud.kubernetes.secrets.enable-api=true",
"spring.main.cloud-platform=KUBERNETES" },
"spring.cloud.kubernetes.secrets.name=my-secret", "spring.cloud.kubernetes.secrets.enable-api=true" },
classes = App.class)
class SecretsFailFastDisabled {

Expand All @@ -229,7 +228,7 @@ public void locateShouldNotRetry() {
"spring.cloud.kubernetes.secrets.fail-fast=true",
"spring.cloud.kubernetes.secrets.retry.enabled=false",
"spring.cloud.kubernetes.config.fail-fast=true", "spring.cloud.kubernetes.secrets.name=my-secret",
"spring.cloud.kubernetes.secrets.enable-api=true", "spring.main.cloud-platform=KUBERNETES" },
"spring.cloud.kubernetes.secrets.enable-api=true" },
classes = App.class)
class SecretsRetryDisabledButConfigRetryEnabled {

Expand Down Expand Up @@ -266,7 +265,7 @@ public void locateShouldFailWithoutRetrying() {
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, properties = {
"spring.cloud.kubernetes.client.namespace=default", "spring.cloud.kubernetes.secrets.fail-fast=true",
"spring.cloud.kubernetes.secrets.retry.enabled=false", "spring.cloud.kubernetes.secrets.name=my-secret",
"spring.cloud.kubernetes.secrets.enable-api=true", "spring.main.cloud-platform=KUBERNETES" },
"spring.cloud.kubernetes.secrets.enable-api=true" },
classes = App.class)
class SecretsFailFastEnabledButRetryDisabled {

Expand Down Expand Up @@ -323,7 +322,7 @@ public void afterEach() {
@Test
public void doesNotContainRetryableSecretsPropertySourceLocator() throws Exception {
stubFor(get(API).willReturn(aResponse().withStatus(500).withBody("Internal Server Error")));
setup("debug=true", "spring.main.cloud-platform=KUBERNETES",
setup("debug=true",
"spring.cloud.kubernetes.test.enable-retry=true", "spring.cloud.kubernetes.secrets.name=my-secret",
"spring.cloud.kubernetes.secrets.enable-api=true");
assertThat(context.containsBean("retryableSecretsPropertySourceLocator")).isFalse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ public void kubernetesReloadEnabledButSecretAndConfigDisabled() throws Exception

@Test
public void kubernetesReloadEnabledWithPolling() throws Exception {
setup("spring.cloud.kubernetes.reload.enabled=true", "spring.cloud.kubernetes.reload.mode=polling",
"spring.main.cloud-platform=KUBERNETES");
setup("spring.cloud.kubernetes.reload.enabled=true", "spring.cloud.kubernetes.reload.mode=polling");
assertThat(context.containsBean("configMapPropertySourceLocator")).isTrue();
assertThat(context.containsBean("secretsPropertySourceLocator")).isTrue();
assertThat(context.containsBean("configMapPropertyChangePollingWatcher")).isTrue();
Expand All @@ -164,8 +163,7 @@ public void kubernetesReloadEnabledWithPolling() throws Exception {

@Test
public void kubernetesReloadEnabledWithEvent() throws Exception {
setup("spring.cloud.kubernetes.reload.enabled=true", "spring.cloud.kubernetes.reload.mode=event",
"spring.main.cloud-platform=KUBERNETES");
setup("spring.cloud.kubernetes.reload.enabled=true", "spring.cloud.kubernetes.reload.mode=event");
assertThat(context.containsBean("configMapPropertyChangePollingWatcher")).isFalse();
assertThat(context.containsBean("secretsPropertyChangePollingWatcher")).isFalse();
assertThat(context.containsBean("configMapPropertyChangeEventWatcher")).isTrue();
Expand All @@ -176,21 +174,21 @@ public void kubernetesReloadEnabledWithEvent() throws Exception {

@Test
public void kubernetesConfigAndSecretEnabledByDefault() throws Exception {
setup("spring.main.cloud-platform=KUBERNETES");
setup();
assertThat(context.containsBean("configMapPropertySourceLocator")).isTrue();
assertThat(context.containsBean("secretsPropertySourceLocator")).isTrue();
}

@Test
public void kubernetesConfigEnabledButSecretDisabled() throws Exception {
setup("spring.cloud.kubernetes.secrets.enabled=false", "spring.main.cloud-platform=KUBERNETES");
setup("spring.cloud.kubernetes.secrets.enabled=false");
assertThat(context.containsBean("configMapPropertySourceLocator")).isTrue();
assertThat(context.containsBean("secretsPropertySourceLocator")).isFalse();
}

@Test
public void kubernetesSecretsEnabledButConfigDisabled() throws Exception {
setup("spring.cloud.kubernetes.config.enabled=false", "spring.main.cloud-platform=KUBERNETES");
setup("spring.cloud.kubernetes.config.enabled=false");
assertThat(context.containsBean("configMapPropertySourceLocator")).isFalse();
assertThat(context.containsBean("secretsPropertySourceLocator")).isTrue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnCloudPlatform;
import org.springframework.boot.cloud.CloudPlatform;
import org.springframework.cloud.kubernetes.commons.ConditionalOnKubernetesConfigEnabled;
import org.springframework.cloud.kubernetes.commons.ConditionalOnKubernetesEnabled;
import org.springframework.cloud.kubernetes.commons.ConditionalOnKubernetesSecretsEnabled;
Expand All @@ -50,7 +48,6 @@
@Import({ KubernetesCommonsAutoConfiguration.class, Fabric8AutoConfiguration.class })
@ConditionalOnClass({ ConfigMap.class, Secret.class })
@AutoConfigureAfter(KubernetesBootstrapConfiguration.class)
@ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES)
public class Fabric8BootstrapConfiguration {

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnCloudPlatform;
import org.springframework.boot.cloud.CloudPlatform;
import org.springframework.cloud.kubernetes.commons.ConditionalOnKubernetesEnabled;
import org.springframework.cloud.kubernetes.commons.KubernetesCommonsAutoConfiguration;
import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider;
Expand All @@ -48,7 +46,6 @@
@Import({ KubernetesCommonsAutoConfiguration.class, Fabric8AutoConfiguration.class })
@ConditionalOnClass({ ConfigMap.class, Secret.class })
@AutoConfigureAfter(KubernetesBootstrapConfiguration.class)
@ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES)
@ConditionalOnKubernetesConfigOrSecretsRetryEnabled
public class Fabric8RetryBootstrapConfiguration {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@
@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
classes = IncludeProfileSpecificSourcesApp.class,
properties = { "spring.cloud.bootstrap.name=include-profile-specific-sources",
"spring.main.cloud-platform=KUBERNETES" })
properties = { "spring.cloud.bootstrap.name=include-profile-specific-sources" })
@AutoConfigureWebTestClient
@EnableKubernetesMockClient(crud = true, https = false)
@ActiveProfiles("dev")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@
*/
@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = WithPrefixApp.class,
properties = { "spring.cloud.bootstrap.name=config-map-name-as-prefix",
"spring.main.cloud-platform=KUBERNETES" })
properties = { "spring.cloud.bootstrap.name=config-map-name-as-prefix"})
@AutoConfigureWebTestClient
@EnableKubernetesMockClient(crud = true, https = false)
class ConfigMapWithPrefixTests {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@
"spring.cloud.kubernetes.config.enableApi=false",
"spring.cloud.kubernetes.config.paths=" + ConfigMapsFromFilePathsTests.FIRST_FILE_NAME_FULL_PATH + ","
+ ConfigMapsFromFilePathsTests.SECOND_FILE_NAME_FULL_PATH + ","
+ ConfigMapsFromFilePathsTests.FIRST_FILE_NAME_DUPLICATED_FULL_PATH,
"spring.main.cloud-platform=KUBERNETES" })
+ ConfigMapsFromFilePathsTests.FIRST_FILE_NAME_DUPLICATED_FULL_PATH })
@EnableKubernetesMockClient(crud = true, https = false)
public class ConfigMapsFromFilePathsTests {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class,
properties = { "spring.application.name=" + ConfigMapsMixedTests.APPLICATION_NAME,
"spring.cloud.kubernetes.config.enableApi=true",
"spring.cloud.kubernetes.config.paths=" + ConfigMapsMixedTests.FILE_NAME_FULL_PATH,
"spring.main.cloud-platform=KUBERNETES" })
"spring.cloud.kubernetes.config.paths=" + ConfigMapsMixedTests.FILE_NAME_FULL_PATH })
@EnableKubernetesMockClient(crud = true, https = false)
public class ConfigMapsMixedTests {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
*/
@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class,
properties = { "spring.application.name=configmap-example", "spring.cloud.kubernetes.reload.enabled=false",
"spring.main.cloud-platform=KUBERNETES" })
properties = { "spring.application.name=configmap-example", "spring.cloud.kubernetes.reload.enabled=false"})
@AutoConfigureWebTestClient
@EnableKubernetesMockClient(crud = true, https = false)
public class ConfigMapsTests {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = RANDOM_PORT, classes = App.class,
properties = { "spring.application.name=configmap-with-active-profile-name-example",
"spring.cloud.kubernetes.reload.enabled=false", "spring.main.cloud-platform=KUBERNETES" })
"spring.cloud.kubernetes.reload.enabled=false" })
@ActiveProfiles("development")
@AutoConfigureWebTestClient
@EnableKubernetesMockClient(crud = true, https = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class,
properties = { "spring.application.name=configmap-with-profile-example",
"spring.cloud.kubernetes.reload.enabled=false", "spring.main.cloud-platform=KUBERNETES" })
"spring.cloud.kubernetes.reload.enabled=false" })
@ActiveProfiles({ "production", "us-east" })
@AutoConfigureWebTestClient
@EnableKubernetesMockClient(crud = true, https = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class,
properties = { "spring.application.name=configmap-with-profile-no-active-profiles-example",
"spring.cloud.kubernetes.reload.enabled=false", "spring.main.cloud-platform=KUBERNETES" })
"spring.cloud.kubernetes.reload.enabled=false" })
@AutoConfigureWebTestClient
@EnableKubernetesMockClient(crud = true, https = false)
public class ConfigMapsWithProfilesNoActiveProfileTests {
Expand Down
Loading

0 comments on commit 74258a8

Please sign in to comment.