Skip to content

Commit 2d7cbda

Browse files
committed
Merge branch '3.1.x'
2 parents 6495f46 + d29c69b commit 2d7cbda

24 files changed

+913
-1371
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,21 @@
5050
<filtering>true</filtering>
5151
</resource>
5252
</resources>
53+
54+
<plugins>
55+
<plugin>
56+
<groupId>org.springframework.boot</groupId>
57+
<artifactId>spring-boot-maven-plugin</artifactId>
58+
<executions>
59+
<execution>
60+
<id>build-image</id>
61+
<configuration>
62+
<skip>true</skip>
63+
</configuration>
64+
</execution>
65+
</executions>
66+
</plugin>
67+
</plugins>
5368
</build>
5469

5570
</project>

spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/client/discovery/Fabric8ApplicationDiscoveryListener.java

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

spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/client/discovery/Fabric8DiscoveryApp.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* @author wind57
2424
*/
2525
@SpringBootApplication
26-
public class Fabric8DiscoveryApp {
26+
class Fabric8DiscoveryApp {
2727

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

spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/client/discovery/Fabric8DiscoveryController.java

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

spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/client/discovery/Fabric8ReactiveDiscoveryController.java

Lines changed: 0 additions & 55 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/*
2+
* Copyright 2012-2024 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.client.discovery;
18+
19+
import java.io.InputStream;
20+
21+
import io.fabric8.kubernetes.api.model.Service;
22+
import io.fabric8.kubernetes.client.utils.Serialization;
23+
import org.junit.jupiter.api.AfterEach;
24+
import org.junit.jupiter.api.BeforeAll;
25+
import org.junit.jupiter.api.BeforeEach;
26+
import org.junit.jupiter.api.Nested;
27+
import org.junit.jupiter.api.Test;
28+
29+
import org.springframework.beans.factory.annotation.Autowired;
30+
import org.springframework.cloud.client.discovery.DiscoveryClient;
31+
import org.springframework.cloud.kubernetes.integration.tests.commons.Images;
32+
import org.springframework.cloud.kubernetes.integration.tests.commons.Phase;
33+
import org.springframework.test.context.TestPropertySource;
34+
35+
import static org.springframework.cloud.kubernetes.fabric8.client.discovery.TestAssertions.assertAllServices;
36+
37+
/**
38+
* @author wind57
39+
*/
40+
class Fabric8DiscoveryAllServicesIT extends Fabric8DiscoveryBase {
41+
42+
private static Service externalServiceName;
43+
44+
@BeforeAll
45+
static void beforeAllInNested() {
46+
InputStream externalNameServiceStream = util.inputStream("external-name-service.yaml");
47+
externalServiceName = Serialization.unmarshal(externalNameServiceStream, Service.class);
48+
}
49+
50+
private void externalNameServices(Phase phase) {
51+
if (phase == Phase.CREATE) {
52+
util.createAndWait(NAMESPACE, null, null, externalServiceName, null, true);
53+
}
54+
else {
55+
util.deleteAndWait(NAMESPACE, null, externalServiceName, null);
56+
}
57+
}
58+
59+
@Nested
60+
@TestPropertySource(properties = { "spring.cloud.kubernetes.discovery.include-external-name-services=true" })
61+
class NonBootstrap {
62+
63+
@Autowired
64+
private DiscoveryClient discoveryClient;
65+
66+
@BeforeEach
67+
void beforeEach() {
68+
Images.loadBusybox(K3S);
69+
util.busybox(NAMESPACE, Phase.CREATE);
70+
externalNameServices(Phase.CREATE);
71+
}
72+
73+
@AfterEach
74+
void afterEach() {
75+
util.busybox(NAMESPACE, Phase.DELETE);
76+
externalNameServices(Phase.DELETE);
77+
}
78+
79+
/**
80+
* <pre>
81+
* - there are 3 services : 'busybox-service', 'kubernetes', 'external-name-service'
82+
* - all of them are found
83+
* </pre>
84+
*/
85+
@Test
86+
void test() {
87+
assertAllServices(discoveryClient);
88+
}
89+
90+
}
91+
92+
@Nested
93+
@TestPropertySource(properties = { "spring.cloud.kubernetes.discovery.include-external-name-services=true",
94+
"spring.cloud.bootstrap.enabled=true" })
95+
class Bootstrap {
96+
97+
@Autowired
98+
private DiscoveryClient discoveryClient;
99+
100+
@BeforeEach
101+
void beforeEach() {
102+
Images.loadBusybox(K3S);
103+
util.busybox(NAMESPACE, Phase.CREATE);
104+
externalNameServices(Phase.CREATE);
105+
}
106+
107+
@AfterEach
108+
void afterEach() {
109+
util.busybox(NAMESPACE, Phase.DELETE);
110+
externalNameServices(Phase.DELETE);
111+
}
112+
113+
/**
114+
* <pre>
115+
* - there are 3 services : 'busybox-service', 'kubernetes', 'external-name-service'
116+
* - all of them are found
117+
* </pre>
118+
*/
119+
@Test
120+
void test() {
121+
assertAllServices(discoveryClient);
122+
}
123+
124+
}
125+
126+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Copyright 2012-2024 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.client.discovery;
18+
19+
import io.fabric8.kubernetes.client.Config;
20+
import io.fabric8.kubernetes.client.KubernetesClient;
21+
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
22+
import org.junit.jupiter.api.BeforeAll;
23+
import org.junit.jupiter.api.extension.ExtendWith;
24+
import org.testcontainers.k3s.K3sContainer;
25+
26+
import org.springframework.boot.test.context.SpringBootTest;
27+
import org.springframework.boot.test.context.TestConfiguration;
28+
import org.springframework.boot.test.system.OutputCaptureExtension;
29+
import org.springframework.cloud.kubernetes.integration.tests.commons.Commons;
30+
import org.springframework.cloud.kubernetes.integration.tests.commons.fabric8_client.Util;
31+
import org.springframework.context.annotation.Bean;
32+
import org.springframework.context.annotation.Primary;
33+
import org.springframework.test.context.TestPropertySource;
34+
35+
/**
36+
* @author wind57
37+
*/
38+
@TestPropertySource(properties = { "spring.main.cloud-platform=kubernetes",
39+
"spring.cloud.config.import-check.enabled=false", "spring.cloud.kubernetes.client.namespace=default",
40+
"spring.cloud.kubernetes.discovery.metadata.add-pod-labels=true",
41+
"spring.cloud.kubernetes.discovery.metadata.add-pod-annotations=true",
42+
"logging.level.org.springframework.cloud.kubernetes.fabric8.discovery=debug" })
43+
@ExtendWith(OutputCaptureExtension.class)
44+
@SpringBootTest(classes = { Fabric8DiscoveryApp.class, Fabric8DiscoveryBase.TestConfig.class },
45+
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
46+
abstract class Fabric8DiscoveryBase {
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 KubernetesClient client() {
61+
String kubeConfigYaml = K3S.getKubeConfigYaml();
62+
Config config = Config.fromKubeconfig(kubeConfigYaml);
63+
return new KubernetesClientBuilder().withConfig(config).build();
64+
}
65+
66+
@TestConfiguration
67+
static class TestConfig {
68+
69+
@Bean
70+
@Primary
71+
KubernetesClient kubernetesClient() {
72+
return client();
73+
}
74+
75+
}
76+
77+
}

0 commit comments

Comments
 (0)