-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
913 additions
and
1,371 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 0 additions & 45 deletions
45
...mework/cloud/kubernetes/fabric8/client/discovery/Fabric8ApplicationDiscoveryListener.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 0 additions & 59 deletions
59
...springframework/cloud/kubernetes/fabric8/client/discovery/Fabric8DiscoveryController.java
This file was deleted.
Oops, something went wrong.
55 changes: 0 additions & 55 deletions
55
...amework/cloud/kubernetes/fabric8/client/discovery/Fabric8ReactiveDiscoveryController.java
This file was deleted.
Oops, something went wrong.
126 changes: 126 additions & 0 deletions
126
...ingframework/cloud/kubernetes/fabric8/client/discovery/Fabric8DiscoveryAllServicesIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* | ||
* Copyright 2012-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.cloud.kubernetes.fabric8.client.discovery; | ||
|
||
import java.io.InputStream; | ||
|
||
import io.fabric8.kubernetes.api.model.Service; | ||
import io.fabric8.kubernetes.client.utils.Serialization; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.cloud.client.discovery.DiscoveryClient; | ||
import org.springframework.cloud.kubernetes.integration.tests.commons.Images; | ||
import org.springframework.cloud.kubernetes.integration.tests.commons.Phase; | ||
import org.springframework.test.context.TestPropertySource; | ||
|
||
import static org.springframework.cloud.kubernetes.fabric8.client.discovery.TestAssertions.assertAllServices; | ||
|
||
/** | ||
* @author wind57 | ||
*/ | ||
class Fabric8DiscoveryAllServicesIT extends Fabric8DiscoveryBase { | ||
|
||
private static Service externalServiceName; | ||
|
||
@BeforeAll | ||
static void beforeAllInNested() { | ||
InputStream externalNameServiceStream = util.inputStream("external-name-service.yaml"); | ||
externalServiceName = Serialization.unmarshal(externalNameServiceStream, Service.class); | ||
} | ||
|
||
private void externalNameServices(Phase phase) { | ||
if (phase == Phase.CREATE) { | ||
util.createAndWait(NAMESPACE, null, null, externalServiceName, null, true); | ||
} | ||
else { | ||
util.deleteAndWait(NAMESPACE, null, externalServiceName, null); | ||
} | ||
} | ||
|
||
@Nested | ||
@TestPropertySource(properties = { "spring.cloud.kubernetes.discovery.include-external-name-services=true" }) | ||
class NonBootstrap { | ||
|
||
@Autowired | ||
private DiscoveryClient discoveryClient; | ||
|
||
@BeforeEach | ||
void beforeEach() { | ||
Images.loadBusybox(K3S); | ||
util.busybox(NAMESPACE, Phase.CREATE); | ||
externalNameServices(Phase.CREATE); | ||
} | ||
|
||
@AfterEach | ||
void afterEach() { | ||
util.busybox(NAMESPACE, Phase.DELETE); | ||
externalNameServices(Phase.DELETE); | ||
} | ||
|
||
/** | ||
* <pre> | ||
* - there are 3 services : 'busybox-service', 'kubernetes', 'external-name-service' | ||
* - all of them are found | ||
* </pre> | ||
*/ | ||
@Test | ||
void test() { | ||
assertAllServices(discoveryClient); | ||
} | ||
|
||
} | ||
|
||
@Nested | ||
@TestPropertySource(properties = { "spring.cloud.kubernetes.discovery.include-external-name-services=true", | ||
"spring.cloud.bootstrap.enabled=true" }) | ||
class Bootstrap { | ||
|
||
@Autowired | ||
private DiscoveryClient discoveryClient; | ||
|
||
@BeforeEach | ||
void beforeEach() { | ||
Images.loadBusybox(K3S); | ||
util.busybox(NAMESPACE, Phase.CREATE); | ||
externalNameServices(Phase.CREATE); | ||
} | ||
|
||
@AfterEach | ||
void afterEach() { | ||
util.busybox(NAMESPACE, Phase.DELETE); | ||
externalNameServices(Phase.DELETE); | ||
} | ||
|
||
/** | ||
* <pre> | ||
* - there are 3 services : 'busybox-service', 'kubernetes', 'external-name-service' | ||
* - all of them are found | ||
* </pre> | ||
*/ | ||
@Test | ||
void test() { | ||
assertAllServices(discoveryClient); | ||
} | ||
|
||
} | ||
|
||
} |
77 changes: 77 additions & 0 deletions
77
...a/org/springframework/cloud/kubernetes/fabric8/client/discovery/Fabric8DiscoveryBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright 2012-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.cloud.kubernetes.fabric8.client.discovery; | ||
|
||
import io.fabric8.kubernetes.client.Config; | ||
import io.fabric8.kubernetes.client.KubernetesClient; | ||
import io.fabric8.kubernetes.client.KubernetesClientBuilder; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.testcontainers.k3s.K3sContainer; | ||
|
||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.context.TestConfiguration; | ||
import org.springframework.boot.test.system.OutputCaptureExtension; | ||
import org.springframework.cloud.kubernetes.integration.tests.commons.Commons; | ||
import org.springframework.cloud.kubernetes.integration.tests.commons.fabric8_client.Util; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Primary; | ||
import org.springframework.test.context.TestPropertySource; | ||
|
||
/** | ||
* @author wind57 | ||
*/ | ||
@TestPropertySource(properties = { "spring.main.cloud-platform=kubernetes", | ||
"spring.cloud.config.import-check.enabled=false", "spring.cloud.kubernetes.client.namespace=default", | ||
"spring.cloud.kubernetes.discovery.metadata.add-pod-labels=true", | ||
"spring.cloud.kubernetes.discovery.metadata.add-pod-annotations=true", | ||
"logging.level.org.springframework.cloud.kubernetes.fabric8.discovery=debug" }) | ||
@ExtendWith(OutputCaptureExtension.class) | ||
@SpringBootTest(classes = { Fabric8DiscoveryApp.class, Fabric8DiscoveryBase.TestConfig.class }, | ||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
abstract class Fabric8DiscoveryBase { | ||
|
||
protected static final String NAMESPACE = "default"; | ||
|
||
protected static final K3sContainer K3S = Commons.container(); | ||
|
||
protected static Util util; | ||
|
||
@BeforeAll | ||
protected static void beforeAll() { | ||
K3S.start(); | ||
util = new Util(K3S); | ||
} | ||
|
||
protected static KubernetesClient client() { | ||
String kubeConfigYaml = K3S.getKubeConfigYaml(); | ||
Config config = Config.fromKubeconfig(kubeConfigYaml); | ||
return new KubernetesClientBuilder().withConfig(config).build(); | ||
} | ||
|
||
@TestConfiguration | ||
static class TestConfig { | ||
|
||
@Bean | ||
@Primary | ||
KubernetesClient kubernetesClient() { | ||
return client(); | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.