Skip to content

Commit 11d382b

Browse files
committed
Merge branch '3.1.x'
2 parents 641ee1e + aad8cd0 commit 11d382b

File tree

10 files changed

+55
-34
lines changed

10 files changed

+55
-34
lines changed

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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ public static MultipleSourcesContainer processNamedData(List<StrippedSourceConta
210210
sourceNames.forEach(sourceName -> {
211211
StrippedSourceContainer stripped = hashByName.get(sourceName);
212212
if (stripped != null) {
213-
LOG.debug("Found source with name : '" + sourceName + " in namespace: '" + namespace + "'");
213+
LOG.debug("Found source with name : '" + sourceName + "' in namespace: '" + namespace + "'");
214214
foundSourceNames.add(sourceName);
215215
// see if data is a single yaml/properties file and if it needs decoding
216216
Map<String, String> rawData = stripped.data();
@@ -229,6 +229,9 @@ public static MultipleSourcesContainer processNamedData(List<StrippedSourceConta
229229
environment, includeDefaultProfileData));
230230
}
231231
}
232+
else {
233+
LOG.warn("sourceName : " + sourceName + " was requested, but not found in namespace : " + namespace);
234+
}
232235
});
233236

234237
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) {

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

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -141,25 +141,25 @@ else if (propertySource instanceof CompositePropertySource source) {
141141
return result;
142142
}
143143

144-
static boolean changed(List<? extends MapPropertySource> left, List<? extends MapPropertySource> right) {
145-
if (left.size() != right.size()) {
144+
static boolean changed(List<? extends MapPropertySource> k8sSources, List<? extends MapPropertySource> appSources) {
145+
if (k8sSources.size() != appSources.size()) {
146146
if (LOG.isDebugEnabled()) {
147-
LOG.debug("left size: " + left.size());
148-
left.forEach(item -> LOG.debug(item.toString()));
147+
LOG.debug("k8s property sources size: " + k8sSources.size());
148+
k8sSources.forEach(item -> LOG.debug(item.toString()));
149149

150-
LOG.debug("right size: " + right.size());
151-
right.forEach(item -> LOG.debug(item.toString()));
150+
LOG.debug("app property sources size size: " + appSources.size());
151+
appSources.forEach(item -> LOG.debug(item.toString()));
152152
}
153-
LOG.warn(() -> "The current number of ConfigMap PropertySources does not match "
153+
LOG.warn(() -> "The current number of PropertySources does not match "
154154
+ "the ones loaded from Kubernetes - No reload will take place");
155155
return false;
156156
}
157157

158-
for (int i = 0; i < left.size(); i++) {
159-
MapPropertySource leftPropertySource = left.get(i);
160-
MapPropertySource rightPropertySource = right.get(i);
161-
if (changed(leftPropertySource, rightPropertySource)) {
162-
LOG.debug(() -> "found change in : " + leftPropertySource);
158+
for (int i = 0; i < k8sSources.size(); i++) {
159+
MapPropertySource k8sSource = k8sSources.get(i);
160+
MapPropertySource appSource = appSources.get(i);
161+
if (changed(k8sSource, appSource)) {
162+
LOG.debug(() -> "found change in : " + k8sSource);
163163
return true;
164164
}
165165
}
@@ -169,20 +169,20 @@ static boolean changed(List<? extends MapPropertySource> left, List<? extends Ma
169169

170170
/**
171171
* Determines if two property sources are different.
172-
* @param left left map property sources
173-
* @param right right map property sources
172+
* @param k8sSource left map property sources
173+
* @param appSource right map property sources
174174
* @return {@code true} if source has changed
175175
*/
176-
static boolean changed(MapPropertySource left, MapPropertySource right) {
177-
if (left == right) {
176+
static boolean changed(MapPropertySource k8sSource, MapPropertySource appSource) {
177+
if (k8sSource == appSource) {
178178
return false;
179179
}
180-
if (left == null || right == null) {
180+
if (k8sSource == null || appSource == null) {
181181
return true;
182182
}
183-
Map<String, Object> leftMap = left.getSource();
184-
Map<String, Object> rightMap = right.getSource();
185-
return !Objects.equals(leftMap, rightMap);
183+
Map<String, Object> k8sMap = k8sSource.getSource();
184+
Map<String, Object> appMap = appSource.getSource();
185+
return !Objects.equals(k8sMap, appMap);
186186
}
187187

188188
}

spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-k8s-client-reload/src/main/resources/application-with-secret.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
logging:
22
level:
3-
root: DEBUG
3+
org:
4+
springframework:
5+
cloud:
6+
kubernetes: debug
47

58
spring:
69
application:
@@ -18,3 +21,6 @@ spring:
1821
secrets:
1922
enabled: true
2023
enable-api: true
24+
25+
config:
26+
enabled: false

0 commit comments

Comments
 (0)