Allows disabling the SecretsPropertySourceLocator with a property.

fixes gh-125
This commit is contained in:
Spencer Gibb
2018-11-13 11:44:15 -05:00
parent 8be84431bc
commit 0b8e1c9810
3 changed files with 19 additions and 3 deletions

View File

@@ -39,18 +39,19 @@ public class BootstrapConfiguration {
@Import(KubernetesAutoConfiguration.class)
@EnableConfigurationProperties({ ConfigMapConfigProperties.class,
SecretsConfigProperties.class })
@ConditionalOnProperty(name = "spring.cloud.kubernetes.config.enabled", matchIfMissing = true)
protected static class KubernetesPropertySourceConfiguration {
@Autowired
private KubernetesClient client;
@Bean
@ConditionalOnProperty(name = "spring.cloud.kubernetes.config.enabled", matchIfMissing = true)
public ConfigMapPropertySourceLocator configMapPropertySourceLocator(
ConfigMapConfigProperties properties) {
return new ConfigMapPropertySourceLocator(client, properties);
}
@Bean
@ConditionalOnProperty(name = "spring.cloud.kubernetes.secrets.enabled", matchIfMissing = true)
public SecretsPropertySourceLocator secretsPropertySourceLocator(
SecretsConfigProperties properties) {
return new SecretsPropertySourceLocator(client, properties);

View File

@@ -0,0 +1,15 @@
{"properties": [
{
"name": "spring.cloud.kubernetes.config.enabled",
"type": "java.lang.Boolean",
"description": "Enable the ConfigMap property source locator.",
"defaultValue": true
},
{
"name": "spring.cloud.kubernetes.secrets.enabled",
"type": "java.lang.Boolean",
"description": "Enable the Secrets property source locator.",
"defaultValue": true
}
]}

View File

@@ -37,12 +37,12 @@ public class KubernetesConfigConfigurationTest {
@Test
public void kubernetesWhenKubernetesConfigDisabled() throws Exception {
setup("spring.cloud.kubernetes.config.enabled=false");
setup("spring.cloud.kubernetes.config.enabled=false",
"spring.cloud.kubernetes.secrets.enabled=false");
assertFalse(context.containsBean("configMapPropertySourceLocator"));
assertFalse(context.containsBean("secretsPropertySourceLocator"));
}
@Test
public void kubernetesDefaultEnabled() throws Exception {
setup("spring.cloud.kubernetes.enabled=true");