Skip to content

Commit 65566c4

Browse files
committed
fix issue
Signed-off-by: wind57 <[email protected]>
1 parent 88729ee commit 65566c4

File tree

4 files changed

+53
-12
lines changed

4 files changed

+53
-12
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright 2013-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.cloud.kubernetes.commons.config;
18+
19+
/**
20+
* @author wind57
21+
*/
22+
public final class MountSecretPropertySource extends SecretsPropertySource {
23+
24+
public MountSecretPropertySource(SourceData sourceData) {
25+
super(sourceData);
26+
}
27+
28+
}

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,33 +152,33 @@ protected void putPathConfig(CompositePropertySource composite) {
152152
* @author wind57
153153
*/
154154
private static class SecretsPropertySourceCollector
155-
implements Collector<Path, List<SecretsPropertySource>, List<SecretsPropertySource>> {
155+
implements Collector<Path, List<MountSecretPropertySource>, List<MountSecretPropertySource>> {
156156

157157
@Override
158-
public Supplier<List<SecretsPropertySource>> supplier() {
158+
public Supplier<List<MountSecretPropertySource>> supplier() {
159159
return ArrayList::new;
160160
}
161161

162162
@Override
163-
public BiConsumer<List<SecretsPropertySource>, Path> accumulator() {
163+
public BiConsumer<List<MountSecretPropertySource>, Path> accumulator() {
164164
return (list, filePath) -> {
165-
SecretsPropertySource source = property(filePath);
165+
MountSecretPropertySource source = property(filePath);
166166
if (source != null) {
167167
list.add(source);
168168
}
169169
};
170170
}
171171

172172
@Override
173-
public BinaryOperator<List<SecretsPropertySource>> combiner() {
173+
public BinaryOperator<List<MountSecretPropertySource>> combiner() {
174174
return (left, right) -> {
175175
left.addAll(right);
176176
return left;
177177
};
178178
}
179179

180180
@Override
181-
public Function<List<SecretsPropertySource>, List<SecretsPropertySource>> finisher() {
181+
public Function<List<MountSecretPropertySource>, List<MountSecretPropertySource>> finisher() {
182182
return Function.identity();
183183
}
184184

@@ -187,15 +187,15 @@ public Set<Characteristics> characteristics() {
187187
return EnumSet.of(Characteristics.UNORDERED, Characteristics.IDENTITY_FINISH);
188188
}
189189

190-
private SecretsPropertySource property(Path filePath) {
190+
private MountSecretPropertySource property(Path filePath) {
191191

192192
String fileName = filePath.getFileName().toString();
193193

194194
try {
195195
String content = new String(Files.readAllBytes(filePath)).trim();
196196
String sourceName = fileName.toLowerCase(Locale.ROOT);
197197
SourceData sourceData = new SourceData(sourceName, Map.of(fileName, content));
198-
return new SecretsPropertySource(sourceData);
198+
return new MountSecretPropertySource(sourceData);
199199
}
200200
catch (IOException e) {
201201
LOG.warn("Error reading properties file", e);

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.springframework.cloud.bootstrap.config.BootstrapPropertySource;
2828
import org.springframework.cloud.bootstrap.config.PropertySourceLocator;
2929
import org.springframework.cloud.kubernetes.commons.config.MountConfigMapPropertySource;
30+
import org.springframework.cloud.kubernetes.commons.config.MountSecretPropertySource;
3031
import org.springframework.core.env.CompositePropertySource;
3132
import org.springframework.core.env.ConfigurableEnvironment;
3233
import org.springframework.core.env.MapPropertySource;
@@ -88,6 +89,7 @@ public static boolean reload(PropertySourceLocator locator, ConfigurableEnvironm
8889
* @deprecated this method will not be public in the next major release.
8990
*/
9091
@Deprecated(forRemoval = false)
92+
@SuppressWarnings("unchecked")
9193
public static <S extends PropertySource<?>> List<S> findPropertySources(Class<S> sourceClass,
9294
ConfigurableEnvironment environment) {
9395
List<S> managedSources = new ArrayList<>();
@@ -110,6 +112,10 @@ else if (source instanceof MountConfigMapPropertySource mountConfigMapPropertySo
110112
// we know that the type is correct here
111113
managedSources.add((S) mountConfigMapPropertySource);
112114
}
115+
else if (source instanceof MountSecretPropertySource mountSecretPropertySource) {
116+
// we know that the type is correct here
117+
managedSources.add((S) mountSecretPropertySource);
118+
}
113119
else if (source instanceof BootstrapPropertySource<?> bootstrapPropertySource) {
114120
PropertySource<?> propertySource = bootstrapPropertySource.getDelegate();
115121
LOG.debug(() -> "bootstrap delegate class : " + propertySource.getClass());
@@ -120,6 +126,10 @@ else if (propertySource instanceof MountConfigMapPropertySource mountConfigMapPr
120126
// we know that the type is correct here
121127
managedSources.add((S) mountConfigMapPropertySource);
122128
}
129+
else if (propertySource instanceof MountSecretPropertySource mountSecretPropertySource) {
130+
// we know that the type is correct here
131+
managedSources.add((S) mountSecretPropertySource);
132+
}
123133
}
124134
}
125135

spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/config/reload/ConfigReloadUtilTests.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import org.springframework.cloud.bootstrap.config.BootstrapPropertySource;
2929
import org.springframework.cloud.kubernetes.commons.config.MountConfigMapPropertySource;
30+
import org.springframework.cloud.kubernetes.commons.config.MountSecretPropertySource;
3031
import org.springframework.cloud.kubernetes.commons.config.SecretsPropertySource;
3132
import org.springframework.cloud.kubernetes.commons.config.SourceData;
3233
import org.springframework.core.env.CompositePropertySource;
@@ -157,23 +158,25 @@ public Object getProperty(String name) {
157158
void testSecretsPropertySource() {
158159
MockEnvironment environment = new MockEnvironment();
159160
MutablePropertySources propertySources = environment.getPropertySources();
160-
propertySources.addFirst(new SecretsPropertySource(new SourceData("secret", Map.of("a", "b"))));
161+
propertySources.addFirst(new MountSecretPropertySource(new SourceData("secret", Map.of("a", "b"))));
161162

162163
List<? extends PropertySource> result = ConfigReloadUtil.findPropertySources(PlainPropertySource.class,
163164
environment);
164-
assertThat(result.size()).isEqualTo(0);
165+
assertThat(result.size()).isEqualTo(1);
166+
assertThat(result.get(0).getProperty("a")).isEqualTo("b");
165167
}
166168

167169
@Test
168170
void testBootstrapSecretsPropertySource() {
169171
MockEnvironment environment = new MockEnvironment();
170172
MutablePropertySources propertySources = environment.getPropertySources();
171173
propertySources
172-
.addFirst(new OneBootstrap<>(new SecretsPropertySource(new SourceData("secret", Map.of("a", "b")))));
174+
.addFirst(new OneBootstrap<>(new MountSecretPropertySource(new SourceData("secret", Map.of("a", "b")))));
173175

174176
List<? extends PropertySource> result = ConfigReloadUtil.findPropertySources(PlainPropertySource.class,
175177
environment);
176-
assertThat(result.size()).isEqualTo(0);
178+
assertThat(result.size()).isEqualTo(1);
179+
assertThat(result.get(0).getProperty("a")).isEqualTo("b");
177180
}
178181

179182
private static final class OneComposite extends CompositePropertySource {

0 commit comments

Comments
 (0)