move ConfigReloadProperties to record (#1110)
This commit is contained in:
@@ -57,7 +57,7 @@ public final class KubernetesClientConfigUtils {
|
||||
*/
|
||||
public static Set<String> namespaces(KubernetesNamespaceProvider provider, ConfigReloadProperties properties,
|
||||
String target) {
|
||||
Set<String> namespaces = properties.getNamespaces();
|
||||
Set<String> namespaces = properties.namespaces();
|
||||
if (namespaces.isEmpty()) {
|
||||
namespaces = Set.of(getApplicationNamespace(null, target, provider));
|
||||
}
|
||||
|
||||
@@ -103,8 +103,8 @@ public class KubernetesClientEventBasedConfigMapChangeDetector extends Configura
|
||||
// certificate authorities for the cluster. This results in SSL errors.
|
||||
// See https://github.com/spring-cloud/spring-cloud-kubernetes/issues/885
|
||||
this.factory = new SharedInformerFactory(createApiClientForInformerClient());
|
||||
this.monitorConfigMaps = properties.isMonitoringConfigMaps();
|
||||
this.enableReloadFiltering = properties.isEnableReloadFiltering();
|
||||
this.monitorConfigMaps = properties.monitoringConfigMaps();
|
||||
this.enableReloadFiltering = properties.enableReloadFiltering();
|
||||
namespaces = namespaces(kubernetesNamespaceProvider, properties, "configmap");
|
||||
}
|
||||
|
||||
|
||||
@@ -103,8 +103,8 @@ public class KubernetesClientEventBasedSecretsChangeDetector extends Configurati
|
||||
// certificate authorities for the cluster. This results in SSL errors.
|
||||
// See https://github.com/spring-cloud/spring-cloud-kubernetes/issues/885
|
||||
this.factory = new SharedInformerFactory(createApiClientForInformerClient());
|
||||
this.monitorSecrets = properties.isMonitoringSecrets();
|
||||
this.enableReloadFiltering = properties.isEnableReloadFiltering();
|
||||
this.monitorSecrets = properties.monitoringSecrets();
|
||||
this.enableReloadFiltering = properties.enableReloadFiltering();
|
||||
namespaces = namespaces(kubernetesNamespaceProvider, properties, "secret");
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.cloud.kubernetes.client.config;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
@@ -58,21 +59,22 @@ class KubernetesClientConfigUtilsTests {
|
||||
|
||||
@Test
|
||||
void testNamespacesFromProperties() {
|
||||
ConfigReloadProperties configReloadProperties = new ConfigReloadProperties();
|
||||
configReloadProperties.setNamespaces(Set.of("non-default"));
|
||||
Set<String> namespaces = KubernetesClientConfigUtils.namespaces(
|
||||
new KubernetesNamespaceProvider(new MockEnvironment()), configReloadProperties, "configmap");
|
||||
ConfigReloadProperties properties = new ConfigReloadProperties(false, false, false,
|
||||
ConfigReloadProperties.ReloadStrategy.REFRESH, ConfigReloadProperties.ReloadDetectionMode.EVENT,
|
||||
Duration.ofMillis(15000), Set.of("non-default"), false, Duration.ofSeconds(2));
|
||||
Set<String> namespaces = KubernetesClientConfigUtils
|
||||
.namespaces(new KubernetesNamespaceProvider(new MockEnvironment()), properties, "configmap");
|
||||
Assertions.assertEquals(1, namespaces.size());
|
||||
Assertions.assertEquals(namespaces.iterator().next(), "non-default");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNamespacesFromProvider() {
|
||||
ConfigReloadProperties configReloadProperties = new ConfigReloadProperties();
|
||||
ConfigReloadProperties properties = ConfigReloadProperties.DEFAULT;
|
||||
MockEnvironment environment = new MockEnvironment();
|
||||
environment.setProperty("spring.cloud.kubernetes.client.namespace", "some");
|
||||
KubernetesNamespaceProvider provider = new KubernetesNamespaceProvider(environment);
|
||||
Set<String> namespaces = KubernetesClientConfigUtils.namespaces(provider, configReloadProperties, "configmap");
|
||||
Set<String> namespaces = KubernetesClientConfigUtils.namespaces(provider, properties, "configmap");
|
||||
Assertions.assertEquals(1, namespaces.size());
|
||||
Assertions.assertEquals(namespaces.iterator().next(), "some");
|
||||
}
|
||||
|
||||
@@ -158,8 +158,9 @@ class KubernetesClientEventBasedConfigMapChangeDetectorTests {
|
||||
when(locator.locate(environment)).thenAnswer(x -> new MockPropertySource().withProperty("debug", "false"));
|
||||
KubernetesNamespaceProvider kubernetesNamespaceProvider = mock(KubernetesNamespaceProvider.class);
|
||||
when(kubernetesNamespaceProvider.getNamespace()).thenReturn("default");
|
||||
|
||||
KubernetesClientEventBasedConfigMapChangeDetector changeDetector = new KubernetesClientEventBasedConfigMapChangeDetector(
|
||||
coreV1Api, environment, new ConfigReloadProperties(), strategy, locator, kubernetesNamespaceProvider);
|
||||
coreV1Api, environment, ConfigReloadProperties.DEFAULT, strategy, locator, kubernetesNamespaceProvider);
|
||||
|
||||
Thread controllerThread = new Thread(changeDetector::inform);
|
||||
controllerThread.setDaemon(true);
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.time.Duration;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.github.tomakehurst.wiremock.WireMockServer;
|
||||
@@ -151,8 +152,9 @@ class KubernetesClientEventBasedSecretsChangeDetectorTests {
|
||||
KubernetesClientSecretsPropertySourceLocator locator = mock(KubernetesClientSecretsPropertySourceLocator.class);
|
||||
when(locator.locate(environment))
|
||||
.thenAnswer(ignoreMe -> new MockPropertySource().withProperty("db-password", "p455w0rd2"));
|
||||
ConfigReloadProperties properties = new ConfigReloadProperties();
|
||||
properties.setMonitoringSecrets(true);
|
||||
ConfigReloadProperties properties = new ConfigReloadProperties(false, false, true,
|
||||
ConfigReloadProperties.ReloadStrategy.REFRESH, ConfigReloadProperties.ReloadDetectionMode.EVENT,
|
||||
Duration.ofMillis(15000), Set.of(), false, Duration.ofSeconds(2));
|
||||
KubernetesNamespaceProvider kubernetesNamespaceProvider = mock(KubernetesNamespaceProvider.class);
|
||||
when(kubernetesNamespaceProvider.getNamespace()).thenReturn("default");
|
||||
KubernetesClientEventBasedSecretsChangeDetector changeDetector = new KubernetesClientEventBasedSecretsChangeDetector(
|
||||
|
||||
@@ -63,8 +63,8 @@ public class ConfigReloadAutoConfiguration {
|
||||
@ConditionalOnMissingBean
|
||||
public ConfigurationUpdateStrategy configurationUpdateStrategy(ConfigReloadProperties properties,
|
||||
ConfigurableApplicationContext ctx, Optional<RestartEndpoint> restarter, ContextRefresher refresher) {
|
||||
String strategyName = properties.getStrategy().name();
|
||||
return switch (properties.getStrategy()) {
|
||||
String strategyName = properties.strategy().name();
|
||||
return switch (properties.strategy()) {
|
||||
case RESTART_CONTEXT -> {
|
||||
restarter.orElseThrow(() -> new AssertionError("Restart endpoint is not enabled"));
|
||||
yield new ConfigurationUpdateStrategy(strategyName, () -> {
|
||||
@@ -81,7 +81,7 @@ public class ConfigReloadAutoConfiguration {
|
||||
}
|
||||
|
||||
private static void wait(ConfigReloadProperties properties) {
|
||||
long waitMillis = ThreadLocalRandom.current().nextLong(properties.getMaxWaitForRestart().toMillis());
|
||||
long waitMillis = ThreadLocalRandom.current().nextLong(properties.maxWaitForRestart().toMillis());
|
||||
try {
|
||||
Thread.sleep(waitMillis);
|
||||
}
|
||||
|
||||
@@ -17,152 +17,51 @@
|
||||
package org.springframework.cloud.kubernetes.commons.config.reload;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.context.properties.bind.DefaultValue;
|
||||
|
||||
/**
|
||||
* General configuration for the configuration reload.
|
||||
* @param enabled Enables the Kubernetes configuration reload on change.
|
||||
* @param monitoringConfigMaps Enables monitoring on secrets to detect changes.
|
||||
* @param monitoringSecrets Monitor secrets or not.
|
||||
* @param strategy Sets reload strategy for Kubernetes configuration reload on change.
|
||||
* @param mode Sets the detection mode for Kubernetes configuration reload.
|
||||
* @param period Sets the polling period to use when the detection mode is POLLING.
|
||||
* @param namespaces namespaces where an informer will be set-up. this property is only
|
||||
* relevant for event based reloading.
|
||||
* @param enableReloadFiltering create an informer only for sources that have
|
||||
* 'spring.cloud.kubernetes.config.informer.enabled=true' label. This property is only
|
||||
* relevant for event based reloading.
|
||||
* @param maxWaitForRestart Restart or Shutdown strategies are used, Spring Cloud
|
||||
* Kubernetes waits a random amount of time before restarting. This is done in order to
|
||||
* avoid having all instances of the same application restart at the same time. This
|
||||
* property configures the maximum of amount of wait time from the moment the signal is
|
||||
* received that a restart is needed until the moment the restart is actually triggered
|
||||
*
|
||||
* @author Nicola Ferraro
|
||||
*/
|
||||
@ConfigurationProperties(prefix = "spring.cloud.kubernetes.reload")
|
||||
public class ConfigReloadProperties {
|
||||
public record ConfigReloadProperties(boolean enabled, @DefaultValue("true") boolean monitoringConfigMaps,
|
||||
boolean monitoringSecrets, @DefaultValue("REFRESH") ReloadStrategy strategy,
|
||||
@DefaultValue("EVENT") ReloadDetectionMode mode, @DefaultValue("15000ms") Duration period,
|
||||
@DefaultValue Set<String> namespaces, boolean enableReloadFiltering,
|
||||
@DefaultValue("2s") Duration maxWaitForRestart) {
|
||||
|
||||
/**
|
||||
* default instance.
|
||||
*/
|
||||
public static ConfigReloadProperties DEFAULT = new ConfigReloadProperties(false, true, false,
|
||||
ReloadStrategy.REFRESH, ReloadDetectionMode.EVENT, Duration.ofMillis(15000), Set.of(), false,
|
||||
Duration.ofSeconds(2));
|
||||
|
||||
/**
|
||||
* label for filtering sources.
|
||||
*/
|
||||
public static final String RELOAD_LABEL_FILTER = "spring.cloud.kubernetes.config.informer.enabled";
|
||||
|
||||
/**
|
||||
* Enables the Kubernetes configuration reload on change.
|
||||
*/
|
||||
private boolean enabled = false;
|
||||
|
||||
/**
|
||||
* Enables monitoring on config maps to detect changes.
|
||||
*/
|
||||
private boolean monitoringConfigMaps = true;
|
||||
|
||||
/**
|
||||
* Enables monitoring on secrets to detect changes.
|
||||
*/
|
||||
private boolean monitoringSecrets = false;
|
||||
|
||||
/**
|
||||
* Sets reload strategy for Kubernetes configuration reload on change.
|
||||
*/
|
||||
private ReloadStrategy strategy = ReloadStrategy.REFRESH;
|
||||
|
||||
/**
|
||||
* Sets the detection mode for Kubernetes configuration reload.
|
||||
*/
|
||||
private ReloadDetectionMode mode = ReloadDetectionMode.EVENT;
|
||||
|
||||
/**
|
||||
* Sets the polling period to use when the detection mode is POLLING.
|
||||
*/
|
||||
private Duration period = Duration.ofMillis(15000L);
|
||||
|
||||
/**
|
||||
* namespaces where an informer will be set-up. this property is only relevant for
|
||||
* event based reloading.
|
||||
*/
|
||||
private Set<String> namespaces = Collections.emptySet();
|
||||
|
||||
/**
|
||||
* create an informer only for sources that have
|
||||
* 'spring.cloud.kubernetes.config.informer.enabled=true' label. This property is only
|
||||
* relevant for event based reloading.
|
||||
*/
|
||||
private boolean enableReloadFiltering = false;
|
||||
|
||||
/**
|
||||
* If Restart or Shutdown strategies are used, Spring Cloud Kubernetes waits a random
|
||||
* amount of time before restarting. This is done in order to avoid having all
|
||||
* instances of the same application restart at the same time. This property
|
||||
* configures the maximum of amount of wait time from the moment the signal is
|
||||
* received that a restart is needed until the moment the restart is actually
|
||||
* triggered
|
||||
*/
|
||||
private Duration maxWaitForRestart = Duration.ofSeconds(2);
|
||||
|
||||
public ConfigReloadProperties() {
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public boolean isMonitoringConfigMaps() {
|
||||
return this.monitoringConfigMaps;
|
||||
}
|
||||
|
||||
public void setMonitoringConfigMaps(boolean monitoringConfigMaps) {
|
||||
this.monitoringConfigMaps = monitoringConfigMaps;
|
||||
}
|
||||
|
||||
public boolean isMonitoringSecrets() {
|
||||
return this.monitoringSecrets;
|
||||
}
|
||||
|
||||
public void setMonitoringSecrets(boolean monitoringSecrets) {
|
||||
this.monitoringSecrets = monitoringSecrets;
|
||||
}
|
||||
|
||||
public ReloadStrategy getStrategy() {
|
||||
return this.strategy;
|
||||
}
|
||||
|
||||
public void setStrategy(ReloadStrategy strategy) {
|
||||
this.strategy = strategy;
|
||||
}
|
||||
|
||||
public ReloadDetectionMode getMode() {
|
||||
return this.mode;
|
||||
}
|
||||
|
||||
public void setMode(ReloadDetectionMode mode) {
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
public Duration getPeriod() {
|
||||
return this.period;
|
||||
}
|
||||
|
||||
public void setPeriod(Duration period) {
|
||||
this.period = period;
|
||||
}
|
||||
|
||||
public Duration getMaxWaitForRestart() {
|
||||
return maxWaitForRestart;
|
||||
}
|
||||
|
||||
public void setMaxWaitForRestart(Duration maxWaitForRestart) {
|
||||
this.maxWaitForRestart = maxWaitForRestart;
|
||||
}
|
||||
|
||||
public Set<String> getNamespaces() {
|
||||
return namespaces;
|
||||
}
|
||||
|
||||
public void setNamespaces(Set<String> namespaces) {
|
||||
this.namespaces = namespaces;
|
||||
}
|
||||
|
||||
public boolean isEnableReloadFiltering() {
|
||||
return enableReloadFiltering;
|
||||
}
|
||||
|
||||
public void setEnableReloadFiltering(boolean enableReloadFiltering) {
|
||||
this.enableReloadFiltering = enableReloadFiltering;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reload strategies.
|
||||
*/
|
||||
|
||||
@@ -62,8 +62,8 @@ public class PollingConfigMapChangeDetector extends ConfigurationChangeDetector
|
||||
this.propertySourceLocator = propertySourceLocator;
|
||||
this.propertySourceClass = propertySourceClass;
|
||||
this.taskExecutor = taskExecutor;
|
||||
this.period = properties.getPeriod().toMillis();
|
||||
this.monitorConfigMaps = properties.isMonitoringConfigMaps();
|
||||
this.period = properties.period().toMillis();
|
||||
this.monitorConfigMaps = properties.monitoringConfigMaps();
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
|
||||
@@ -62,8 +62,8 @@ public class PollingSecretsChangeDetector extends ConfigurationChangeDetector {
|
||||
this.propertySourceLocator = propertySourceLocator;
|
||||
this.propertySourceClass = propertySourceClass;
|
||||
this.taskExecutor = taskExecutor;
|
||||
this.period = properties.getPeriod().toMillis();
|
||||
this.monitorSecrets = properties.isMonitoringSecrets();
|
||||
this.period = properties.period().toMillis();
|
||||
this.monitorSecrets = properties.monitoringSecrets();
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright 2013-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.kubernetes.commons.config;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.cloud.kubernetes.commons.config.reload.ConfigReloadProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author wind57
|
||||
*
|
||||
* Tests binding, since we moved from a class to a record
|
||||
*/
|
||||
class ConfigReloadPropertiesTests {
|
||||
|
||||
@Test
|
||||
void testDefaults() {
|
||||
new ApplicationContextRunner().withUserConfiguration(Config.class).run(context -> {
|
||||
ConfigReloadProperties properties = context.getBean(ConfigReloadProperties.class);
|
||||
Assertions.assertNotNull(properties);
|
||||
Assertions.assertFalse(properties.enabled());
|
||||
Assertions.assertTrue(properties.monitoringConfigMaps());
|
||||
Assertions.assertFalse(properties.monitoringSecrets());
|
||||
Assertions.assertEquals(ConfigReloadProperties.ReloadStrategy.REFRESH, properties.strategy());
|
||||
Assertions.assertEquals(ConfigReloadProperties.ReloadDetectionMode.EVENT, properties.mode());
|
||||
Assertions.assertEquals(Duration.ofMillis(15000), properties.period());
|
||||
Assertions.assertTrue(properties.namespaces().isEmpty());
|
||||
Assertions.assertEquals(Duration.ofSeconds(2), properties.maxWaitForRestart());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNonDefaults() {
|
||||
new ApplicationContextRunner().withUserConfiguration(Config.class)
|
||||
.withPropertyValues("spring.cloud.kubernetes.reload.enabled=true",
|
||||
"spring.cloud.kubernetes.reload.monitoring-config-maps=false",
|
||||
"spring.cloud.kubernetes.reload.monitoring-secrets=true",
|
||||
"spring.cloud.kubernetes.reload.strategy=SHUTDOWN",
|
||||
"spring.cloud.kubernetes.reload.mode=POLLING", "spring.cloud.kubernetes.reload.period=1000ms",
|
||||
"spring.cloud.kubernetes.reload.namespaces[0]=a",
|
||||
"spring.cloud.kubernetes.reload.namespaces[1]=b",
|
||||
"spring.cloud.kubernetes.reload.max-wait-for-restart=5s")
|
||||
.run(context -> {
|
||||
ConfigReloadProperties properties = context.getBean(ConfigReloadProperties.class);
|
||||
Assertions.assertNotNull(properties);
|
||||
Assertions.assertTrue(properties.enabled());
|
||||
Assertions.assertFalse(properties.monitoringConfigMaps());
|
||||
Assertions.assertTrue(properties.monitoringSecrets());
|
||||
Assertions.assertEquals(ConfigReloadProperties.ReloadStrategy.SHUTDOWN, properties.strategy());
|
||||
Assertions.assertEquals(ConfigReloadProperties.ReloadDetectionMode.POLLING, properties.mode());
|
||||
Assertions.assertEquals(Duration.ofMillis(1000), properties.period());
|
||||
Assertions.assertEquals(Set.of("a", "b"), properties.namespaces());
|
||||
Assertions.assertEquals(Duration.ofSeconds(5), properties.maxWaitForRestart());
|
||||
});
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(ConfigReloadProperties.class)
|
||||
static class Config {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.springframework.cloud.kubernetes.configuration.watcher;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import io.kubernetes.client.openapi.apis.CoreV1Api;
|
||||
import io.kubernetes.client.openapi.models.V1ConfigMap;
|
||||
import io.kubernetes.client.openapi.models.V1ObjectMeta;
|
||||
@@ -74,12 +72,10 @@ class BusEventBasedConfigMapWatcherChangeDetectorTests {
|
||||
void setup() {
|
||||
MockEnvironment mockEnvironment = new MockEnvironment();
|
||||
mockEnvironment.setProperty(NAMESPACE_PROPERTY, "default");
|
||||
ConfigReloadProperties configReloadProperties = new ConfigReloadProperties();
|
||||
configReloadProperties.setNamespaces(Set.of("default"));
|
||||
ConfigurationWatcherConfigurationProperties configurationWatcherConfigurationProperties = new ConfigurationWatcherConfigurationProperties();
|
||||
busProperties = new BusProperties();
|
||||
changeDetector = new BusEventBasedConfigMapWatcherChangeDetector(coreV1Api, mockEnvironment,
|
||||
configReloadProperties, UPDATE_STRATEGY, configMapPropertySourceLocator,
|
||||
ConfigReloadProperties.DEFAULT, UPDATE_STRATEGY, configMapPropertySourceLocator,
|
||||
new KubernetesNamespaceProvider(mockEnvironment), configurationWatcherConfigurationProperties,
|
||||
threadPoolTaskExecutor, new BusRefreshTrigger(applicationEventPublisher, busProperties.getId()));
|
||||
}
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.springframework.cloud.kubernetes.configuration.watcher;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import io.kubernetes.client.openapi.apis.CoreV1Api;
|
||||
import io.kubernetes.client.openapi.models.V1ObjectMeta;
|
||||
import io.kubernetes.client.openapi.models.V1Secret;
|
||||
@@ -74,12 +72,10 @@ class BusEventBasedSecretsWatcherChangeDetectorTests {
|
||||
void setup() {
|
||||
MockEnvironment mockEnvironment = new MockEnvironment();
|
||||
mockEnvironment.setProperty(NAMESPACE_PROPERTY, "default");
|
||||
ConfigReloadProperties configReloadProperties = new ConfigReloadProperties();
|
||||
configReloadProperties.setNamespaces(Set.of("default"));
|
||||
ConfigurationWatcherConfigurationProperties configurationWatcherConfigurationProperties = new ConfigurationWatcherConfigurationProperties();
|
||||
busProperties = new BusProperties();
|
||||
changeDetector = new BusEventBasedSecretsWatcherChangeDetector(coreV1Api, mockEnvironment,
|
||||
configReloadProperties, UPDATE_STRATEGY, secretsPropertySourceLocator,
|
||||
ConfigReloadProperties.DEFAULT, UPDATE_STRATEGY, secretsPropertySourceLocator,
|
||||
new KubernetesNamespaceProvider(mockEnvironment), configurationWatcherConfigurationProperties,
|
||||
threadPoolTaskExecutor, new BusRefreshTrigger(applicationEventPublisher, busProperties.getId()));
|
||||
}
|
||||
|
||||
@@ -104,7 +104,6 @@ class HttpBasedConfigMapWatchChangeDetectorTests {
|
||||
|
||||
MockEnvironment mockEnvironment = new MockEnvironment();
|
||||
mockEnvironment.setProperty(NAMESPACE_PROPERTY, "default");
|
||||
ConfigReloadProperties configReloadProperties = new ConfigReloadProperties();
|
||||
configurationWatcherConfigurationProperties = new ConfigurationWatcherConfigurationProperties();
|
||||
WebClient webClient = WebClient.builder().build();
|
||||
|
||||
@@ -112,10 +111,11 @@ class HttpBasedConfigMapWatchChangeDetectorTests {
|
||||
|
||||
});
|
||||
|
||||
changeDetector = new HttpBasedConfigMapWatchChangeDetector(coreV1Api, mockEnvironment, configReloadProperties,
|
||||
strategy, configMapPropertySourceLocator, new KubernetesNamespaceProvider(mockEnvironment),
|
||||
configurationWatcherConfigurationProperties, threadPoolTaskExecutor, new HttpRefreshTrigger(
|
||||
reactiveDiscoveryClient, configurationWatcherConfigurationProperties, webClient));
|
||||
changeDetector = new HttpBasedConfigMapWatchChangeDetector(coreV1Api, mockEnvironment,
|
||||
ConfigReloadProperties.DEFAULT, strategy, configMapPropertySourceLocator,
|
||||
new KubernetesNamespaceProvider(mockEnvironment), configurationWatcherConfigurationProperties,
|
||||
threadPoolTaskExecutor, new HttpRefreshTrigger(reactiveDiscoveryClient,
|
||||
configurationWatcherConfigurationProperties, webClient));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -93,13 +93,13 @@ class HttpBasedSecretsWatchChangeDetectorTests {
|
||||
void setup() {
|
||||
MockEnvironment mockEnvironment = new MockEnvironment();
|
||||
mockEnvironment.setProperty(NAMESPACE_PROPERTY, "default");
|
||||
ConfigReloadProperties configReloadProperties = new ConfigReloadProperties();
|
||||
configurationWatcherConfigurationProperties = new ConfigurationWatcherConfigurationProperties();
|
||||
WebClient webClient = WebClient.builder().build();
|
||||
changeDetector = new HttpBasedSecretsWatchChangeDetector(coreV1Api, mockEnvironment, configReloadProperties,
|
||||
updateStrategy, secretsPropertySourceLocator, new KubernetesNamespaceProvider(mockEnvironment),
|
||||
configurationWatcherConfigurationProperties, threadPoolTaskExecutor, new HttpRefreshTrigger(
|
||||
reactiveDiscoveryClient, configurationWatcherConfigurationProperties, webClient));
|
||||
changeDetector = new HttpBasedSecretsWatchChangeDetector(coreV1Api, mockEnvironment,
|
||||
ConfigReloadProperties.DEFAULT, updateStrategy, secretsPropertySourceLocator,
|
||||
new KubernetesNamespaceProvider(mockEnvironment), configurationWatcherConfigurationProperties,
|
||||
threadPoolTaskExecutor, new HttpRefreshTrigger(reactiveDiscoveryClient,
|
||||
configurationWatcherConfigurationProperties, webClient));
|
||||
}
|
||||
|
||||
@BeforeAll
|
||||
|
||||
@@ -54,7 +54,7 @@ public final class Fabric8ConfigUtils {
|
||||
*/
|
||||
public static Set<String> namespaces(KubernetesClient client, KubernetesNamespaceProvider provider,
|
||||
ConfigReloadProperties properties, String target) {
|
||||
Set<String> namespaces = properties.getNamespaces();
|
||||
Set<String> namespaces = properties.namespaces();
|
||||
if (namespaces.isEmpty()) {
|
||||
namespaces = Set.of(getApplicationNamespace(client, null, target, provider));
|
||||
}
|
||||
|
||||
@@ -74,8 +74,8 @@ public class Fabric8EventBasedConfigMapChangeDetector extends ConfigurationChang
|
||||
super(environment, properties, strategy);
|
||||
this.kubernetesClient = kubernetesClient;
|
||||
this.fabric8ConfigMapPropertySourceLocator = fabric8ConfigMapPropertySourceLocator;
|
||||
this.enableReloadFiltering = properties.isEnableReloadFiltering();
|
||||
monitoringConfigMaps = properties.isMonitoringConfigMaps();
|
||||
this.enableReloadFiltering = properties.enableReloadFiltering();
|
||||
monitoringConfigMaps = properties.monitoringConfigMaps();
|
||||
namespaces = namespaces(kubernetesClient, namespaceProvider, properties, "configmap");
|
||||
}
|
||||
|
||||
|
||||
@@ -74,8 +74,8 @@ public class Fabric8EventBasedSecretsChangeDetector extends ConfigurationChangeD
|
||||
super(environment, properties, strategy);
|
||||
this.kubernetesClient = kubernetesClient;
|
||||
this.fabric8SecretsPropertySourceLocator = fabric8SecretsPropertySourceLocator;
|
||||
this.enableReloadFiltering = properties.isEnableReloadFiltering();
|
||||
monitorSecrets = properties.isMonitoringSecrets();
|
||||
this.enableReloadFiltering = properties.enableReloadFiltering();
|
||||
monitorSecrets = properties.monitoringSecrets();
|
||||
namespaces = namespaces(kubernetesClient, namespaceProvider, properties, "secrets");
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.cloud.kubernetes.fabric8.config;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Base64;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Map;
|
||||
@@ -350,8 +351,9 @@ class Fabric8ConfigUtilsTests {
|
||||
|
||||
@Test
|
||||
void testNamespacesFromProperties() {
|
||||
ConfigReloadProperties configReloadProperties = new ConfigReloadProperties();
|
||||
configReloadProperties.setNamespaces(Set.of("non-default"));
|
||||
ConfigReloadProperties configReloadProperties = new ConfigReloadProperties(false, true, false,
|
||||
ConfigReloadProperties.ReloadStrategy.REFRESH, ConfigReloadProperties.ReloadDetectionMode.EVENT,
|
||||
Duration.ofMillis(15000), Set.of("non-default"), false, Duration.ofSeconds(2));
|
||||
Set<String> namespaces = Fabric8ConfigUtils.namespaces(null,
|
||||
new KubernetesNamespaceProvider(new MockEnvironment()), configReloadProperties, "configmap");
|
||||
Assertions.assertEquals(1, namespaces.size());
|
||||
@@ -360,11 +362,11 @@ class Fabric8ConfigUtilsTests {
|
||||
|
||||
@Test
|
||||
void testNamespacesFromProvider() {
|
||||
ConfigReloadProperties configReloadProperties = new ConfigReloadProperties();
|
||||
MockEnvironment environment = new MockEnvironment();
|
||||
environment.setProperty("spring.cloud.kubernetes.client.namespace", "some");
|
||||
KubernetesNamespaceProvider provider = new KubernetesNamespaceProvider(environment);
|
||||
Set<String> namespaces = Fabric8ConfigUtils.namespaces(null, provider, configReloadProperties, "configmap");
|
||||
Set<String> namespaces = Fabric8ConfigUtils.namespaces(null, provider, ConfigReloadProperties.DEFAULT,
|
||||
"configmap");
|
||||
Assertions.assertEquals(1, namespaces.size());
|
||||
Assertions.assertEquals(namespaces.iterator().next(), "some");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user