Merge branch 'fix_secrets_reload_issue' into drop_ingress

This commit is contained in:
wind57
2025-03-29 21:42:03 +02:00
2 changed files with 44 additions and 13 deletions

View File

@@ -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;

View File

@@ -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<? extends PropertySource> 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<? extends PropertySource> 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<? extends PropertySource> 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<PropertySource<?>> 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<String> {
private static final class PlainPropertySource<T> extends PropertySource<T> {
private PlainPropertySource(String name) {
super(name);
@@ -189,15 +215,18 @@ class ConfigReloadUtilTests {
}
private static final class OneBootstrap extends BootstrapPropertySource<String> {
private static final class OneBootstrap<T> extends BootstrapPropertySource<T> {
private OneBootstrap(EnumerablePropertySource<String> delegate) {
private final EnumerablePropertySource<T> delegate;
private OneBootstrap(EnumerablePropertySource<T> delegate) {
super(delegate);
this.delegate = delegate;
}
@Override
public PropertySource<String> getDelegate() {
return new PlainPropertySource("from-bootstrap");
public PropertySource<T> getDelegate() {
return delegate;
}
}