Skip to content

Commit 1f67050

Browse files
committed
merge 3.1.x
Signed-off-by: wind57 <[email protected]>
2 parents 956628c + ec38be1 commit 1f67050

21 files changed

+745
-2340
lines changed

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

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111

1212
<artifactId>spring-cloud-kubernetes-k8s-client-discovery</artifactId>
1313

14+
<properties>
15+
<spring-boot.repackage.skip>true</spring-boot.repackage.skip>
16+
<spring-boot.build-image.skip>true</spring-boot.build-image.skip>
17+
</properties>
18+
1419
<dependencies>
1520
<dependency>
1621
<groupId>org.springframework.cloud</groupId>
@@ -41,17 +46,5 @@
4146
</dependency>
4247

4348
</dependencies>
44-
<build>
45-
<resources>
46-
<resource>
47-
<directory>../src/main/resources</directory>
48-
<filtering>true</filtering>
49-
</resource>
50-
<resource>
51-
<directory>src/main/resources</directory>
52-
<filtering>true</filtering>
53-
</resource>
54-
</resources>
55-
</build>
5649

5750
</project>

spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-k8s-client-discovery/src/main/java/org/springframework/cloud/kubernetes/k8s/client/discovery/DiscoveryApp.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2023 the original author or authors.
2+
* Copyright 2013-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,7 +23,7 @@
2323
* @author wind57
2424
*/
2525
@SpringBootApplication
26-
public class DiscoveryApp {
26+
class DiscoveryApp {
2727

2828
public static void main(String[] args) {
2929
SpringApplication.run(DiscoveryApp.class, args);

spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-k8s-client-discovery/src/main/java/org/springframework/cloud/kubernetes/k8s/client/discovery/DiscoveryApplicationListener.java

Lines changed: 0 additions & 44 deletions
This file was deleted.

spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-k8s-client-discovery/src/main/java/org/springframework/cloud/kubernetes/k8s/client/discovery/DiscoveryController.java

Lines changed: 0 additions & 52 deletions
This file was deleted.

spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-k8s-client-discovery/src/main/java/org/springframework/cloud/kubernetes/k8s/client/discovery/ReactiveDiscoveryController.java

Lines changed: 0 additions & 55 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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.k8s.client.discovery;
18+
19+
import java.util.Set;
20+
21+
import io.kubernetes.client.openapi.ApiClient;
22+
import org.junit.jupiter.api.AfterEach;
23+
import org.junit.jupiter.api.BeforeEach;
24+
import org.junit.jupiter.api.Test;
25+
26+
import org.springframework.beans.factory.annotation.Autowired;
27+
import org.springframework.boot.test.context.SpringBootTest;
28+
import org.springframework.boot.test.context.TestConfiguration;
29+
import org.springframework.boot.test.system.CapturedOutput;
30+
import org.springframework.boot.test.web.server.LocalManagementPort;
31+
import org.springframework.cloud.client.discovery.DiscoveryClient;
32+
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
33+
import org.springframework.cloud.kubernetes.integration.tests.commons.Images;
34+
import org.springframework.cloud.kubernetes.integration.tests.commons.Phase;
35+
import org.springframework.context.annotation.Bean;
36+
import org.springframework.context.annotation.Primary;
37+
import org.springframework.test.context.TestPropertySource;
38+
39+
import static org.springframework.cloud.kubernetes.k8s.client.discovery.TestAssertions.assertBlockingConfiguration;
40+
import static org.springframework.cloud.kubernetes.k8s.client.discovery.TestAssertions.assertPodMetadata;
41+
42+
/**
43+
* @author wind57
44+
*/
45+
@SpringBootTest(classes = { DiscoveryApp.class, KubernetesClientBlockingIT.TestConfig.class },
46+
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
47+
@TestPropertySource(
48+
properties = { "spring.cloud.discovery.reactive.enabled=false", "spring.cloud.discovery.blocking.enabled=true",
49+
"logging.level.org.springframework.cloud.kubernetes.commons.discovery=debug",
50+
"logging.level.org.springframework.cloud.client.discovery.health=debug",
51+
"logging.level.org.springframework.cloud.kubernetes.client.discovery=debug" })
52+
class KubernetesClientBlockingIT extends KubernetesClientDiscoveryBase {
53+
54+
@LocalManagementPort
55+
private int port;
56+
57+
@Autowired
58+
private DiscoveryClient discoveryClient;
59+
60+
@BeforeEach
61+
void beforeEach() {
62+
Images.loadWiremock(K3S);
63+
util.wiremock(NAMESPACE, "/", Phase.CREATE);
64+
}
65+
66+
@AfterEach
67+
void afterEach() {
68+
util.wiremock(NAMESPACE, "/", Phase.DELETE);
69+
}
70+
71+
/**
72+
* <pre>
73+
*
74+
* Reactive is disabled, only blocking is active. As such,
75+
* We assert for logs and call '/health' endpoint to see that blocking discovery
76+
* client was initialized.
77+
*
78+
* </pre>
79+
*/
80+
@Test
81+
void test(CapturedOutput output) {
82+
assertBlockingConfiguration(output, port);
83+
assertPodMetadata(discoveryClient);
84+
}
85+
86+
@TestConfiguration
87+
static class TestConfig {
88+
89+
@Bean
90+
@Primary
91+
ApiClient client() {
92+
return apiClient();
93+
}
94+
95+
@Bean
96+
@Primary
97+
KubernetesDiscoveryProperties kubernetesDiscoveryProperties() {
98+
return discoveryProperties(false, Set.of(NAMESPACE), null);
99+
}
100+
101+
}
102+
103+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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.k8s.client.discovery;
18+
19+
import java.io.IOException;
20+
import java.io.StringReader;
21+
import java.util.Map;
22+
import java.util.Set;
23+
24+
import io.kubernetes.client.openapi.ApiClient;
25+
import io.kubernetes.client.openapi.apis.CoreV1Api;
26+
import io.kubernetes.client.util.Config;
27+
import org.junit.jupiter.api.BeforeAll;
28+
import org.junit.jupiter.api.extension.ExtendWith;
29+
import org.testcontainers.k3s.K3sContainer;
30+
31+
import org.springframework.boot.test.system.OutputCaptureExtension;
32+
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
33+
import org.springframework.cloud.kubernetes.integration.tests.commons.Commons;
34+
import org.springframework.cloud.kubernetes.integration.tests.commons.native_client.Util;
35+
import org.springframework.test.context.TestPropertySource;
36+
37+
/**
38+
* @author wind57
39+
*/
40+
@TestPropertySource(properties = { "spring.main.cloud-platform=kubernetes",
41+
"spring.cloud.config.import-check.enabled=false", "spring.cloud.kubernetes.client.namespace=default",
42+
"spring.cloud.kubernetes.discovery.metadata.add-pod-labels=true",
43+
"spring.cloud.kubernetes.discovery.metadata.add-pod-annotations=true",
44+
"logging.level.org.springframework.cloud.kubernetes.client.discovery=debug" })
45+
@ExtendWith(OutputCaptureExtension.class)
46+
abstract class KubernetesClientDiscoveryBase {
47+
48+
protected static final String NAMESPACE = "default";
49+
50+
protected static final K3sContainer K3S = Commons.container();
51+
52+
protected static Util util;
53+
54+
@BeforeAll
55+
protected static void beforeAll() {
56+
K3S.start();
57+
util = new Util(K3S);
58+
}
59+
60+
protected static ApiClient apiClient() {
61+
String kubeConfigYaml = K3S.getKubeConfigYaml();
62+
63+
ApiClient client;
64+
try {
65+
client = Config.fromConfig(new StringReader(kubeConfigYaml));
66+
}
67+
catch (IOException e) {
68+
throw new RuntimeException(e);
69+
}
70+
return new CoreV1Api(client).getApiClient();
71+
}
72+
73+
protected static KubernetesDiscoveryProperties discoveryProperties(boolean useEndpointSlices,
74+
Set<String> namespaces, String filter) {
75+
KubernetesDiscoveryProperties.Metadata metadata = new KubernetesDiscoveryProperties.Metadata(true, null, true,
76+
null, true, "port.", true, true);
77+
return new KubernetesDiscoveryProperties(true, false, namespaces, true, 60, false, filter, Set.of(443, 8443),
78+
Map.of(), null, metadata, 0, useEndpointSlices, true, null);
79+
}
80+
81+
}

0 commit comments

Comments
 (0)