Skip to content

Commit f9a678c

Browse files
committed
2 parents dd24a07 + e19e3e7 commit f9a678c

File tree

33 files changed

+883
-2433
lines changed

33 files changed

+883
-2433
lines changed

docs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
"@antora/collector-extension": "1.0.1",
66
"@asciidoctor/tabs": "1.0.0-beta.6",
77
"@springio/antora-extensions": "1.14.2",
8-
"@springio/asciidoctor-extensions": "1.0.0-alpha.14"
8+
"@springio/asciidoctor-extensions": "1.0.0-alpha.16"
99
}
1010
}

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,10 +339,11 @@ public static <T> void registerSingle(ConfigurableBootstrapContext bootstrapCont
339339
String name, ApplicationListener<?> listener) {
340340
bootstrapContext.registerIfAbsent(cls, BootstrapRegistry.InstanceSupplier.of(instance));
341341
bootstrapContext.addCloseListener(event -> {
342-
if (event.getApplicationContext().getBeanFactory().getSingleton(name) == null) {
343-
event.getApplicationContext()
344-
.getBeanFactory()
345-
.registerSingleton(name, event.getBootstrapContext().get(cls));
342+
343+
T singleton = event.getBootstrapContext().get(cls);
344+
345+
if (event.getApplicationContext().getBeanFactory().getSingleton(name) == null && singleton != null) {
346+
event.getApplicationContext().getBeanFactory().registerSingleton(name, singleton);
346347
event.getApplicationContext().addApplicationListener(listener);
347348
}
348349
});

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
public abstract class KubernetesConfigDataLocationResolver
5353
implements ConfigDataLocationResolver<KubernetesConfigDataResource>, Ordered {
5454

55+
private static final Class<KubernetesClientProperties> PROPERTIES_CLASS = KubernetesClientProperties.class;
56+
5557
private static final boolean RETRY_IS_PRESENT = isPresent("org.springframework.retry.annotation.Retryable", null);
5658

5759
private final Log log;
@@ -139,8 +141,7 @@ private void registerProperties(ConfigDataLocationResolverContext resolverContex
139141
SecretsConfigProperties secretsProperties) {
140142

141143
ConfigurableBootstrapContext bootstrapContext = resolverContext.getBootstrapContext();
142-
registerSingle(bootstrapContext, KubernetesClientProperties.class, clientProperties,
143-
"configDataKubernetesClientProperties");
144+
registerSingle(bootstrapContext, PROPERTIES_CLASS, clientProperties, "configDataKubernetesClientProperties");
144145

145146
if (configMapProperties != null) {
146147
registerSingle(bootstrapContext, ConfigMapConfigProperties.class, configMapProperties,
@@ -174,15 +175,14 @@ private static PropertyHolder of(ConfigDataLocationResolverContext context) {
174175
private static KubernetesClientProperties clientProperties(ConfigDataLocationResolverContext context,
175176
String namespace) {
176177
KubernetesClientProperties kubernetesClientProperties;
178+
ConfigurableBootstrapContext bootstrapContext = context.getBootstrapContext();
177179

178-
if (context.getBootstrapContext().isRegistered(KubernetesClientProperties.class)) {
179-
kubernetesClientProperties = context.getBootstrapContext()
180-
.get(KubernetesClientProperties.class)
181-
.withNamespace(namespace);
180+
if (bootstrapContext.isRegistered(PROPERTIES_CLASS) && bootstrapContext.get(PROPERTIES_CLASS) != null) {
181+
kubernetesClientProperties = bootstrapContext.get(PROPERTIES_CLASS).withNamespace(namespace);
182182
}
183183
else {
184184
kubernetesClientProperties = context.getBinder()
185-
.bindOrCreate(KubernetesClientProperties.PREFIX, Bindable.of(KubernetesClientProperties.class))
185+
.bindOrCreate(KubernetesClientProperties.PREFIX, Bindable.of(PROPERTIES_CLASS))
186186
.withNamespace(namespace);
187187
}
188188

spring-cloud-kubernetes-dependencies/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
<properties>
3535
<kubernetes-fabric8-client.version>6.13.5</kubernetes-fabric8-client.version>
3636
<kubernetes-native-client.version>19.0.2</kubernetes-native-client.version>
37-
<wiremock.version>3.9.1</wiremock.version>
37+
<wiremock.version>3.9.2</wiremock.version>
3838
</properties>
3939
<dependencyManagement>
4040
<dependencies>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2013-2025 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;
18+
19+
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
20+
import org.springframework.boot.context.config.ConfigDataLocation;
21+
import org.springframework.boot.context.config.ConfigDataLocationResolverContext;
22+
import org.springframework.boot.context.config.Profiles;
23+
import org.springframework.boot.logging.DeferredLogFactory;
24+
import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider;
25+
import org.springframework.cloud.kubernetes.commons.config.KubernetesConfigDataLocationResolver;
26+
27+
/**
28+
* @author wind57
29+
*/
30+
@ConditionalOnProperty(value = "dummy.config.loader.enabled", havingValue = "true", matchIfMissing = false)
31+
class DummyConfigDataLocationResolver extends KubernetesConfigDataLocationResolver {
32+
33+
DummyConfigDataLocationResolver(DeferredLogFactory factory) {
34+
super(factory);
35+
}
36+
37+
@Override
38+
protected void registerBeans(ConfigDataLocationResolverContext resolverContext, ConfigDataLocation location,
39+
Profiles profiles, PropertyHolder propertyHolder, KubernetesNamespaceProvider namespaceProvider) {
40+
41+
}
42+
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Copyright 2013-2025 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.fabric8.discovery;
18+
19+
import com.github.tomakehurst.wiremock.WireMockServer;
20+
import com.github.tomakehurst.wiremock.client.WireMock;
21+
import org.assertj.core.api.Assertions;
22+
import org.junit.jupiter.api.AfterAll;
23+
import org.junit.jupiter.api.BeforeAll;
24+
import org.junit.jupiter.api.Test;
25+
26+
import org.springframework.beans.factory.annotation.Autowired;
27+
import org.springframework.boot.autoconfigure.SpringBootApplication;
28+
import org.springframework.boot.test.context.SpringBootTest;
29+
import org.springframework.context.ApplicationContext;
30+
31+
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
32+
import static com.github.tomakehurst.wiremock.client.WireMock.get;
33+
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
34+
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
35+
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
36+
37+
/**
38+
* Test that proves that this
39+
* <a href="https://github.com/spring-cloud/spring-cloud-kubernetes/issues/1831">issue</a>
40+
* is fixed.
41+
*
42+
* @author wind57
43+
*/
44+
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
45+
properties = { "spring.main.cloud-platform=KUBERNETES",
46+
"spring.config.import=kubernetes:, optional:configserver:", "dummy.config.loader.enabled=true" })
47+
class Fabric8ConfigServerTest {
48+
49+
private static WireMockServer wireMockServer;
50+
51+
@Autowired
52+
private ApplicationContext applicationContext;
53+
54+
@BeforeAll
55+
static void beforeAll() {
56+
wireMockServer = new WireMockServer(options().port(8888));
57+
wireMockServer.start();
58+
WireMock.configureFor("localhost", wireMockServer.port());
59+
}
60+
61+
@AfterAll
62+
static void after() {
63+
WireMock.shutdownServer();
64+
wireMockServer.stop();
65+
}
66+
67+
@Test
68+
void test() {
69+
stubFor(get(urlEqualTo("/application/default")).willReturn(aResponse().withStatus(200).withBody("{}")));
70+
Assertions.assertThat(applicationContext).isNotNull();
71+
}
72+
73+
@SpringBootApplication
74+
protected static class TestConfig {
75+
76+
}
77+
78+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
org.springframework.boot.context.config.ConfigDataLocationResolver=\
2+
org.springframework.cloud.kubernetes.DummyConfigDataLocationResolver

spring-cloud-kubernetes-fabric8-leader/src/test/java/org/springframework/cloud/kubernetes/fabric8/leader/Fabric8LeaderInitiatorTest.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import java.time.Duration;
2020

21-
import org.awaitility.Awaitility;
2221
import org.junit.jupiter.api.AfterEach;
2322
import org.junit.jupiter.api.BeforeEach;
2423
import org.junit.jupiter.api.Test;
@@ -77,14 +76,6 @@ void shouldStart() {
7776
assertThat(leaderInitiator.isRunning()).isTrue();
7877
verify(mockFabric8LeaderRecordWatcher).start();
7978
verify(mockFabric8PodReadinessWatcher).start();
80-
boolean[] updateCalled = new boolean[1];
81-
Mockito.doAnswer(x -> {
82-
updateCalled[0] = true;
83-
return null;
84-
}).when(mockFabric8LeadershipController).update();
85-
86-
Awaitility.await().atMost(Duration.ofSeconds(3)).until(() -> updateCalled[0]);
87-
8879
verify(mockFabric8LeadershipController, atLeastOnce()).update();
8980
}
9081

spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/pom.xml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,4 @@
3636
</dependency>
3737

3838
</dependencies>
39-
<build>
40-
<resources>
41-
<resource>
42-
<directory>../src/main/resources</directory>
43-
<filtering>true</filtering>
44-
</resource>
45-
<resource>
46-
<directory>src/main/resources</directory>
47-
<filtering>true</filtering>
48-
</resource>
49-
</resources>
50-
</build>
5139
</project>

spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/pom.xml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,5 @@
4444
</dependency>
4545

4646
</dependencies>
47-
<build>
48-
<resources>
49-
<resource>
50-
<directory>../src/main/resources</directory>
51-
<filtering>true</filtering>
52-
</resource>
53-
<resource>
54-
<directory>src/main/resources</directory>
55-
<filtering>true</filtering>
56-
</resource>
57-
</resources>
58-
</build>
5947

6048
</project>

0 commit comments

Comments
 (0)