fix tests

Signed-off-by: wind57 <eugen.rabii@gmail.com>
This commit is contained in:
wind57
2025-03-28 11:27:39 +02:00
parent b851f9c127
commit 71c9c893f4
4 changed files with 12 additions and 5 deletions

View File

@@ -27,6 +27,7 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.cloud.bootstrap.config.BootstrapPropertySource;
import org.springframework.cloud.bootstrap.config.PropertySourceLocator;
import org.springframework.cloud.kubernetes.commons.config.MountConfigMapPropertySource;
import org.springframework.cloud.kubernetes.commons.config.SecretsPropertySource;
import org.springframework.core.env.CompositePropertySource;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MapPropertySource;
@@ -120,6 +121,10 @@ public final class ConfigReloadUtil {
// we know that the type is correct here
managedSources.add((S) mountConfigMapPropertySource);
}
else if (propertySource instanceof SecretsPropertySource secretsPropertySource) {
// we know that the type is correct here
managedSources.add((S) secretsPropertySource);
}
}
}
@@ -179,6 +184,8 @@ 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

@@ -13,3 +13,6 @@ spring:
paths:
- /tmp/application.properties
config:
import: "kubernetes:"

View File

@@ -5,7 +5,7 @@ spring:
kubernetes:
reload:
enabled: true
strategy: shutdown
strategy: refresh
mode: polling
period: 5000
monitoring-secrets: true

View File

@@ -18,7 +18,6 @@ package org.springframework.cloud.kubernetes.k8s.client.reload.it;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.Base64;
import java.util.Map;
import io.kubernetes.client.openapi.apis.CoreV1Api;
@@ -28,7 +27,6 @@ import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.testcontainers.k3s.K3sContainer;
import org.springframework.cloud.kubernetes.commons.config.Constants;
import org.springframework.cloud.kubernetes.integration.tests.commons.Commons;
import org.springframework.cloud.kubernetes.integration.tests.commons.Phase;
import org.springframework.cloud.kubernetes.integration.tests.commons.native_client.Util;
@@ -101,8 +99,7 @@ class K8sClientSecretMountBootstrapPollingIT extends K8sClientReloadBase {
// replace data in secret and wait for k8s to pick it up
// our polling will detect that and restart the app
V1Secret secret = (V1Secret) util.yaml("mount/secret.yaml");
secret.setData(Map.of(Constants.APPLICATION_PROPERTIES, Base64.getEncoder()
.encode("from.properties.secret.key=as-mount-changed".getBytes(StandardCharsets.UTF_8))));
secret.setData(Map.of("from.properties.secret.key", "as-mount-changed".getBytes(StandardCharsets.UTF_8)));
coreV1Api.replaceNamespacedSecret("secret-reload", NAMESPACE, secret, null, null, null, null);
Commons.waitForLogStatement("Detected change in config maps/secrets, reload will be triggered", K3S,