Skip to content

Commit 4e4ebff

Browse files
committed
Merge branch 'main' into move-to-a-common-configuration-for-health
2 parents 61c9aec + 0355d7a commit 4e4ebff

File tree

20 files changed

+129
-91
lines changed

20 files changed

+129
-91
lines changed

docs/modules/ROOT/pages/property-source-config/propertysource-reload.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
= `PropertySource` Reload
33

44
WARNING: This functionality has been deprecated in the 2020.0 release. Please see
5-
the xref:spring-cloud-kubernetes-configuration-watcher.adoc#spring-cloud-kubernetes-configuration-watcher[null] controller for an alternative way
6-
to achieve the same functionality.
5+
the xref:spring-cloud-kubernetes-configuration-watcher.adoc#spring-cloud-kubernetes-configuration-watcher[Spring Cloud Kubernetes Configuration Watcher]
6+
controller for an alternative way to achieve the same functionality.
77

88
Some applications may need to detect changes on external property sources and update their internal status to reflect the new configuration.
99
The reload feature of Spring Cloud Kubernetes is able to trigger an application reload when a related `ConfigMap` or

docs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"dependencies": {
33
"antora": "3.2.0-alpha.4",
44
"@antora/atlas-extension": "1.0.0-alpha.2",
5-
"@antora/collector-extension": "1.0.0-beta.3",
5+
"@antora/collector-extension": "1.0.0-beta.4",
66
"@asciidoctor/tabs": "1.0.0-beta.6",
77
"@springio/antora-extensions": "1.11.1",
88
"@springio/asciidoctor-extensions": "1.0.0-alpha.14"

spring-cloud-kubernetes-client-config/src/main/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientConfigUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ private static List<StrippedSourceContainer> strippedConfigMaps(CoreV1Api coreV1
147147
private static List<StrippedSourceContainer> strippedSecrets(CoreV1Api coreV1Api, String namespace) {
148148
List<StrippedSourceContainer> strippedSecrets = KubernetesClientSecretsCache.byNamespace(coreV1Api, namespace);
149149
if (strippedSecrets.isEmpty()) {
150-
LOG.debug("No configmaps in namespace '" + namespace + "'");
150+
LOG.debug("No secrets in namespace '" + namespace + "'");
151151
}
152152
return strippedSecrets;
153153
}

spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/ConfigMapPropertySourceLocator.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,11 @@ public PropertySource<?> locate(Environment environment) {
8282
if (this.properties.enableApi()) {
8383
Set<NormalizedSource> sources = new LinkedHashSet<>(this.properties.determineSources(environment));
8484
LOG.debug("Config Map normalized sources : " + sources);
85-
sources.forEach(s -> composite.addFirstPropertySource(getMapPropertySource(s, env)));
85+
sources.forEach(s -> {
86+
MapPropertySource propertySource = getMapPropertySource(s, env);
87+
LOG.debug("Adding config map property source " + propertySource.getName());
88+
composite.addFirstPropertySource(propertySource);
89+
});
8690
}
8791

8892
addPropertySourcesFromPaths(environment, composite);

spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/ConfigUtils.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ public final class ConfigUtils {
6161
|| sourceName.endsWith("-" + activeProfile + ".yaml")
6262
|| sourceName.endsWith("-" + activeProfile + ".properties");
6363

64-
private static final ApplicationListener<?> NO_OP = (e) -> { };
64+
private static final ApplicationListener<?> NO_OP = (e) -> {
65+
};
6566

6667
private ConfigUtils() {
6768
}
@@ -209,7 +210,7 @@ public static MultipleSourcesContainer processNamedData(List<StrippedSourceConta
209210
sourceNames.forEach(sourceName -> {
210211
StrippedSourceContainer stripped = hashByName.get(sourceName);
211212
if (stripped != null) {
212-
LOG.debug("Found source with name : '" + sourceName + " in namespace: '" + namespace + "'");
213+
LOG.debug("Found source with name : '" + sourceName + "' in namespace: '" + namespace + "'");
213214
foundSourceNames.add(sourceName);
214215
// see if data is a single yaml/properties file and if it needs decoding
215216
Map<String, String> rawData = stripped.data();
@@ -228,6 +229,9 @@ public static MultipleSourcesContainer processNamedData(List<StrippedSourceConta
228229
environment, includeDefaultProfileData));
229230
}
230231
}
232+
else {
233+
LOG.warn("sourceName : " + sourceName + " was requested, but not found in namespace : " + namespace);
234+
}
231235
});
232236

233237
return new MultipleSourcesContainer(foundSourceNames, data);

spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/LabeledSourceData.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ public final SourceData compute(Map<String, String> labels, ConfigUtils.Prefix p
4545
data = dataSupplier(labels, profiles);
4646

4747
// need this check because when there is no data, the name of the property
48-
// source
49-
// is using provided labels,
48+
// source is using provided labels,
5049
// unlike when the data is present: when we use secret names
5150
if (data.names().isEmpty()) {
5251
String names = labels.keySet()

spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/NamedSourceData.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
package org.springframework.cloud.kubernetes.commons.config;
1818

1919
import java.util.LinkedHashSet;
20-
import java.util.Map;
2120
import java.util.stream.Collectors;
2221

22+
import org.apache.commons.logging.Log;
23+
import org.apache.commons.logging.LogFactory;
24+
2325
import static org.springframework.cloud.kubernetes.commons.config.ConfigUtils.onException;
2426
import static org.springframework.cloud.kubernetes.commons.config.Constants.PROPERTY_SOURCE_NAME_SEPARATOR;
2527

@@ -31,6 +33,8 @@
3133
*/
3234
public abstract class NamedSourceData {
3335

36+
private static final Log LOG = LogFactory.getLog(NamedSourceData.class);
37+
3438
public final SourceData compute(String sourceName, ConfigUtils.Prefix prefix, String target, boolean profileSources,
3539
boolean failFast, String namespace, String[] activeProfiles) {
3640

@@ -51,7 +55,9 @@ public final SourceData compute(String sourceName, ConfigUtils.Prefix prefix, St
5155
data = dataSupplier(sourceNames);
5256

5357
if (data.names().isEmpty()) {
54-
return new SourceData(ConfigUtils.sourceName(target, sourceName, namespace), Map.of());
58+
String emptySourceName = ConfigUtils.sourceName(target, sourceName, namespace);
59+
LOG.debug("Will return empty source with name : " + emptySourceName);
60+
return SourceData.emptyRecord(emptySourceName);
5561
}
5662

5763
if (prefix != ConfigUtils.Prefix.DEFAULT) {

spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/SecretsPropertySourceLocator.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.springframework.core.env.CompositePropertySource;
4343
import org.springframework.core.env.ConfigurableEnvironment;
4444
import org.springframework.core.env.Environment;
45+
import org.springframework.core.env.MapPropertySource;
4546
import org.springframework.core.env.PropertySource;
4647

4748
/**
@@ -87,8 +88,11 @@ public PropertySource<?> locate(Environment environment) {
8788
putPathConfig(composite);
8889

8990
if (this.properties.enableApi()) {
90-
uniqueSources
91-
.forEach(s -> composite.addPropertySource(getSecretsPropertySourceForSingleSecret(env, s)));
91+
uniqueSources.forEach(s -> {
92+
MapPropertySource propertySource = getSecretsPropertySourceForSingleSecret(env, s);
93+
LOG.debug("Adding secret property source " + propertySource.getName());
94+
composite.addFirstPropertySource(propertySource);
95+
});
9296
}
9397

9498
cache.discardAll();

spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/SourceData.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package org.springframework.cloud.kubernetes.commons.config;
1818

19-
import java.util.Collections;
2019
import java.util.Map;
2120

2221
/**
@@ -25,10 +24,10 @@
2524
*
2625
* @author wind57
2726
*/
28-
public final record SourceData(String sourceName, Map<String, Object> sourceData) {
27+
public record SourceData(String sourceName, Map<String, Object> sourceData) {
2928

3029
public static SourceData emptyRecord(String sourceName) {
31-
return new SourceData(sourceName, Collections.emptyMap());
30+
return new SourceData(sourceName, Map.of());
3231
}
3332

3433
}

spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/SourceDataEntriesProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class SourceDataEntriesProcessor extends MapPropertySource {
4848

4949
private static final Log LOG = LogFactory.getLog(SourceDataEntriesProcessor.class);
5050

51-
private static Predicate<String> ENDS_IN_EXTENSION = x -> x.endsWith(".yml") || x.endsWith(".yaml")
51+
private static final Predicate<String> ENDS_IN_EXTENSION = x -> x.endsWith(".yml") || x.endsWith(".yaml")
5252
|| x.endsWith(".properties");
5353

5454
public SourceDataEntriesProcessor(SourceData sourceData) {

0 commit comments

Comments
 (0)