Skip to content

Commit c5d83f6

Browse files
committed
dirty
1 parent 260af17 commit c5d83f6

File tree

8 files changed

+232
-180
lines changed

8 files changed

+232
-180
lines changed

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

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

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

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

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

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,6 @@ static void after() throws Exception {
137137
}
138138

139139
private void testAllOther() {
140-
testAllServices();
141-
testAllServicesWithBootstrap();
142-
testExternalNameServiceInstance();
143140
testBlockingConfiguration();
144141
testDefaultConfiguration();
145142
testReactiveConfiguration();
@@ -148,21 +145,6 @@ private void testAllOther() {
148145
namespaceFilter();
149146
}
150147

151-
private void testAllServices() {
152-
util.patchWithReplace(DOCKER_IMAGE, DEPLOYMENT_NAME, NAMESPACE, BODY_ONE, Map.of("app", IMAGE_NAME));
153-
Fabric8DiscoveryDelegate.testAllServices();
154-
}
155-
156-
private void testAllServicesWithBootstrap() {
157-
util.patchWithReplace(DOCKER_IMAGE, DEPLOYMENT_NAME, NAMESPACE, BODY_ONE_WITH_BOOTSTRAP,
158-
Map.of("app", IMAGE_NAME));
159-
Fabric8DiscoveryBoostrapDelegate.testAllServicesWithBootstrap();
160-
}
161-
162-
private void testExternalNameServiceInstance() {
163-
Fabric8DiscoveryDelegate.testExternalNameServiceInstance();
164-
}
165-
166148
private void testBlockingConfiguration() {
167149
util.patchWithReplace(DOCKER_IMAGE, DEPLOYMENT_NAME, NAMESPACE, BODY_TWO, Map.of("app", IMAGE_NAME));
168150
Fabric8DiscoveryClientHealthDelegate.testBlockingConfiguration(K3S, IMAGE_NAME);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
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.it;
18+
19+
import java.io.IOException;
20+
import java.io.InputStream;
21+
22+
import io.fabric8.kubernetes.api.model.Service;
23+
import io.fabric8.kubernetes.client.KubernetesClient;
24+
import io.fabric8.kubernetes.client.utils.Serialization;
25+
import org.junit.jupiter.api.AfterEach;
26+
import org.junit.jupiter.api.BeforeEach;
27+
import org.junit.jupiter.api.Nested;
28+
import org.junit.jupiter.api.Test;
29+
30+
import org.springframework.beans.factory.annotation.Autowired;
31+
import org.springframework.boot.test.context.SpringBootTest;
32+
import org.springframework.boot.test.context.TestConfiguration;
33+
import org.springframework.cloud.client.discovery.DiscoveryClient;
34+
import org.springframework.cloud.kubernetes.fabric8.client.discovery.Fabric8DiscoveryApp;
35+
import org.springframework.cloud.kubernetes.integration.tests.commons.Images;
36+
import org.springframework.cloud.kubernetes.integration.tests.commons.Phase;
37+
import org.springframework.context.annotation.Bean;
38+
import org.springframework.context.annotation.Primary;
39+
import org.springframework.test.context.TestPropertySource;
40+
41+
import static org.springframework.cloud.kubernetes.fabric8.client.discovery.it.TestAssertions.assertAllServices;
42+
43+
/**
44+
* @author wind57
45+
*/
46+
class Fabric8DiscoveryAllServicesIT extends Fabric8DiscoveryBase {
47+
48+
@Nested
49+
@TestPropertySource(properties = { "spring.cloud.kubernetes.discovery.include-external-name-services=true" })
50+
class NonBootstrap {
51+
52+
@Autowired
53+
private DiscoveryClient discoveryClient;
54+
55+
@BeforeEach
56+
void beforeEach() {
57+
Images.loadBusybox(K3S);
58+
util.busybox(NAMESPACE, Phase.CREATE);
59+
externalNameServices(Phase.CREATE);
60+
}
61+
62+
@AfterEach
63+
void afterEach() {
64+
util.busybox(NAMESPACE, Phase.DELETE);
65+
externalNameServices(Phase.DELETE);
66+
}
67+
68+
/**
69+
* <pre>
70+
* - there are 3 services : 'busybox-service', 'kubernetes', 'external-name-service'
71+
* - all of them are found
72+
* </pre>
73+
*/
74+
@Test
75+
void test() {
76+
assertAllServices(discoveryClient);
77+
}
78+
}
79+
80+
@Nested
81+
@TestPropertySource(properties = { "spring.cloud.kubernetes.discovery.include-external-name-services=true",
82+
"spring.cloud.bootstrap.enabled=true"})
83+
class Bootstrap {
84+
85+
@Autowired
86+
private DiscoveryClient discoveryClient;
87+
88+
@BeforeEach
89+
void beforeEach() {
90+
Images.loadBusybox(K3S);
91+
util.busybox(NAMESPACE, Phase.CREATE);
92+
externalNameServices(Phase.CREATE);
93+
}
94+
95+
@AfterEach
96+
void afterEach() {
97+
util.busybox(NAMESPACE, Phase.DELETE);
98+
externalNameServices(Phase.DELETE);
99+
}
100+
101+
/**
102+
* <pre>
103+
* - there are 3 services : 'busybox-service', 'kubernetes', 'external-name-service'
104+
* - all of them are found
105+
* </pre>
106+
*/
107+
@Test
108+
void test() {
109+
assertAllServices(discoveryClient);
110+
}
111+
}
112+
113+
private void externalNameServices(Phase phase) {
114+
try (InputStream externalNameServiceStream = util.inputStream("external-name-service.yaml")) {
115+
Service externalServiceName = Serialization.unmarshal(externalNameServiceStream, Service.class);
116+
if (phase == Phase.CREATE) {
117+
util.createAndWait(NAMESPACE, null, null, externalServiceName, null, true);
118+
}
119+
else {
120+
util.deleteAndWait(NAMESPACE, null, externalServiceName, null);
121+
}
122+
}
123+
catch (IOException e) {
124+
throw new RuntimeException(e);
125+
}
126+
}
127+
128+
}

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
2222
import org.junit.jupiter.api.BeforeAll;
2323
import org.junit.jupiter.api.extension.ExtendWith;
24+
import org.springframework.boot.test.context.SpringBootTest;
25+
import org.springframework.boot.test.context.TestConfiguration;
26+
import org.springframework.cloud.kubernetes.fabric8.client.discovery.Fabric8DiscoveryApp;
27+
import org.springframework.context.annotation.Bean;
28+
import org.springframework.context.annotation.Primary;
2429
import org.testcontainers.k3s.K3sContainer;
2530

2631
import org.springframework.boot.test.system.OutputCaptureExtension;
@@ -38,6 +43,7 @@
3843
"spring.cloud.kubernetes.discovery.metadata.add-pod-annotations=true" ,
3944
"logging.level.org.springframework.cloud.kubernetes.fabric8.discovery=debug" })
4045
@ExtendWith(OutputCaptureExtension.class)
46+
@SpringBootTest(classes = { Fabric8DiscoveryApp.class, Fabric8DiscoveryAllServicesIT.TestConfig.class })
4147
abstract class Fabric8DiscoveryBase {
4248

4349
protected static final String NAMESPACE = "default";
@@ -58,4 +64,15 @@ protected static KubernetesClient client() {
5864
return new KubernetesClientBuilder().withConfig(config).build();
5965
}
6066

67+
@TestConfiguration
68+
static class TestConfig {
69+
70+
@Bean
71+
@Primary
72+
KubernetesClient kubernetesClient() {
73+
return client();
74+
}
75+
76+
}
77+
6178
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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.it;
18+
19+
import java.io.IOException;
20+
import java.io.InputStream;
21+
22+
import io.fabric8.kubernetes.api.model.Service;
23+
import io.fabric8.kubernetes.client.KubernetesClient;
24+
import io.fabric8.kubernetes.client.utils.Serialization;
25+
import org.junit.jupiter.api.AfterEach;
26+
import org.junit.jupiter.api.BeforeEach;
27+
import org.junit.jupiter.api.Nested;
28+
import org.junit.jupiter.api.Test;
29+
30+
import org.springframework.beans.factory.annotation.Autowired;
31+
import org.springframework.boot.test.context.SpringBootTest;
32+
import org.springframework.boot.test.context.TestConfiguration;
33+
import org.springframework.cloud.client.discovery.DiscoveryClient;
34+
import org.springframework.cloud.kubernetes.fabric8.client.discovery.Fabric8DiscoveryApp;
35+
import org.springframework.cloud.kubernetes.integration.tests.commons.Images;
36+
import org.springframework.cloud.kubernetes.integration.tests.commons.Phase;
37+
import org.springframework.context.annotation.Bean;
38+
import org.springframework.context.annotation.Primary;
39+
import org.springframework.test.context.TestPropertySource;
40+
41+
import static org.springframework.cloud.kubernetes.fabric8.client.discovery.it.TestAssertions.assertAllServices;
42+
43+
/**
44+
* @author wind57
45+
*/
46+
@SpringBootTest(classes = { Fabric8DiscoveryApp.class, Fabric8DiscoveryPodMetadataIT.TestConfig.class })
47+
class Fabric8DiscoveryBlockingIT extends Fabric8DiscoveryBase {
48+
}

0 commit comments

Comments
 (0)