Skip to content

Commit bf38b57

Browse files
authored
Fix 1338 main (#1344)
1 parent 66c1446 commit bf38b57

File tree

16 files changed

+378
-130
lines changed

16 files changed

+378
-130
lines changed

spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/RetryableKubernetesClientSourcesOrderTests.java

Lines changed: 0 additions & 80 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2013-2023 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.client.config.applications.sources_order;
18+
19+
import org.springframework.boot.test.context.SpringBootTest;
20+
21+
/**
22+
* @author wind57
23+
*/
24+
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = SourcesOrderApp.class,
25+
properties = { "spring.cloud.bootstrap.name=retryable-sources-order", "sources.order.stub=true",
26+
"spring.main.cloud-platform=KUBERNETES", "spring.cloud.bootstrap.enabled=true" })
27+
class BootstrapRetryableSourcesOrderTests extends SourcesOrderTests {
28+
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2013-2023 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.client.config.applications.sources_order;
18+
19+
import org.springframework.boot.test.context.SpringBootTest;
20+
21+
/**
22+
* @author wind57
23+
*/
24+
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = SourcesOrderApp.class,
25+
properties = { "spring.cloud.bootstrap.name=sources-order", "sources.order.stub=true",
26+
"spring.main.cloud-platform=KUBERNETES", "spring.cloud.bootstrap.enabled=true" })
27+
class BootstrapSourcesOrderTests extends SourcesOrderTests {
28+
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright 2013-2023 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.client.config.applications.sources_order;
18+
19+
import com.github.tomakehurst.wiremock.WireMockServer;
20+
import com.github.tomakehurst.wiremock.client.WireMock;
21+
import io.kubernetes.client.util.ClientBuilder;
22+
import org.junit.jupiter.api.AfterAll;
23+
import org.junit.jupiter.api.BeforeAll;
24+
import org.junit.jupiter.api.extension.ExtendWith;
25+
import org.mockito.MockedStatic;
26+
import org.mockito.Mockito;
27+
28+
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
29+
import org.springframework.boot.test.context.SpringBootTest;
30+
import org.springframework.cloud.kubernetes.client.KubernetesClientUtils;
31+
import org.springframework.test.context.junit.jupiter.SpringExtension;
32+
33+
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
34+
import static org.mockito.Mockito.mockStatic;
35+
import static org.springframework.cloud.kubernetes.client.config.boostrap.stubs.SourcesOrderConfigurationStub.stubConfigMapData;
36+
import static org.springframework.cloud.kubernetes.client.config.boostrap.stubs.SourcesOrderConfigurationStub.stubSecretsData;
37+
38+
/**
39+
* The stub data for this test is in :
40+
* {@link org.springframework.cloud.kubernetes.client.config.boostrap.stubs.SourcesOrderConfigurationStub}
41+
*
42+
* @author wind57
43+
*/
44+
@ExtendWith(SpringExtension.class)
45+
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = SourcesOrderApp.class,
46+
properties = { "spring.cloud.bootstrap.name=retryable-sources-order", "sources.order.stub=true",
47+
"spring.main.cloud-platform=KUBERNETES", "spring.cloud.bootstrap.enabled=true" })
48+
@AutoConfigureWebTestClient
49+
class ConfigDataRetryableSourcesOrderTests extends SourcesOrderTests {
50+
51+
private static MockedStatic<KubernetesClientUtils> clientUtilsMock;
52+
53+
@BeforeAll
54+
static void wireMock() {
55+
WireMockServer server = new WireMockServer(options().dynamicPort());
56+
server.start();
57+
WireMock.configureFor("localhost", server.port());
58+
clientUtilsMock = mockStatic(KubernetesClientUtils.class);
59+
clientUtilsMock.when(KubernetesClientUtils::kubernetesApiClient)
60+
.thenReturn(new ClientBuilder().setBasePath(server.baseUrl()).build());
61+
clientUtilsMock
62+
.when(() -> KubernetesClientUtils.getApplicationNamespace(Mockito.any(), Mockito.any(), Mockito.any()))
63+
.thenReturn("spring-k8s");
64+
stubConfigMapData();
65+
stubSecretsData();
66+
}
67+
68+
@AfterAll
69+
static void teardown() {
70+
clientUtilsMock.close();
71+
}
72+
73+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright 2013-2023 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.client.config.applications.sources_order;
18+
19+
import com.github.tomakehurst.wiremock.WireMockServer;
20+
import com.github.tomakehurst.wiremock.client.WireMock;
21+
import io.kubernetes.client.util.ClientBuilder;
22+
import org.junit.jupiter.api.AfterAll;
23+
import org.junit.jupiter.api.BeforeAll;
24+
import org.mockito.MockedStatic;
25+
import org.mockito.Mockito;
26+
27+
import org.springframework.boot.test.context.SpringBootTest;
28+
import org.springframework.cloud.kubernetes.client.KubernetesClientUtils;
29+
30+
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
31+
import static org.mockito.Mockito.mockStatic;
32+
import static org.springframework.cloud.kubernetes.client.config.boostrap.stubs.SourcesOrderConfigurationStub.stubConfigMapData;
33+
import static org.springframework.cloud.kubernetes.client.config.boostrap.stubs.SourcesOrderConfigurationStub.stubSecretsData;
34+
35+
/**
36+
* @author wind57
37+
*/
38+
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = SourcesOrderApp.class,
39+
properties = { "spring.cloud.application.name=sources-order", "sources.order.stub=true",
40+
"spring.main.cloud-platform=KUBERNETES",
41+
"spring.config.import=kubernetes:,classpath:./sources-order.yaml",
42+
"spring.cloud.kubernetes.client.namespace=spring-k8s" })
43+
class ConfigDataSourcesOrderTests extends SourcesOrderTests {
44+
45+
private static MockedStatic<KubernetesClientUtils> clientUtilsMock;
46+
47+
@BeforeAll
48+
static void wireMock() {
49+
WireMockServer server = new WireMockServer(options().dynamicPort());
50+
server.start();
51+
WireMock.configureFor("localhost", server.port());
52+
clientUtilsMock = mockStatic(KubernetesClientUtils.class);
53+
clientUtilsMock.when(KubernetesClientUtils::kubernetesApiClient)
54+
.thenReturn(new ClientBuilder().setBasePath(server.baseUrl()).build());
55+
clientUtilsMock
56+
.when(() -> KubernetesClientUtils.getApplicationNamespace(Mockito.any(), Mockito.any(), Mockito.any()))
57+
.thenReturn("spring-k8s");
58+
stubConfigMapData();
59+
stubSecretsData();
60+
}
61+
62+
@AfterAll
63+
static void teardown() {
64+
clientUtilsMock.close();
65+
}
66+
67+
}

spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientSourcesOrderTests.java renamed to spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/applications/sources_order/SourcesOrderTests.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.cloud.kubernetes.client.config;
17+
package org.springframework.cloud.kubernetes.client.config.applications.sources_order;
1818

1919
import com.github.tomakehurst.wiremock.client.WireMock;
2020
import org.hamcrest.Matchers;
@@ -26,7 +26,6 @@
2626
import org.springframework.beans.factory.annotation.Autowired;
2727
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
2828
import org.springframework.boot.test.context.SpringBootTest;
29-
import org.springframework.cloud.kubernetes.client.config.applications.sources_order.SourcesOrderApp;
3029
import org.springframework.test.context.junit.jupiter.SpringExtension;
3130
import org.springframework.test.web.reactive.server.WebTestClient;
3231

@@ -39,9 +38,9 @@
3938
@ExtendWith(SpringExtension.class)
4039
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = SourcesOrderApp.class,
4140
properties = { "spring.cloud.bootstrap.name=sources-order", "sources.order.stub=true",
42-
"spring.main.cloud-platform=KUBERNETES", "spring.cloud.bootstrap.enabled=true"})
41+
"spring.main.cloud-platform=KUBERNETES", "spring.cloud.bootstrap.enabled=true" })
4342
@AutoConfigureWebTestClient
44-
class KubernetesClientSourcesOrderTests {
43+
abstract class SourcesOrderTests {
4544

4645
@Autowired
4746
private WebTestClient webClient;

spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/boostrap/stubs/SourcesOrderConfigurationStub.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public ApiClient apiClient(WireMockServer wireMockServer) {
6464
return apiClient;
6565
}
6666

67-
private void stubConfigMapData() {
67+
public static void stubConfigMapData() {
6868

6969
Map<String, String> configMapData = new HashMap<>();
7070
configMapData.put("my.key", "from-configmap");
@@ -82,7 +82,7 @@ private void stubConfigMapData() {
8282
.willReturn(WireMock.aResponse().withStatus(200).withBody(new JSON().serialize(allConfigMaps))));
8383
}
8484

85-
private void stubSecretsData() {
85+
public static void stubSecretsData() {
8686

8787
Map<String, byte[]> secretData = new HashMap<>();
8888
secretData.put("my.key", "from-secret".getBytes(StandardCharsets.UTF_8));

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,14 @@ public ConfigData load(ConfigDataLoaderContext context, KubernetesConfigDataReso
4343
ConfigurableBootstrapContext bootstrapContext = context.getBootstrapContext();
4444
Environment env = resource.getEnvironment();
4545

46-
if (bootstrapContext.isRegistered(ConfigMapPropertySourceLocator.class)) {
47-
propertySources.add(bootstrapContext.get(ConfigMapPropertySourceLocator.class).locate(env));
48-
}
4946
if (bootstrapContext.isRegistered(SecretsPropertySourceLocator.class)) {
5047
propertySources.add(bootstrapContext.get(SecretsPropertySourceLocator.class).locate(env));
5148
}
5249

50+
if (bootstrapContext.isRegistered(ConfigMapPropertySourceLocator.class)) {
51+
propertySources.add(bootstrapContext.get(ConfigMapPropertySourceLocator.class).locate(env));
52+
}
53+
5354
// boot 2.4.5+
5455
return new ConfigData(propertySources, propertySource -> {
5556
String propertySourceName = propertySource.getName();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ void testBothRegistered() throws IOException {
137137
ConfigData configData = loader.load(CONTEXT, EMPTY_RESOURCE);
138138
Assertions.assertNotNull(configData);
139139
Assertions.assertEquals(2, configData.getPropertySources().size());
140-
Assertions.assertEquals("k8s-config-map", configData.getPropertySources().get(0).getName());
141-
Assertions.assertEquals("k8s-secrets", configData.getPropertySources().get(1).getName());
140+
Assertions.assertEquals("k8s-secrets", configData.getPropertySources().get(0).getName());
141+
Assertions.assertEquals("k8s-config-map", configData.getPropertySources().get(1).getName());
142142
}
143143

144144
}

spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/BootstrapConfigMapsWithProfileExpressionTests.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,29 @@
1919
import io.fabric8.kubernetes.client.KubernetesClient;
2020
import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient;
2121
import org.junit.jupiter.api.BeforeAll;
22-
import org.junit.jupiter.api.extension.ExtendWith;
2322

2423
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
2524
import org.springframework.boot.test.context.SpringBootTest;
2625
import org.springframework.cloud.kubernetes.fabric8.config.example.App;
2726
import org.springframework.test.context.ActiveProfiles;
28-
import org.springframework.test.context.junit.jupiter.SpringExtension;
2927

3028
/**
3129
* Tests reading property from YAML document specified by profile expression.
3230
*/
3331

34-
@ExtendWith(SpringExtension.class)
3532
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class,
3633
properties = { "spring.application.name=configmap-with-profile-example",
3734
"spring.cloud.kubernetes.reload.enabled=false", "spring.main.cloud-platform=KUBERNETES",
3835
"spring.cloud.bootstrap.enabled=true" })
3936
@ActiveProfiles({ "production", "us-east" })
4037
@AutoConfigureWebTestClient
4138
@EnableKubernetesMockClient(crud = true, https = false)
42-
public class BootstrapConfigMapsWithProfileExpressionTests extends ConfigMapsWithProfileExpressionTests {
39+
class BootstrapConfigMapsWithProfileExpressionTests extends ConfigMapsWithProfileExpressionTests {
4340

4441
private static KubernetesClient mockClient;
4542

4643
@BeforeAll
47-
public static void setUpBeforeClass() {
44+
static void setUpBeforeClass() {
4845
setUpBeforeClass(mockClient);
4946
}
5047

0 commit comments

Comments
 (0)