diff --git a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/reload/ConfigReloadUtil.java b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/reload/ConfigReloadUtil.java index 3640bb7b..f066da4c 100644 --- a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/reload/ConfigReloadUtil.java +++ b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/reload/ConfigReloadUtil.java @@ -111,6 +111,10 @@ public final class ConfigReloadUtil { // we know that the type is correct here managedSources.add((S) mountConfigMapPropertySource); } + else if (source instanceof SecretsPropertySource secretsPropertySource) { + // we know that the type is correct here + managedSources.add((S) secretsPropertySource); + } else if (source instanceof BootstrapPropertySource bootstrapPropertySource) { PropertySource propertySource = bootstrapPropertySource.getDelegate(); LOG.debug(() -> "bootstrap delegate class : " + propertySource.getClass()); @@ -184,8 +188,6 @@ public final class ConfigReloadUtil { for (int i = 0; i < k8sSources.size(); i++) { MapPropertySource k8sSource = k8sSources.get(i); MapPropertySource appSource = appSources.get(i); - System.out.println("k8sSource (abc): " + k8sSource.getSource()); - System.out.println("appSource (abc): " + appSource.getSource()); if (changed(k8sSource, appSource)) { LOG.debug(() -> "found change in : " + k8sSource); return true; diff --git a/spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/config/reload/ConfigReloadUtilTests.java b/spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/config/reload/ConfigReloadUtilTests.java index 280d95f9..2d8430f7 100644 --- a/spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/config/reload/ConfigReloadUtilTests.java +++ b/spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/config/reload/ConfigReloadUtilTests.java @@ -27,6 +27,8 @@ import org.junit.jupiter.api.Test; import org.springframework.cloud.bootstrap.config.BootstrapPropertySource; import org.springframework.cloud.kubernetes.commons.config.MountConfigMapPropertySource; +import org.springframework.cloud.kubernetes.commons.config.SecretsPropertySource; +import org.springframework.cloud.kubernetes.commons.config.SourceData; import org.springframework.core.env.CompositePropertySource; import org.springframework.core.env.EnumerablePropertySource; import org.springframework.core.env.MapPropertySource; @@ -127,8 +129,8 @@ class ConfigReloadUtilTests { MockEnvironment environment = new MockEnvironment(); MutablePropertySources propertySources = environment.getPropertySources(); propertySources.addFirst(new OneComposite()); - propertySources.addFirst(new PlainPropertySource("plain")); - propertySources.addFirst(new OneBootstrap(new EnumerablePropertySource<>("enumerable") { + propertySources.addFirst(new PlainPropertySource<>("plain")); + propertySources.addFirst(new OneBootstrap<>(new EnumerablePropertySource<>("enumerable") { @Override public String[] getPropertyNames() { return new String[0]; @@ -143,11 +145,35 @@ class ConfigReloadUtilTests { List result = ConfigReloadUtil.findPropertySources(PlainPropertySource.class, environment); - Assertions.assertEquals(4, result.size()); + Assertions.assertEquals(3, result.size()); Assertions.assertEquals("b", result.get(0).getProperty("a")); Assertions.assertEquals("plain", result.get(1).getProperty("")); - Assertions.assertEquals("from-bootstrap", result.get(2).getProperty("")); - Assertions.assertEquals("from-inner-two-composite", result.get(3).getProperty("")); + Assertions.assertEquals("from-inner-two-composite", result.get(2).getProperty("")); + } + + @Test + void testSecretsPropertySource() { + MockEnvironment environment = new MockEnvironment(); + MutablePropertySources propertySources = environment.getPropertySources(); + propertySources.addFirst(new SecretsPropertySource(new SourceData("secret", Map.of("a", "b")))); + + List result = ConfigReloadUtil.findPropertySources(PlainPropertySource.class, + environment); + assertThat(result.size()).isEqualTo(1); + assertThat(result.get(0).getProperty("a")).isEqualTo("b"); + } + + @Test + void testBootstrapSecretsPropertySource() { + MockEnvironment environment = new MockEnvironment(); + MutablePropertySources propertySources = environment.getPropertySources(); + propertySources + .addFirst(new OneBootstrap<>(new SecretsPropertySource(new SourceData("secret", Map.of("a", "b"))))); + + List result = ConfigReloadUtil.findPropertySources(PlainPropertySource.class, + environment); + assertThat(result.size()).isEqualTo(1); + assertThat(result.get(0).getProperty("a")).isEqualTo("b"); } private static final class OneComposite extends CompositePropertySource { @@ -171,12 +197,12 @@ class ConfigReloadUtilTests { @Override public Collection> getPropertySources() { - return List.of(new PlainPropertySource("from-inner-two-composite")); + return List.of(new PlainPropertySource<>("from-inner-two-composite")); } } - private static final class PlainPropertySource extends PropertySource { + private static final class PlainPropertySource extends PropertySource { private PlainPropertySource(String name) { super(name); @@ -189,15 +215,18 @@ class ConfigReloadUtilTests { } - private static final class OneBootstrap extends BootstrapPropertySource { + private static final class OneBootstrap extends BootstrapPropertySource { - private OneBootstrap(EnumerablePropertySource delegate) { + private final EnumerablePropertySource delegate; + + private OneBootstrap(EnumerablePropertySource delegate) { super(delegate); + this.delegate = delegate; } @Override - public PropertySource getDelegate() { - return new PlainPropertySource("from-bootstrap"); + public PropertySource getDelegate() { + return delegate; } }