Skip to content

Commit 0f96c04

Browse files
committed
fix
Signed-off-by: wind57 <[email protected]>
2 parents 5f9c82f + 619a1ad commit 0f96c04

File tree

25 files changed

+253
-327
lines changed

25 files changed

+253
-327
lines changed

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

Lines changed: 9 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.SecretsPropertySource;
3031
import org.springframework.core.env.CompositePropertySource;
3132
import org.springframework.core.env.ConfigurableEnvironment;
3233
import org.springframework.core.env.MapPropertySource;
@@ -110,6 +111,10 @@ else if (source instanceof MountConfigMapPropertySource mountConfigMapPropertySo
110111
// we know that the type is correct here
111112
managedSources.add((S) mountConfigMapPropertySource);
112113
}
114+
else if (source instanceof SecretsPropertySource secretsPropertySource) {
115+
// we know that the type is correct here
116+
managedSources.add((S) secretsPropertySource);
117+
}
113118
else if (source instanceof BootstrapPropertySource<?> bootstrapPropertySource) {
114119
PropertySource<?> propertySource = bootstrapPropertySource.getDelegate();
115120
LOG.debug(() -> "bootstrap delegate class : " + propertySource.getClass());
@@ -120,6 +125,10 @@ else if (propertySource instanceof MountConfigMapPropertySource mountConfigMapPr
120125
// we know that the type is correct here
121126
managedSources.add((S) mountConfigMapPropertySource);
122127
}
128+
else if (propertySource instanceof SecretsPropertySource secretsPropertySource) {
129+
// we know that the type is correct here
130+
managedSources.add((S) secretsPropertySource);
131+
}
123132
}
124133
}
125134

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

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
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.SecretsPropertySource;
31+
import org.springframework.cloud.kubernetes.commons.config.SourceData;
3032
import org.springframework.core.env.CompositePropertySource;
3133
import org.springframework.core.env.EnumerablePropertySource;
3234
import org.springframework.core.env.MapPropertySource;
@@ -127,8 +129,8 @@ void testFindPropertySources() {
127129
MockEnvironment environment = new MockEnvironment();
128130
MutablePropertySources propertySources = environment.getPropertySources();
129131
propertySources.addFirst(new OneComposite());
130-
propertySources.addFirst(new PlainPropertySource("plain"));
131-
propertySources.addFirst(new OneBootstrap(new EnumerablePropertySource<>("enumerable") {
132+
propertySources.addFirst(new PlainPropertySource<>("plain"));
133+
propertySources.addFirst(new OneBootstrap<>(new EnumerablePropertySource<>("enumerable") {
132134
@Override
133135
public String[] getPropertyNames() {
134136
return new String[0];
@@ -143,11 +145,38 @@ public Object getProperty(String name) {
143145

144146
List<? extends PropertySource> result = ConfigReloadUtil.findPropertySources(PlainPropertySource.class,
145147
environment);
148+
146149
Assertions.assertThat(result.size()).isEqualTo(4);
147150
Assertions.assertThat(result.get(0).getProperty("a")).isEqualTo("b");
148151
Assertions.assertThat(result.get(1).getProperty("")).isEqualTo("plain");
149152
Assertions.assertThat(result.get(2).getProperty("")).isEqualTo("from-bootstrap");
150153
Assertions.assertThat(result.get(3).getProperty("")).isEqualTo("from-inner-two-composite");
154+
155+
}
156+
157+
@Test
158+
void testSecretsPropertySource() {
159+
MockEnvironment environment = new MockEnvironment();
160+
MutablePropertySources propertySources = environment.getPropertySources();
161+
propertySources.addFirst(new SecretsPropertySource(new SourceData("secret", Map.of("a", "b"))));
162+
163+
List<? extends PropertySource> result = ConfigReloadUtil.findPropertySources(PlainPropertySource.class,
164+
environment);
165+
assertThat(result.size()).isEqualTo(1);
166+
assertThat(result.get(0).getProperty("a")).isEqualTo("b");
167+
}
168+
169+
@Test
170+
void testBootstrapSecretsPropertySource() {
171+
MockEnvironment environment = new MockEnvironment();
172+
MutablePropertySources propertySources = environment.getPropertySources();
173+
propertySources
174+
.addFirst(new OneBootstrap<>(new SecretsPropertySource(new SourceData("secret", Map.of("a", "b")))));
175+
176+
List<? extends PropertySource> result = ConfigReloadUtil.findPropertySources(PlainPropertySource.class,
177+
environment);
178+
assertThat(result.size()).isEqualTo(1);
179+
assertThat(result.get(0).getProperty("a")).isEqualTo("b");
151180
}
152181

153182
private static final class OneComposite extends CompositePropertySource {
@@ -171,12 +200,12 @@ private TwoComposite() {
171200

172201
@Override
173202
public Collection<PropertySource<?>> getPropertySources() {
174-
return List.of(new PlainPropertySource("from-inner-two-composite"));
203+
return List.of(new PlainPropertySource<>("from-inner-two-composite"));
175204
}
176205

177206
}
178207

179-
private static final class PlainPropertySource extends PropertySource<String> {
208+
private static final class PlainPropertySource<T> extends PropertySource<T> {
180209

181210
private PlainPropertySource(String name) {
182211
super(name);
@@ -189,15 +218,18 @@ public Object getProperty(String name) {
189218

190219
}
191220

192-
private static final class OneBootstrap extends BootstrapPropertySource<String> {
221+
private static final class OneBootstrap<T> extends BootstrapPropertySource<T> {
222+
223+
private final EnumerablePropertySource<T> delegate;
193224

194-
private OneBootstrap(EnumerablePropertySource<String> delegate) {
225+
private OneBootstrap(EnumerablePropertySource<T> delegate) {
195226
super(delegate);
227+
this.delegate = delegate;
196228
}
197229

198230
@Override
199-
public PropertySource<String> getDelegate() {
200-
return new PlainPropertySource("from-bootstrap");
231+
public PropertySource<T> getDelegate() {
232+
return delegate;
201233
}
202234

203235
}

spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/discovery/Fabric8DiscoveryFilterIT.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,16 @@ void beforeEach() {
5151
util.createNamespace(NAMESPACE_A_UAT);
5252
util.createNamespace(NAMESPACE_B_UAT);
5353

54-
util.wiremock(NAMESPACE_A_UAT, Phase.CREATE);
55-
util.wiremock(NAMESPACE_B_UAT, Phase.CREATE);
54+
util.wiremock(NAMESPACE_A_UAT, Phase.CREATE, false);
55+
util.wiremock(NAMESPACE_B_UAT, Phase.CREATE, false);
5656

5757
}
5858

5959
@AfterEach
6060
void afterEach() {
6161

62-
util.wiremock(NAMESPACE_A_UAT, Phase.DELETE);
63-
util.wiremock(NAMESPACE_B_UAT, Phase.DELETE);
62+
util.wiremock(NAMESPACE_A_UAT, Phase.DELETE, false);
63+
util.wiremock(NAMESPACE_B_UAT, Phase.DELETE, false);
6464

6565
util.deleteNamespace(NAMESPACE_A_UAT);
6666
util.deleteNamespace(NAMESPACE_B_UAT);

spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-k8s-client-configuration-watcher/src/test/java/org/springframework/cloud/kubernetes/configuration/watcher/ActuatorRefreshIT.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@
4444
*/
4545
class ActuatorRefreshIT {
4646

47-
private static final String WIREMOCK_PATH = "/";
48-
4947
private static final String NAMESPACE = "default";
5048

5149
private static final K3sContainer K3S = Commons.container();
@@ -72,12 +70,12 @@ static void afterAll() {
7270

7371
@BeforeEach
7472
void setup() {
75-
util.wiremock(NAMESPACE, WIREMOCK_PATH, Phase.CREATE);
73+
util.wiremock(NAMESPACE, Phase.CREATE, true);
7674
}
7775

7876
@AfterEach
7977
void after() {
80-
util.wiremock(NAMESPACE, WIREMOCK_PATH, Phase.DELETE);
78+
util.wiremock(NAMESPACE, Phase.DELETE, true);
8179
}
8280

8381
/*
@@ -114,10 +112,10 @@ private static void configWatcher(Phase phase) {
114112
deployment.getSpec().getTemplate().getSpec().getContainers().get(0).setEnv(envVars);
115113

116114
if (phase.equals(Phase.CREATE)) {
117-
util.createAndWait(NAMESPACE, null, deployment, service, null, true);
115+
util.createAndWait(NAMESPACE, null, deployment, service, true);
118116
}
119117
else {
120-
util.deleteAndWait(NAMESPACE, deployment, service, null);
118+
util.deleteAndWait(NAMESPACE, deployment, service);
121119
}
122120

123121
}

spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-k8s-client-configuration-watcher/src/test/java/org/springframework/cloud/kubernetes/configuration/watcher/ActuatorRefreshMultipleNamespacesIT.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ static void beforeAll() throws Exception {
6060
util = new Util(K3S);
6161
util.createNamespace(LEFT_NAMESPACE);
6262
util.createNamespace(RIGHT_NAMESPACE);
63-
util.wiremock(DEFAULT_NAMESPACE, "/", Phase.CREATE);
63+
util.wiremock(DEFAULT_NAMESPACE, Phase.CREATE, true);
6464
util.setUpClusterWide(DEFAULT_NAMESPACE, Set.of(DEFAULT_NAMESPACE, LEFT_NAMESPACE, RIGHT_NAMESPACE));
6565
configWatcher(Phase.CREATE);
6666
}
6767

6868
@AfterAll
6969
static void afterAll() {
7070
configWatcher(Phase.DELETE);
71-
util.wiremock(DEFAULT_NAMESPACE, "/", Phase.DELETE);
71+
util.wiremock(DEFAULT_NAMESPACE, Phase.DELETE, true);
7272
util.deleteClusterWide(DEFAULT_NAMESPACE, Set.of(DEFAULT_NAMESPACE, LEFT_NAMESPACE, RIGHT_NAMESPACE));
7373
util.deleteNamespace(LEFT_NAMESPACE);
7474
util.deleteNamespace(RIGHT_NAMESPACE);
@@ -128,10 +128,10 @@ private static void configWatcher(Phase phase) {
128128
.yaml("config-watcher/spring-cloud-kubernetes-configuration-watcher-service.yaml");
129129

130130
if (phase.equals(Phase.CREATE)) {
131-
util.createAndWait(DEFAULT_NAMESPACE, null, deployment, service, null, true);
131+
util.createAndWait(DEFAULT_NAMESPACE, null, deployment, service, true);
132132
}
133133
else {
134-
util.deleteAndWait(DEFAULT_NAMESPACE, deployment, service, null);
134+
util.deleteAndWait(DEFAULT_NAMESPACE, deployment, service);
135135
}
136136

137137
}

spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-k8s-client-configuration-watcher/src/test/java/org/springframework/cloud/kubernetes/configuration/watcher/TestUtil.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ final class TestUtil {
4646

4747
private static final String WIREMOCK_HOST = "localhost";
4848

49-
private static final int WIREMOCK_PORT = 80;
49+
private static final int WIREMOCK_PORT = 32321;
5050

5151
static final String SPRING_CLOUD_K8S_CONFIG_WATCHER_APP_NAME = "spring-cloud-kubernetes-configuration-watcher";
5252

@@ -60,7 +60,7 @@ static void configureWireMock() {
6060
// is ready to take a request via 'Wiremock::stubFor' (because sometimes it fails)
6161
// As such, get the existing mappings and retrySpec() makes sure we retry until
6262
// we get a response back.
63-
WebClient client = builder().baseUrl("http://localhost:80/__admin/mappings").build();
63+
WebClient client = builder().baseUrl("http://localhost:32321/__admin/mappings").build();
6464
client.method(HttpMethod.GET).retrieve().bodyToMono(String.class).retryWhen(retrySpec()).block();
6565

6666
StubMapping stubMapping = WireMock.stubFor(WireMock.post(WireMock.urlEqualTo("/actuator/refresh"))

spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-k8s-client-discovery-server/src/test/java/org/springframework/cloud/kubernetes/discoveryclient/it/DiscoveryServerClientBase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ protected static void discoveryServer(Phase phase) {
9393
V1Service service = (V1Service) util.yaml("manifests/discoveryserver-service.yaml");
9494

9595
if (phase.equals(Phase.CREATE)) {
96-
util.createAndWait(NAMESPACE, null, deployment, service, null, true);
96+
util.createAndWait(NAMESPACE, null, deployment, service, true);
9797
}
9898
else {
99-
util.deleteAndWait(NAMESPACE, deployment, service, null);
99+
util.deleteAndWait(NAMESPACE, deployment, service);
100100
}
101101
}
102102

spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-k8s-client-discovery-server/src/test/java/org/springframework/cloud/kubernetes/discoveryclient/it/DiscoveryServerClientIT.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,17 @@ static void beforeAllLocal() throws Exception {
7878
discoveryServer(Phase.CREATE);
7979

8080
Images.loadWiremock(K3S);
81-
util.wiremock(NAMESPACE_LEFT, "/wiremock-" + NAMESPACE_LEFT, Phase.CREATE, false);
82-
util.wiremock(NAMESPACE_RIGHT, "/wiremock-" + NAMESPACE_RIGHT, Phase.CREATE, false);
81+
util.wiremock(NAMESPACE_LEFT, Phase.CREATE, false);
82+
util.wiremock(NAMESPACE_RIGHT, Phase.CREATE, false);
8383
}
8484

8585
@AfterAll
8686
static void afterAllLocal() {
8787
serviceAccount(Phase.DELETE);
8888
discoveryServer(Phase.DELETE);
8989

90-
util.wiremock(NAMESPACE_LEFT, "/wiremock-" + NAMESPACE_LEFT, Phase.DELETE, false);
91-
util.wiremock(NAMESPACE_RIGHT, "/wiremock-" + NAMESPACE_RIGHT, Phase.DELETE, false);
90+
util.wiremock(NAMESPACE_LEFT, Phase.DELETE, false);
91+
util.wiremock(NAMESPACE_RIGHT, Phase.DELETE, false);
9292

9393
util.deleteNamespace(NAMESPACE_LEFT);
9494
util.deleteNamespace(NAMESPACE_RIGHT);

spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-k8s-client-discovery/src/test/java/org/springframework/cloud/kubernetes/k8s/client/discovery/KubernetesClientBlockingIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ class KubernetesClientBlockingIT extends KubernetesClientDiscoveryBase {
6060
@BeforeEach
6161
void beforeEach() {
6262
Images.loadWiremock(K3S);
63-
util.wiremock(NAMESPACE, "/", Phase.CREATE);
63+
util.wiremock(NAMESPACE, Phase.CREATE, true);
6464
}
6565

6666
@AfterEach
6767
void afterEach() {
68-
util.wiremock(NAMESPACE, "/", Phase.DELETE);
68+
util.wiremock(NAMESPACE, Phase.DELETE, true);
6969
}
7070

7171
/**

spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-k8s-client-discovery/src/test/java/org/springframework/cloud/kubernetes/k8s/client/discovery/KubernetesClientDiscoveryFilterIT.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@ void beforeEach() {
6363
util.createNamespace(NAMESPACE_B_UAT);
6464

6565
Images.loadWiremock(K3S);
66-
util.wiremock(NAMESPACE_A_UAT, "/", Phase.CREATE);
67-
util.wiremock(NAMESPACE_B_UAT, "/", Phase.CREATE);
66+
util.wiremock(NAMESPACE_A_UAT, Phase.CREATE, false);
67+
util.wiremock(NAMESPACE_B_UAT, Phase.CREATE, false);
6868
}
6969

7070
@AfterEach
7171
void afterEach() {
72-
util.wiremock(NAMESPACE_A_UAT, "/", Phase.DELETE);
73-
util.wiremock(NAMESPACE_B_UAT, "/", Phase.DELETE);
72+
util.wiremock(NAMESPACE_A_UAT, Phase.DELETE, false);
73+
util.wiremock(NAMESPACE_B_UAT, Phase.DELETE, false);
7474

7575
util.deleteNamespace(NAMESPACE_A_UAT);
7676
util.deleteNamespace(NAMESPACE_B_UAT);

0 commit comments

Comments
 (0)