Skip to content

Commit

Permalink
Decouples configMap and secret property source locators by making the…
Browse files Browse the repository at this point in the history
…m optional dependencies for reload auto config as they could be enabled/disabled through config independent of each other. Fixes spring-cloud#635
  • Loading branch information
krisiye committed Sep 21, 2020
1 parent ca8b89b commit 60c6d0c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ protected static class ConfigReloadAutoConfigurationBeans {
@Autowired
private KubernetesClient kubernetesClient;

@Autowired
@Autowired(required = false)
private ConfigMapPropertySourceLocator configMapPropertySourceLocator;

@Autowired
@Autowired(required = false)
private SecretsPropertySourceLocator secretsPropertySourceLocator;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,26 @@ public void kubernetesWhenKubernetesDisabled() throws Exception {
}

@Test
public void kubernetesWhenKubernetesConfigDisabled() throws Exception {
setup("spring.cloud.kubernetes.config.enabled=false",
"spring.cloud.kubernetes.secrets.enabled=false");
public void kubernetesWhenKubernetesConfigAndSecretDisabled() throws Exception {
setup("spring.cloud.kubernetes.config.enabled=false", "spring.cloud.kubernetes.secrets.enabled=false");
assertThat(this.context.containsBean("configMapPropertySourceLocator")).isFalse();
assertThat(this.context.containsBean("secretsPropertySourceLocator")).isFalse();
}

@Test
public void kubernetesWhenKubernetesConfigEnabledButSecretDisabled() throws Exception {
setup("spring.cloud.kubernetes.config.enabled=true", "spring.cloud.kubernetes.secrets.enabled=false");
assertThat(this.context.containsBean("configMapPropertySourceLocator")).isTrue();
assertThat(this.context.containsBean("secretsPropertySourceLocator")).isFalse();
}

@Test
public void kubernetesWhenKubernetesConfigDisabledButSecretEnabled() throws Exception {
setup("spring.cloud.kubernetes.config.enabled=false", "spring.cloud.kubernetes.secrets.enabled=true");
assertThat(this.context.containsBean("configMapPropertySourceLocator")).isFalse();
assertThat(this.context.containsBean("secretsPropertySourceLocator")).isTrue();
}

@Test
public void kubernetesDefaultEnabled() throws Exception {
setup("spring.cloud.kubernetes.enabled=true");
Expand All @@ -66,11 +79,9 @@ public void kubernetesDefaultEnabled() throws Exception {
}

private void setup(String... env) {
this.context = new SpringApplicationBuilder(
PropertyPlaceholderAutoConfiguration.class,
this.context = new SpringApplicationBuilder(PropertyPlaceholderAutoConfiguration.class,
KubernetesClientTestConfiguration.class, BootstrapConfiguration.class)
.web(org.springframework.boot.WebApplicationType.NONE)
.properties(env).run();
.web(org.springframework.boot.WebApplicationType.NONE).properties(env).run();
}

@Configuration(proxyBeanMethods = false)
Expand Down

0 comments on commit 60c6d0c

Please sign in to comment.