From 9bd74ed997e101d1b626b8acc1d4b1c7b6174105 Mon Sep 17 00:00:00 2001 From: wind57 Date: Tue, 7 Oct 2025 14:27:02 +0300 Subject: [PATCH 1/5] first draft Signed-off-by: wind57 --- .../config/CommonPropertySourceLocator.java | 85 +++++++++++++++++++ ...tryableConfigMapPropertySourceLocator.java | 6 +- ...RetryableSecretsPropertySourceLocator.java | 3 +- .../ConfigMapPropertySourceLocator.java | 57 +------------ .../config/SecretsPropertySourceLocator.java | 55 +----------- 5 files changed, 96 insertions(+), 110 deletions(-) create mode 100644 spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/CommonPropertySourceLocator.java diff --git a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/CommonPropertySourceLocator.java b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/CommonPropertySourceLocator.java new file mode 100644 index 0000000000..25dd35fe5f --- /dev/null +++ b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/CommonPropertySourceLocator.java @@ -0,0 +1,85 @@ +/* + * Copyright 2013-present 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.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.apache.commons.logging.LogFactory; + +import org.springframework.cloud.bootstrap.config.PropertySourceLocator; +import org.springframework.core.env.CompositePropertySource; +import org.springframework.core.env.ConfigurableEnvironment; +import org.springframework.core.env.Environment; +import org.springframework.core.env.MapPropertySource; +import org.springframework.core.env.PropertySource; +import org.springframework.core.log.LogAccessor; + +/** + * @author wind57 + */ +abstract class CommonPropertySourceLocator implements PropertySourceLocator { + + private static final LogAccessor LOG = new LogAccessor(LogFactory.getLog(CommonPropertySourceLocator.class)); + + protected final SourceConfigProperties properties; + + private final String type; + + CommonPropertySourceLocator(SourceConfigProperties properties, String type) { + this.properties = properties; + this.type = type; + } + + protected abstract MapPropertySource getPropertySource(ConfigurableEnvironment environment, + NormalizedSource normalizedSource, ReadType readType); + + @Override + public PropertySource locate(Environment environment) { + + if (environment instanceof ConfigurableEnvironment env) { + + List sources = properties.determineSources(false, environment); + Set uniqueSources = new HashSet<>(sources); + LOG.debug(type + " normalized sources : " + uniqueSources); + CompositePropertySource composite = new CompositePropertySource("composite-" + type); + + uniqueSources.forEach(secretSource -> { + MapPropertySource propertySource = getPropertySource(env, secretSource, properties.readType()); + + if ("true".equals(propertySource.getProperty(Constants.ERROR_PROPERTY))) { + LOG.warn(() -> "Failed to load source: " + secretSource); + } + else { + LOG.debug("Adding " + type + " property source " + propertySource.getName()); + composite.addFirstPropertySource(propertySource); + } + }); + + return composite; + } + return null; + } + + @Override + public Collection> locateCollection(Environment environment) { + return PropertySourceLocator.super.locateCollection(environment); + } + +} diff --git a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/ConfigDataRetryableConfigMapPropertySourceLocator.java b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/ConfigDataRetryableConfigMapPropertySourceLocator.java index 288636c301..4ca82f5c34 100644 --- a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/ConfigDataRetryableConfigMapPropertySourceLocator.java +++ b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/ConfigDataRetryableConfigMapPropertySourceLocator.java @@ -47,9 +47,9 @@ public ConfigDataRetryableConfigMapPropertySourceLocator( } @Override - protected MapPropertySource getMapPropertySource(NormalizedSource normalizedSource, - ConfigurableEnvironment environment, ReadType readType) { - return configMapPropertySourceLocator.getMapPropertySource(normalizedSource, environment, readType); + protected MapPropertySource getPropertySource(ConfigurableEnvironment environment, + NormalizedSource normalizedSource, ReadType readType) { + return configMapPropertySourceLocator.getPropertySource(environment, normalizedSource, readType); } @Override diff --git a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/ConfigDataRetryableSecretsPropertySourceLocator.java b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/ConfigDataRetryableSecretsPropertySourceLocator.java index 06227f4b17..c96d01b4b3 100644 --- a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/ConfigDataRetryableSecretsPropertySourceLocator.java +++ b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/ConfigDataRetryableSecretsPropertySourceLocator.java @@ -20,6 +20,7 @@ import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.Environment; +import org.springframework.core.env.MapPropertySource; import org.springframework.core.env.PropertySource; import org.springframework.retry.support.RetryTemplate; @@ -56,7 +57,7 @@ public Collection> locateCollection(Environment environment) { } @Override - protected SecretsPropertySource getPropertySource(ConfigurableEnvironment environment, + protected MapPropertySource getPropertySource(ConfigurableEnvironment environment, NormalizedSource normalizedSource, ReadType readType) { return this.secretsPropertySourceLocator.getPropertySource(environment, normalizedSource, readType); } diff --git a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/ConfigMapPropertySourceLocator.java b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/ConfigMapPropertySourceLocator.java index 23b900751b..30181fb60d 100644 --- a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/ConfigMapPropertySourceLocator.java +++ b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/ConfigMapPropertySourceLocator.java @@ -16,66 +16,17 @@ package org.springframework.cloud.kubernetes.commons.config; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.Set; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import org.springframework.cloud.bootstrap.config.PropertySourceLocator; -import org.springframework.core.env.CompositePropertySource; -import org.springframework.core.env.ConfigurableEnvironment; -import org.springframework.core.env.Environment; -import org.springframework.core.env.MapPropertySource; -import org.springframework.core.env.PropertySource; - /** - * A {@link PropertySourceLocator} that uses config maps. + * A PropertySourceLocator that uses config maps. * * @author Ioannis Canellos * @author Michael Moudatsos * @author Isik Erhan */ -public abstract class ConfigMapPropertySourceLocator implements PropertySourceLocator { - - private static final Log LOG = LogFactory.getLog(ConfigMapPropertySourceLocator.class); - - protected final ConfigMapConfigProperties properties; - - public ConfigMapPropertySourceLocator(ConfigMapConfigProperties properties) { - this.properties = properties; - } - - protected abstract MapPropertySource getMapPropertySource(NormalizedSource normalizedSource, - ConfigurableEnvironment environment, ReadType readType); - - @Override - public PropertySource locate(Environment environment) { - if (environment instanceof ConfigurableEnvironment env) { - - CompositePropertySource composite = new CompositePropertySource("composite-configmap"); - Set sources = new LinkedHashSet<>(this.properties.determineSources(true, environment)); - LOG.debug("Config Map normalized sources : " + sources); - sources.forEach(configMapSource -> { - MapPropertySource propertySource = getMapPropertySource(configMapSource, env, properties.readType()); - if ("true".equals(propertySource.getProperty(Constants.ERROR_PROPERTY))) { - LOG.warn("Failed to load source: " + configMapSource); - } - else { - LOG.debug("Adding config map property source " + propertySource.getName()); - composite.addFirstPropertySource(propertySource); - } - }); - - return composite; - } - return null; - } +public abstract class ConfigMapPropertySourceLocator extends CommonPropertySourceLocator { - @Override - public Collection> locateCollection(Environment environment) { - return PropertySourceLocator.super.locateCollection(environment); + public ConfigMapPropertySourceLocator(ConfigMapConfigProperties configMapConfigProperties) { + super(configMapConfigProperties, "configmaps"); } } diff --git a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/SecretsPropertySourceLocator.java b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/SecretsPropertySourceLocator.java index cf2a745b8b..fbd92ff593 100644 --- a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/SecretsPropertySourceLocator.java +++ b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/SecretsPropertySourceLocator.java @@ -16,20 +16,7 @@ package org.springframework.cloud.kubernetes.commons.config; -import java.util.Collection; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - import org.springframework.cloud.bootstrap.config.PropertySourceLocator; -import org.springframework.core.env.CompositePropertySource; -import org.springframework.core.env.ConfigurableEnvironment; -import org.springframework.core.env.Environment; -import org.springframework.core.env.MapPropertySource; -import org.springframework.core.env.PropertySource; /** * Kubernetes {@link PropertySourceLocator} for secrets. @@ -39,48 +26,10 @@ * @author wind57 * @author Isik Erhan */ -public abstract class SecretsPropertySourceLocator implements PropertySourceLocator { - - private static final Log LOG = LogFactory.getLog(SecretsPropertySourceLocator.class); - - protected final SecretsConfigProperties properties; +public abstract class SecretsPropertySourceLocator extends CommonPropertySourceLocator { public SecretsPropertySourceLocator(SecretsConfigProperties properties) { - this.properties = properties; - } - - protected abstract SecretsPropertySource getPropertySource(ConfigurableEnvironment environment, - NormalizedSource normalizedSource, ReadType readType); - - @Override - public PropertySource locate(Environment environment) { - if (environment instanceof ConfigurableEnvironment env) { - - List sources = this.properties.determineSources(false, environment); - Set uniqueSources = new HashSet<>(sources); - LOG.debug("Secrets normalized sources : " + sources); - CompositePropertySource composite = new CompositePropertySource("composite-secrets"); - - uniqueSources.forEach(secretSource -> { - MapPropertySource propertySource = getPropertySource(env, secretSource, properties.readType()); - - if ("true".equals(propertySource.getProperty(Constants.ERROR_PROPERTY))) { - LOG.warn("Failed to load source: " + secretSource); - } - else { - LOG.debug("Adding secret property source " + propertySource.getName()); - composite.addFirstPropertySource(propertySource); - } - }); - - return composite; - } - return null; - } - - @Override - public Collection> locateCollection(Environment environment) { - return PropertySourceLocator.super.locateCollection(environment); + super(properties, "secrets"); } } From bb0c35d5537fbfb92245e8d1e4c6c8a412744563 Mon Sep 17 00:00:00 2001 From: wind57 Date: Tue, 7 Oct 2025 14:57:20 +0300 Subject: [PATCH 2/5] first draft Signed-off-by: wind57 --- ...sClientConfigMapPropertySourceLocator.java | 2 +- .../config/CommonPropertySourceLocator.java | 17 +++++----- .../ConfigMapPropertySourceLocator.java | 2 +- .../config/SecretsPropertySourceLocator.java | 2 +- .../config/SourceConfigProperties.java | 20 ++++++------ .../kubernetes/commons/config/SourceType.java | 31 +++++++++++++++++++ .../ConfigMapConfigPropertiesTests.java | 18 +++++------ .../config/SecretsConfigPropertiesTests.java | 16 +++++----- ...Fabric8ConfigMapPropertySourceLocator.java | 4 +-- ...nfigMapPropertySourceLocatorMockTests.java | 2 +- 10 files changed, 73 insertions(+), 41 deletions(-) create mode 100644 spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/SourceType.java diff --git a/spring-cloud-kubernetes-client-config/src/main/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientConfigMapPropertySourceLocator.java b/spring-cloud-kubernetes-client-config/src/main/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientConfigMapPropertySourceLocator.java index 1949c3522f..a9f7c0b019 100644 --- a/spring-cloud-kubernetes-client-config/src/main/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientConfigMapPropertySourceLocator.java +++ b/spring-cloud-kubernetes-client-config/src/main/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientConfigMapPropertySourceLocator.java @@ -57,7 +57,7 @@ public PropertySource locate(Environment environment) { } @Override - protected MapPropertySource getMapPropertySource(NormalizedSource source, ConfigurableEnvironment environment, + protected MapPropertySource getPropertySource(ConfigurableEnvironment environment, NormalizedSource source, ReadType readType) { String normalizedNamespace = source.namespace().orElse(null); diff --git a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/CommonPropertySourceLocator.java b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/CommonPropertySourceLocator.java index 25dd35fe5f..38f3b06e50 100644 --- a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/CommonPropertySourceLocator.java +++ b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/CommonPropertySourceLocator.java @@ -19,6 +19,7 @@ import java.util.Collection; import java.util.HashSet; import java.util.List; +import java.util.Locale; import java.util.Set; import org.apache.commons.logging.LogFactory; @@ -40,11 +41,11 @@ abstract class CommonPropertySourceLocator implements PropertySourceLocator { protected final SourceConfigProperties properties; - private final String type; + private final SourceType sourceType; - CommonPropertySourceLocator(SourceConfigProperties properties, String type) { + CommonPropertySourceLocator(SourceConfigProperties properties, SourceType sourceType) { this.properties = properties; - this.type = type; + this.sourceType = sourceType; } protected abstract MapPropertySource getPropertySource(ConfigurableEnvironment environment, @@ -55,10 +56,11 @@ public PropertySource locate(Environment environment) { if (environment instanceof ConfigurableEnvironment env) { - List sources = properties.determineSources(false, environment); + List sources = properties.determineSources(sourceType, environment); Set uniqueSources = new HashSet<>(sources); - LOG.debug(type + " normalized sources : " + uniqueSources); - CompositePropertySource composite = new CompositePropertySource("composite-" + type); + LOG.debug(sourceType.name() + " normalized sources : " + uniqueSources); + CompositePropertySource composite = new CompositePropertySource( + "composite-" + sourceType.name().toLowerCase(Locale.ROOT)); uniqueSources.forEach(secretSource -> { MapPropertySource propertySource = getPropertySource(env, secretSource, properties.readType()); @@ -67,7 +69,8 @@ public PropertySource locate(Environment environment) { LOG.warn(() -> "Failed to load source: " + secretSource); } else { - LOG.debug("Adding " + type + " property source " + propertySource.getName()); + LOG.debug("Adding " + sourceType.name().toLowerCase(Locale.ROOT) + " property source " + + propertySource.getName()); composite.addFirstPropertySource(propertySource); } }); diff --git a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/ConfigMapPropertySourceLocator.java b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/ConfigMapPropertySourceLocator.java index 30181fb60d..ab6dc2052d 100644 --- a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/ConfigMapPropertySourceLocator.java +++ b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/ConfigMapPropertySourceLocator.java @@ -26,7 +26,7 @@ public abstract class ConfigMapPropertySourceLocator extends CommonPropertySourceLocator { public ConfigMapPropertySourceLocator(ConfigMapConfigProperties configMapConfigProperties) { - super(configMapConfigProperties, "configmaps"); + super(configMapConfigProperties, SourceType.CONFIGMAP); } } diff --git a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/SecretsPropertySourceLocator.java b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/SecretsPropertySourceLocator.java index fbd92ff593..d23f5ac23e 100644 --- a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/SecretsPropertySourceLocator.java +++ b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/SecretsPropertySourceLocator.java @@ -29,7 +29,7 @@ public abstract class SecretsPropertySourceLocator extends CommonPropertySourceLocator { public SecretsPropertySourceLocator(SecretsConfigProperties properties) { - super(properties, "secrets"); + super(properties, SourceType.SECRET); } } diff --git a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/SourceConfigProperties.java b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/SourceConfigProperties.java index c06eeaba46..85ba15ba13 100644 --- a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/SourceConfigProperties.java +++ b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/SourceConfigProperties.java @@ -110,13 +110,12 @@ public ReadType readType() { return readType; } - protected final List determineSources(boolean configMap, Environment environment) { + protected final List determineSources(SourceType sourceType, Environment environment) { if (sources().isEmpty()) { List result = new ArrayList<>(2); - String configurationTarget = configMap ? "ConfigMap" : "Secret"; - String name = getApplicationName(environment, name(), configurationTarget); + String name = getApplicationName(environment, name(), sourceType.name()); NormalizedSource normalizedSource; - if (configMap) { + if (sourceType == SourceType.CONFIGMAP) { normalizedSource = new NamedConfigMapNormalizedSource(name, namespace(), failFast(), includeProfileSpecificSources()); } @@ -128,7 +127,7 @@ protected final List determineSources(boolean configMap, Envir if (!labels().isEmpty()) { NormalizedSource labeledSource; - if (configMap) { + if (sourceType == SourceType.CONFIGMAP) { labeledSource = new LabeledConfigMapNormalizedSource(namespace(), labels(), failFast(), ConfigUtils.Prefix.DEFAULT, false); } @@ -142,7 +141,7 @@ protected final List determineSources(boolean configMap, Envir } return sources().stream() - .flatMap(s -> s.normalize(configMap, name(), namespace(), labels(), includeProfileSpecificSources(), + .flatMap(s -> s.normalize(sourceType, name(), namespace(), labels(), includeProfileSpecificSources(), failFast(), useNameAsPrefix(), environment)) .toList(); } @@ -161,7 +160,7 @@ protected final List determineSources(boolean configMap, Envir public record Source(String name, String namespace, @DefaultValue Map labels, String explicitPrefix, Boolean useNameAsPrefix, Boolean includeProfileSpecificSources) { - Stream normalize(boolean configMap, String defaultName, String defaultNamespace, + Stream normalize(SourceType sourceType, String defaultName, String defaultNamespace, Map defaultLabels, boolean defaultIncludeProfileSpecificSources, boolean failFast, boolean defaultUseNameAsPrefix, Environment environment) { @@ -171,8 +170,7 @@ Stream normalize(boolean configMap, String defaultName, String String normalizedNamespace = hasLength(namespace) ? namespace : defaultNamespace; Map normalizedLabels = labels.isEmpty() ? defaultLabels : labels; - String configurationTarget = configMap ? "ConfigMap" : "Secret"; - String sourceName = getApplicationName(environment, normalizedName, configurationTarget); + String sourceName = getApplicationName(environment, normalizedName, sourceType.name()); Prefix prefix = findPrefix(explicitPrefix, useNameAsPrefix, defaultUseNameAsPrefix, normalizedName); @@ -180,7 +178,7 @@ Stream normalize(boolean configMap, String defaultName, String defaultIncludeProfileSpecificSources, this.includeProfileSpecificSources); NormalizedSource namedSource; - if (configMap) { + if (sourceType == SourceType.CONFIGMAP) { namedSource = new NamedConfigMapNormalizedSource(sourceName, normalizedNamespace, failFast, prefix, includeProfileSpecificSources); } @@ -192,7 +190,7 @@ Stream normalize(boolean configMap, String defaultName, String if (!normalizedLabels.isEmpty()) { NormalizedSource labeledSource; - if (configMap) { + if (sourceType == SourceType.CONFIGMAP) { labeledSource = new LabeledConfigMapNormalizedSource(normalizedNamespace, labels, failFast, prefix, includeProfileSpecificSources); } diff --git a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/SourceType.java b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/SourceType.java new file mode 100644 index 0000000000..bd3d7b5817 --- /dev/null +++ b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/SourceType.java @@ -0,0 +1,31 @@ +/* + * Copyright 2013-present 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; + +public enum SourceType { + + /** + * ConfigMap as the source type. + */ + CONFIGMAP, + + /** + * Secret as the source type. + */ + SECRET + +} diff --git a/spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/config/ConfigMapConfigPropertiesTests.java b/spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/config/ConfigMapConfigPropertiesTests.java index d033295373..3b7786004d 100644 --- a/spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/config/ConfigMapConfigPropertiesTests.java +++ b/spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/config/ConfigMapConfigPropertiesTests.java @@ -51,7 +51,7 @@ void testUseNameAsPrefixUnsetEmptySources() { ConfigMapConfigProperties properties = new ConfigMapConfigProperties(true, List.of(), Map.of(), "config-map-a", "spring-k8s", false, false, false, RetryProperties.DEFAULT, BATCH); - List sources = properties.determineSources(true, new MockEnvironment()); + List sources = properties.determineSources(SourceType.CONFIGMAP, new MockEnvironment()); Assertions.assertThat(sources.size()).isEqualTo(1); Assertions.assertThat(((NamedConfigMapNormalizedSource) sources.get(0)).prefix()) @@ -77,7 +77,7 @@ void testUseNameAsPrefixSetEmptySources() { ConfigMapConfigProperties properties = new ConfigMapConfigProperties(true, List.of(), Map.of(), "config-map-a", "spring-k8s", true, false, false, RetryProperties.DEFAULT, BATCH); - List sources = properties.determineSources(true, new MockEnvironment()); + List sources = properties.determineSources(SourceType.CONFIGMAP, new MockEnvironment()); Assertions.assertThat(sources.size()).isEqualTo(1); Assertions.assertThat(((NamedConfigMapNormalizedSource) sources.get(0)).prefix()) @@ -108,7 +108,7 @@ void testUseNameAsPrefixUnsetNonEmptySources() { ConfigMapConfigProperties properties = new ConfigMapConfigProperties(true, List.of(one), Map.of(), "config-map-a", "spring-k8s", true, false, false, RetryProperties.DEFAULT, BATCH); - List sources = properties.determineSources(true, new MockEnvironment()); + List sources = properties.determineSources(SourceType.CONFIGMAP, new MockEnvironment()); Assertions.assertThat(sources.size()).isEqualTo(1); Assertions.assertThat(((NamedConfigMapNormalizedSource) sources.get(0)).prefix().prefixProvider().get()) @@ -151,7 +151,7 @@ void testUseNameAsPrefixSetNonEmptySources() { ConfigMapConfigProperties properties = new ConfigMapConfigProperties(true, List.of(one, two, three), Map.of(), "config-map-a", "spring-k8s", true, false, false, RetryProperties.DEFAULT, BATCH); - List sources = properties.determineSources(true, new MockEnvironment()); + List sources = properties.determineSources(SourceType.CONFIGMAP, new MockEnvironment()); Assertions.assertThat(sources.size()).isEqualTo(3); Assertions.assertThat(((NamedConfigMapNormalizedSource) sources.get(0)).prefix()) @@ -201,7 +201,7 @@ void testMultipleCases() { ConfigMapConfigProperties properties = new ConfigMapConfigProperties(true, List.of(one, two, three, four), Map.of(), "config-map-a", "spring-k8s", true, false, false, RetryProperties.DEFAULT, BATCH); - List sources = properties.determineSources(true, new MockEnvironment()); + List sources = properties.determineSources(SourceType.CONFIGMAP, new MockEnvironment()); Assertions.assertThat(sources.size()).isEqualTo(4); Assertions.assertThat(((NamedConfigMapNormalizedSource) sources.get(0)).prefix().prefixProvider().get()) @@ -234,7 +234,7 @@ void testUseIncludeProfileSpecificSourcesNoChanges() { ConfigMapConfigProperties properties = new ConfigMapConfigProperties(true, List.of(), Map.of(), "config-map-a", "spring-k8s", false, true, false, RetryProperties.DEFAULT, BATCH); - List sources = properties.determineSources(true, new MockEnvironment()); + List sources = properties.determineSources(SourceType.CONFIGMAP, new MockEnvironment()); Assertions.assertThat(sources.size()).isEqualTo(1); Assertions.assertThat(((NamedConfigMapNormalizedSource) sources.get(0)).profileSpecificSources()).isTrue(); @@ -263,7 +263,7 @@ void testUseIncludeProfileSpecificSourcesDefaultChanged() { ConfigMapConfigProperties properties = new ConfigMapConfigProperties(true, List.of(), Map.of(), "config-map-a", "spring-k8s", false, false, false, RetryProperties.DEFAULT, BATCH); - List sources = properties.determineSources(true, new MockEnvironment()); + List sources = properties.determineSources(SourceType.CONFIGMAP, new MockEnvironment()); Assertions.assertThat(sources.size()).isEqualTo(1); Assertions.assertThat(((NamedConfigMapNormalizedSource) sources.get(0)).profileSpecificSources()).isFalse(); @@ -307,7 +307,7 @@ void testUseIncludeProfileSpecificSourcesDefaultChangedSourceOverride() { ConfigMapConfigProperties properties = new ConfigMapConfigProperties(true, List.of(one, two, three), Map.of(), "config-map-a", "spring-k8s", false, false, false, RetryProperties.DEFAULT, BATCH); - List sources = properties.determineSources(true, new MockEnvironment()); + List sources = properties.determineSources(SourceType.CONFIGMAP, new MockEnvironment()); Assertions.assertThat(sources.size()).isEqualTo(3); Assertions.assertThat(((NamedConfigMapNormalizedSource) sources.get(0)).profileSpecificSources()).isTrue(); @@ -364,7 +364,7 @@ void testLabelsMultipleCases() { ConfigMapConfigProperties properties = new ConfigMapConfigProperties(true, List.of(one, two, three, four), Map.of(), "config-map-a", "spring-k8s", false, false, false, RetryProperties.DEFAULT, BATCH); - List sources = properties.determineSources(true, new MockEnvironment()); + List sources = properties.determineSources(SourceType.CONFIGMAP, new MockEnvironment()); // we get 8 property sources, since "named" ones with "application" are // duplicated. // that's OK, since later in the code we get a LinkedHashSet out of them all, diff --git a/spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/config/SecretsConfigPropertiesTests.java b/spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/config/SecretsConfigPropertiesTests.java index bb91e61d1a..30b3fdaf61 100644 --- a/spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/config/SecretsConfigPropertiesTests.java +++ b/spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/config/SecretsConfigPropertiesTests.java @@ -41,7 +41,7 @@ void emptySourcesSecretName() { SecretsConfigProperties properties = new SecretsConfigProperties(true, List.of(), Map.of(), null, "namespace", false, true, false, RetryProperties.DEFAULT, ReadType.BATCH); - List source = properties.determineSources(false, new MockEnvironment()); + List source = properties.determineSources(SourceType.SECRET, new MockEnvironment()); Assertions.assertThat(source.size()).isEqualTo(1); Assertions.assertThat(source.get(0) instanceof NamedSecretNormalizedSource).isTrue(); Assertions.assertThat(source.get(0).name().isPresent()).isTrue(); @@ -82,7 +82,7 @@ void multipleSources() { SecretsConfigProperties properties = new SecretsConfigProperties(true, List.of(one, two, three), Map.of(), null, "namespace", false, true, false, RetryProperties.DEFAULT, ReadType.BATCH); - List result = properties.determineSources(false, new MockEnvironment()); + List result = properties.determineSources(SourceType.SECRET, new MockEnvironment()); Assertions.assertThat(result.size()).isEqualTo(6); Set resultAsSet = new LinkedHashSet<>(result); @@ -124,7 +124,7 @@ void testUseNameAsPrefixUnsetEmptySources() { SecretsConfigProperties properties = new SecretsConfigProperties(true, List.of(), Map.of(), "secret-a", "namespace", false, true, false, RetryProperties.DEFAULT, ReadType.BATCH); - List sources = properties.determineSources(false, new MockEnvironment()); + List sources = properties.determineSources(SourceType.SECRET, new MockEnvironment()); Assertions.assertThat(sources.size()).isEqualTo(1); Assertions.assertThat(((NamedSecretNormalizedSource) sources.get(0)).prefix()) @@ -151,7 +151,7 @@ void testUseNameAsPrefixSetEmptySources() { SecretsConfigProperties properties = new SecretsConfigProperties(true, List.of(), Map.of(), "secret-a", "namespace", true, true, false, RetryProperties.DEFAULT, ReadType.BATCH); - List sources = properties.determineSources(false, new MockEnvironment()); + List sources = properties.determineSources(SourceType.SECRET, new MockEnvironment()); Assertions.assertThat(sources.size()).isEqualTo(1); Assertions.assertThat(((NamedSecretNormalizedSource) sources.get(0)).prefix()) @@ -182,7 +182,7 @@ void testUseNameAsPrefixUnsetNonEmptySources() { SecretsConfigProperties properties = new SecretsConfigProperties(true, List.of(one), Map.of(), "secret-one", null, false, true, false, RetryProperties.DEFAULT, ReadType.BATCH); - List sources = properties.determineSources(false, new MockEnvironment()); + List sources = properties.determineSources(SourceType.SECRET, new MockEnvironment()); Assertions.assertThat(sources.size()).isEqualTo(1); Assertions.assertThat(((NamedSecretNormalizedSource) sources.get(0)).prefix().prefixProvider().get()) @@ -225,7 +225,7 @@ void testUseNameAsPrefixSetNonEmptySources() { SecretsConfigProperties properties = new SecretsConfigProperties(true, List.of(one, two, three), Map.of(), "secret-one", null, false, true, false, RetryProperties.DEFAULT, ReadType.BATCH); - List sources = properties.determineSources(false, new MockEnvironment()); + List sources = properties.determineSources(SourceType.SECRET, new MockEnvironment()); Assertions.assertThat(sources.size()).isEqualTo(3); Assertions.assertThat(((NamedSecretNormalizedSource) sources.get(0)).prefix()) @@ -275,7 +275,7 @@ void testMultipleCases() { SecretsConfigProperties properties = new SecretsConfigProperties(true, List.of(one, two, three, four), Map.of(), "secret-one", "spring-k8s", false, false, false, RetryProperties.DEFAULT, ReadType.BATCH); - List sources = properties.determineSources(false, new MockEnvironment()); + List sources = properties.determineSources(SourceType.SECRET, new MockEnvironment()); Assertions.assertThat(sources.size()).isEqualTo(4); Assertions.assertThat(((NamedSecretNormalizedSource) sources.get(0)).prefix().prefixProvider().get()) @@ -336,7 +336,7 @@ void testLabelsMultipleCases() { SecretsConfigProperties properties = new SecretsConfigProperties(false, List.of(one, two, three, four), Map.of(), null, "spring-k8s", false, false, false, RetryProperties.DEFAULT, ReadType.BATCH); - List sources = properties.determineSources(false, new MockEnvironment()); + List sources = properties.determineSources(SourceType.SECRET, new MockEnvironment()); // we get 8 property sources, since "named" ones with "application" are // duplicated. // that's OK, since later in the code we get a LinkedHashSet out of them all, diff --git a/spring-cloud-kubernetes-fabric8-config/src/main/java/org/springframework/cloud/kubernetes/fabric8/config/Fabric8ConfigMapPropertySourceLocator.java b/spring-cloud-kubernetes-fabric8-config/src/main/java/org/springframework/cloud/kubernetes/fabric8/config/Fabric8ConfigMapPropertySourceLocator.java index ee7377f8c8..326739d43f 100644 --- a/spring-cloud-kubernetes-fabric8-config/src/main/java/org/springframework/cloud/kubernetes/fabric8/config/Fabric8ConfigMapPropertySourceLocator.java +++ b/spring-cloud-kubernetes-fabric8-config/src/main/java/org/springframework/cloud/kubernetes/fabric8/config/Fabric8ConfigMapPropertySourceLocator.java @@ -62,8 +62,8 @@ public PropertySource locate(Environment environment) { } @Override - protected MapPropertySource getMapPropertySource(NormalizedSource normalizedSource, - ConfigurableEnvironment environment, ReadType readType) { + protected MapPropertySource getPropertySource(ConfigurableEnvironment environment, + NormalizedSource normalizedSource, ReadType readType) { // NormalizedSource has a namespace, but users can skip it. // In such cases we try to get it elsewhere String namespace = getApplicationNamespace(this.client, normalizedSource.namespace().orElse(null), diff --git a/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/Fabric8ConfigMapPropertySourceLocatorMockTests.java b/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/Fabric8ConfigMapPropertySourceLocatorMockTests.java index b5d551b9e1..f93c2ca341 100644 --- a/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/Fabric8ConfigMapPropertySourceLocatorMockTests.java +++ b/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/Fabric8ConfigMapPropertySourceLocatorMockTests.java @@ -54,7 +54,7 @@ void constructorWithoutClientNamespaceMustFail() { Fabric8ConfigMapPropertySourceLocator source = new Fabric8ConfigMapPropertySourceLocator(client, configMapConfigProperties, new KubernetesNamespaceProvider(new MockEnvironment())); NormalizedSource normalizedSource = new NamedConfigMapNormalizedSource("name", null, false, PREFIX, false); - assertThatThrownBy(() -> source.getMapPropertySource(normalizedSource, new MockEnvironment(), ReadType.BATCH)) + assertThatThrownBy(() -> source.getPropertySource(new MockEnvironment(), normalizedSource, ReadType.BATCH)) .isInstanceOf(NamespaceResolutionFailedException.class); } From 3cb5714cc82a12ba61fa0079051b915a414b509d Mon Sep 17 00:00:00 2001 From: wind57 Date: Tue, 7 Oct 2025 15:24:34 +0300 Subject: [PATCH 3/5] fix Signed-off-by: wind57 --- .../kubernetes/commons/config/CommonPropertySourceLocator.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/CommonPropertySourceLocator.java b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/CommonPropertySourceLocator.java index 38f3b06e50..aaf5dd372f 100644 --- a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/CommonPropertySourceLocator.java +++ b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/CommonPropertySourceLocator.java @@ -18,6 +18,7 @@ import java.util.Collection; import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.List; import java.util.Locale; import java.util.Set; @@ -57,7 +58,7 @@ public PropertySource locate(Environment environment) { if (environment instanceof ConfigurableEnvironment env) { List sources = properties.determineSources(sourceType, environment); - Set uniqueSources = new HashSet<>(sources); + Set uniqueSources = new LinkedHashSet<>(sources); LOG.debug(sourceType.name() + " normalized sources : " + uniqueSources); CompositePropertySource composite = new CompositePropertySource( "composite-" + sourceType.name().toLowerCase(Locale.ROOT)); From fa058aefbe6ca97a1e1821bb1267337ab09d5b7e Mon Sep 17 00:00:00 2001 From: wind57 Date: Tue, 7 Oct 2025 15:41:47 +0300 Subject: [PATCH 4/5] checkstyle Signed-off-by: wind57 --- .../kubernetes/commons/config/CommonPropertySourceLocator.java | 1 - 1 file changed, 1 deletion(-) diff --git a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/CommonPropertySourceLocator.java b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/CommonPropertySourceLocator.java index aaf5dd372f..357b315d53 100644 --- a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/CommonPropertySourceLocator.java +++ b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/CommonPropertySourceLocator.java @@ -17,7 +17,6 @@ package org.springframework.cloud.kubernetes.commons.config; import java.util.Collection; -import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; import java.util.Locale; From ad63517bc0d3c65e42d23922653a5a15f9b68a63 Mon Sep 17 00:00:00 2001 From: wind57 Date: Tue, 7 Oct 2025 16:03:21 +0300 Subject: [PATCH 5/5] placeholder Signed-off-by: wind57