From 6a17062d4d67cf4c34382e14060222d87bb19c07 Mon Sep 17 00:00:00 2001 From: wind57 Date: Thu, 9 Apr 2026 15:31:28 +0300 Subject: [PATCH 1/2] 2208: added basic properties Signed-off-by: wind57 --- .../config/reload/ConfigReloadProperties.java | 48 +++++++++++++-- .../config/ConfigReloadPropertiesTests.java | 58 ++++++++++++------- 2 files changed, 81 insertions(+), 25 deletions(-) diff --git a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/reload/ConfigReloadProperties.java b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/reload/ConfigReloadProperties.java index ac04ba1b2d..8fd85f0c11 100644 --- a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/reload/ConfigReloadProperties.java +++ b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/reload/ConfigReloadProperties.java @@ -17,9 +17,11 @@ package org.springframework.cloud.kubernetes.commons.config.reload; import java.time.Duration; +import java.util.Map; import java.util.Set; import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.context.properties.bind.ConstructorBinding; import org.springframework.boot.context.properties.bind.DefaultValue; /** @@ -27,7 +29,9 @@ * * @param enabled Enables the Kubernetes configuration reload on change. * @param monitoringConfigMaps Enables monitoring on secrets to detect changes. + * @param configMapsLabels Labels for which to watch config maps. * @param monitoringSecrets Monitor secrets or not. + * @param secretsLabels Labels for which to watch secrets for. * @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. @@ -44,17 +48,53 @@ * @author Nicola Ferraro */ @ConfigurationProperties(prefix = "spring.cloud.kubernetes.reload") -public record ConfigReloadProperties(boolean enabled, @DefaultValue("true") boolean monitoringConfigMaps, - boolean monitoringSecrets, @DefaultValue("REFRESH") ReloadStrategy strategy, +public record ConfigReloadProperties(boolean enabled, boolean monitoringConfigMaps, + Map configMapsLabels, + boolean monitoringSecrets, Map secretsLabels, + ReloadStrategy strategy, + ReloadDetectionMode mode, Duration period, + Set namespaces, boolean enableReloadFiltering, + Duration maxWaitForRestart) { + + @ConstructorBinding + public ConfigReloadProperties(boolean enabled, @DefaultValue("true") boolean monitoringConfigMaps, + @DefaultValue Map configMapsLabels, + boolean monitoringSecrets, @DefaultValue Map secretsLabels, + @DefaultValue("REFRESH") ReloadStrategy strategy, @DefaultValue("EVENT") ReloadDetectionMode mode, @DefaultValue("15000ms") Duration period, @DefaultValue Set namespaces, boolean enableReloadFiltering, @DefaultValue("2s") Duration maxWaitForRestart) { + this.enabled = enabled; + this.monitoringConfigMaps = monitoringConfigMaps; + this.configMapsLabels = configMapsLabels; + this.monitoringSecrets = monitoringSecrets; + this.secretsLabels = secretsLabels; + this.strategy = strategy; + this.mode = mode; + this.period = period; + this.namespaces = namespaces; + this.enableReloadFiltering = enableReloadFiltering; + this.maxWaitForRestart = maxWaitForRestart; + } + + @Deprecated(forRemoval = true) + public ConfigReloadProperties(boolean enabled, @DefaultValue("true") boolean monitoringConfigMaps, + boolean monitoringSecrets, + @DefaultValue("REFRESH") ReloadStrategy strategy, + @DefaultValue("EVENT") ReloadDetectionMode mode, @DefaultValue("15000ms") Duration period, + @DefaultValue Set namespaces, boolean enableReloadFiltering, + @DefaultValue("2s") Duration maxWaitForRestart) { + + this(enabled, monitoringConfigMaps, Map.of(), monitoringSecrets, Map.of(), + strategy, mode, period, namespaces, enableReloadFiltering, maxWaitForRestart); + } + /** * default instance. */ - public static ConfigReloadProperties DEFAULT = new ConfigReloadProperties(false, true, false, - ReloadStrategy.REFRESH, ReloadDetectionMode.EVENT, Duration.ofMillis(15000), Set.of(), false, + public static final ConfigReloadProperties DEFAULT = new ConfigReloadProperties(false, true, Map.of(), false, + Map.of(), ReloadStrategy.REFRESH, ReloadDetectionMode.EVENT, Duration.ofMillis(15000), Set.of(), false, Duration.ofSeconds(2)); /** diff --git a/spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/config/ConfigReloadPropertiesTests.java b/spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/config/ConfigReloadPropertiesTests.java index 63120f0814..43d5b50863 100644 --- a/spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/config/ConfigReloadPropertiesTests.java +++ b/spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/config/ConfigReloadPropertiesTests.java @@ -17,6 +17,7 @@ package org.springframework.cloud.kubernetes.commons.config; import java.time.Duration; +import java.util.Map; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; @@ -26,26 +27,35 @@ import org.springframework.cloud.kubernetes.commons.config.reload.ConfigReloadProperties; import org.springframework.context.annotation.Configuration; +import static org.assertj.core.api.Assertions.assertThat; + /** * @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.assertThat(properties).isNotNull(); - Assertions.assertThat(properties.enabled()).isFalse(); - Assertions.assertThat(properties.monitoringConfigMaps()).isTrue(); - Assertions.assertThat(properties.monitoringSecrets()).isFalse(); - Assertions.assertThat(ConfigReloadProperties.ReloadStrategy.REFRESH).isEqualTo(properties.strategy()); - Assertions.assertThat(ConfigReloadProperties.ReloadDetectionMode.EVENT).isEqualTo(properties.mode()); - Assertions.assertThat(Duration.ofMillis(15000)).isEqualTo(properties.period()); - Assertions.assertThat(properties.namespaces().isEmpty()).isTrue(); - Assertions.assertThat(Duration.ofSeconds(2)).isEqualTo(properties.maxWaitForRestart()); + ConfigReloadProperties properties = null; + try { + properties = context.getBean(ConfigReloadProperties.class); + } catch(Exception e) { + e.printStackTrace(); + context.getStartupFailure().printStackTrace(); + } + assertThat(properties).isNotNull(); + assertThat(properties.enabled()).isFalse(); + assertThat(properties.monitoringConfigMaps()).isTrue(); + assertThat(properties.configMapsLabels()).isEmpty(); + assertThat(properties.monitoringSecrets()).isFalse(); + assertThat(properties.secretsLabels()).isEmpty(); + assertThat(ConfigReloadProperties.ReloadStrategy.REFRESH).isEqualTo(properties.strategy()); + assertThat(ConfigReloadProperties.ReloadDetectionMode.EVENT).isEqualTo(properties.mode()); + assertThat(Duration.ofMillis(15000)).isEqualTo(properties.period()); + assertThat(properties.namespaces().isEmpty()).isTrue(); + assertThat(properties.enableReloadFiltering()).isFalse(); + assertThat(Duration.ofSeconds(2)).isEqualTo(properties.maxWaitForRestart()); }); } @@ -54,22 +64,28 @@ 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.config-maps-labels[aa]=bb", "spring.cloud.kubernetes.reload.monitoring-secrets=true", + "spring.cloud.kubernetes.reload.secrets-labels[cc]=dd", "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.enable-reload-filtering=true", "spring.cloud.kubernetes.reload.max-wait-for-restart=5s") .run(context -> { ConfigReloadProperties properties = context.getBean(ConfigReloadProperties.class); - Assertions.assertThat(properties).isNotNull(); - Assertions.assertThat(properties.enabled()).isTrue(); - Assertions.assertThat(properties.monitoringConfigMaps()).isFalse(); - Assertions.assertThat(properties.monitoringSecrets()).isTrue(); - Assertions.assertThat(ConfigReloadProperties.ReloadStrategy.SHUTDOWN).isEqualTo(properties.strategy()); - Assertions.assertThat(ConfigReloadProperties.ReloadDetectionMode.POLLING).isEqualTo(properties.mode()); - Assertions.assertThat(Duration.ofMillis(1000)).isEqualTo(properties.period()); - Assertions.assertThat(properties.namespaces()).containsExactlyInAnyOrder("a", "b"); - Assertions.assertThat(Duration.ofSeconds(5)).isEqualTo(properties.maxWaitForRestart()); + assertThat(properties).isNotNull(); + assertThat(properties.enabled()).isTrue(); + assertThat(properties.monitoringConfigMaps()).isFalse(); + assertThat(properties.configMapsLabels()).containsExactlyInAnyOrderEntriesOf(Map.of("aa", "bb")); + assertThat(properties.monitoringSecrets()).isTrue(); + assertThat(properties.secretsLabels()).containsExactlyInAnyOrderEntriesOf(Map.of("cc", "dd")); + assertThat(ConfigReloadProperties.ReloadStrategy.SHUTDOWN).isEqualTo(properties.strategy()); + assertThat(ConfigReloadProperties.ReloadDetectionMode.POLLING).isEqualTo(properties.mode()); + assertThat(Duration.ofMillis(1000)).isEqualTo(properties.period()); + assertThat(properties.namespaces()).containsExactlyInAnyOrder("a", "b"); + assertThat(properties.enableReloadFiltering()).isTrue(); + assertThat(Duration.ofSeconds(5)).isEqualTo(properties.maxWaitForRestart()); }); } From ba0288cf6d8482fef5ec99108c31a5fa29e9182d Mon Sep 17 00:00:00 2001 From: wind57 Date: Thu, 9 Apr 2026 15:38:20 +0300 Subject: [PATCH 2/2] 2208: breaking changes Signed-off-by: wind57 --- .../config/reload/ConfigReloadProperties.java | 44 ++----------------- .../config/ConfigReloadPropertiesTests.java | 4 -- 2 files changed, 3 insertions(+), 45 deletions(-) diff --git a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/reload/ConfigReloadProperties.java b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/reload/ConfigReloadProperties.java index 8fd85f0c11..0141c3c967 100644 --- a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/reload/ConfigReloadProperties.java +++ b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/reload/ConfigReloadProperties.java @@ -21,7 +21,6 @@ import java.util.Set; import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.boot.context.properties.bind.ConstructorBinding; import org.springframework.boot.context.properties.bind.DefaultValue; /** @@ -37,9 +36,6 @@ * @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 @@ -48,53 +44,19 @@ * @author Nicola Ferraro */ @ConfigurationProperties(prefix = "spring.cloud.kubernetes.reload") -public record ConfigReloadProperties(boolean enabled, boolean monitoringConfigMaps, - Map configMapsLabels, - boolean monitoringSecrets, Map secretsLabels, - ReloadStrategy strategy, - ReloadDetectionMode mode, Duration period, - Set namespaces, boolean enableReloadFiltering, - Duration maxWaitForRestart) { - - @ConstructorBinding - public ConfigReloadProperties(boolean enabled, @DefaultValue("true") boolean monitoringConfigMaps, +public record ConfigReloadProperties(boolean enabled, @DefaultValue("true") boolean monitoringConfigMaps, @DefaultValue Map configMapsLabels, boolean monitoringSecrets, @DefaultValue Map secretsLabels, @DefaultValue("REFRESH") ReloadStrategy strategy, @DefaultValue("EVENT") ReloadDetectionMode mode, @DefaultValue("15000ms") Duration period, - @DefaultValue Set namespaces, boolean enableReloadFiltering, + @DefaultValue Set namespaces, @DefaultValue("2s") Duration maxWaitForRestart) { - this.enabled = enabled; - this.monitoringConfigMaps = monitoringConfigMaps; - this.configMapsLabels = configMapsLabels; - this.monitoringSecrets = monitoringSecrets; - this.secretsLabels = secretsLabels; - this.strategy = strategy; - this.mode = mode; - this.period = period; - this.namespaces = namespaces; - this.enableReloadFiltering = enableReloadFiltering; - this.maxWaitForRestart = maxWaitForRestart; - } - - @Deprecated(forRemoval = true) - public ConfigReloadProperties(boolean enabled, @DefaultValue("true") boolean monitoringConfigMaps, - boolean monitoringSecrets, - @DefaultValue("REFRESH") ReloadStrategy strategy, - @DefaultValue("EVENT") ReloadDetectionMode mode, @DefaultValue("15000ms") Duration period, - @DefaultValue Set namespaces, boolean enableReloadFiltering, - @DefaultValue("2s") Duration maxWaitForRestart) { - - this(enabled, monitoringConfigMaps, Map.of(), monitoringSecrets, Map.of(), - strategy, mode, period, namespaces, enableReloadFiltering, maxWaitForRestart); - } - /** * default instance. */ public static final ConfigReloadProperties DEFAULT = new ConfigReloadProperties(false, true, Map.of(), false, - Map.of(), ReloadStrategy.REFRESH, ReloadDetectionMode.EVENT, Duration.ofMillis(15000), Set.of(), false, + Map.of(), ReloadStrategy.REFRESH, ReloadDetectionMode.EVENT, Duration.ofMillis(15000), Set.of(), Duration.ofSeconds(2)); /** diff --git a/spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/config/ConfigReloadPropertiesTests.java b/spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/config/ConfigReloadPropertiesTests.java index 43d5b50863..63abc13eb7 100644 --- a/spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/config/ConfigReloadPropertiesTests.java +++ b/spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/config/ConfigReloadPropertiesTests.java @@ -19,7 +19,6 @@ import java.time.Duration; import java.util.Map; -import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import org.springframework.boot.context.properties.EnableConfigurationProperties; @@ -54,7 +53,6 @@ void testDefaults() { assertThat(ConfigReloadProperties.ReloadDetectionMode.EVENT).isEqualTo(properties.mode()); assertThat(Duration.ofMillis(15000)).isEqualTo(properties.period()); assertThat(properties.namespaces().isEmpty()).isTrue(); - assertThat(properties.enableReloadFiltering()).isFalse(); assertThat(Duration.ofSeconds(2)).isEqualTo(properties.maxWaitForRestart()); }); } @@ -70,7 +68,6 @@ void testNonDefaults() { "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.enable-reload-filtering=true", "spring.cloud.kubernetes.reload.max-wait-for-restart=5s") .run(context -> { ConfigReloadProperties properties = context.getBean(ConfigReloadProperties.class); @@ -84,7 +81,6 @@ void testNonDefaults() { assertThat(ConfigReloadProperties.ReloadDetectionMode.POLLING).isEqualTo(properties.mode()); assertThat(Duration.ofMillis(1000)).isEqualTo(properties.period()); assertThat(properties.namespaces()).containsExactlyInAnyOrder("a", "b"); - assertThat(properties.enableReloadFiltering()).isTrue(); assertThat(Duration.ofSeconds(5)).isEqualTo(properties.maxWaitForRestart()); }); }