From 1d6c86df70c6bec8163b8935f25bee116315e2ab Mon Sep 17 00:00:00 2001 From: wind57 Date: Fri, 17 Jan 2025 18:58:08 +0200 Subject: [PATCH 1/7] easier to read code Signed-off-by: wind57 --- .../fabric8/catalog/watch/Fabric8CatalogWatchBase.java | 5 +++-- ...c8CatalogWatchWithEndpointSlicesAndNamespaceFilterIT.java | 2 +- .../watch/Fabric8CatalogWatchWithEndpointSlicesIT.java | 2 +- ...Fabric8CatalogWatchWithEndpointsAndNamespaceFilterIT.java | 2 +- .../catalog/watch/Fabric8CatalogWatchWithEndpointsIT.java | 2 +- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/java/org/springframework/cloud/kubernetes/fabric8/catalog/watch/Fabric8CatalogWatchBase.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/java/org/springframework/cloud/kubernetes/fabric8/catalog/watch/Fabric8CatalogWatchBase.java index 5dd33c44ba..ae55c78c6f 100644 --- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/java/org/springframework/cloud/kubernetes/fabric8/catalog/watch/Fabric8CatalogWatchBase.java +++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/java/org/springframework/cloud/kubernetes/fabric8/catalog/watch/Fabric8CatalogWatchBase.java @@ -60,8 +60,9 @@ protected static void beforeAll() { util = new Util(K3S); } - protected static KubernetesDiscoveryProperties discoveryProperties(boolean useEndpointSlices) { - return new KubernetesDiscoveryProperties(true, false, Set.of(NAMESPACE, NAMESPACE_A), true, 60, false, null, + protected static KubernetesDiscoveryProperties discoveryProperties(boolean useEndpointSlices, + Set discoveryNamespaces) { + return new KubernetesDiscoveryProperties(true, false, discoveryNamespaces, true, 60, false, null, Set.of(443, 8443), Map.of(), null, KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, useEndpointSlices, false, null); } diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/java/org/springframework/cloud/kubernetes/fabric8/catalog/watch/Fabric8CatalogWatchWithEndpointSlicesAndNamespaceFilterIT.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/java/org/springframework/cloud/kubernetes/fabric8/catalog/watch/Fabric8CatalogWatchWithEndpointSlicesAndNamespaceFilterIT.java index a1b5a79cf1..1d7706ed26 100644 --- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/java/org/springframework/cloud/kubernetes/fabric8/catalog/watch/Fabric8CatalogWatchWithEndpointSlicesAndNamespaceFilterIT.java +++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/java/org/springframework/cloud/kubernetes/fabric8/catalog/watch/Fabric8CatalogWatchWithEndpointSlicesAndNamespaceFilterIT.java @@ -96,7 +96,7 @@ KubernetesClient kubernetesClient() { @Bean @Primary KubernetesDiscoveryProperties kubernetesDiscoveryProperties() { - return discoveryProperties(true); + return discoveryProperties(true, Set.of(NAMESPACE, NAMESPACE_A)); } } diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/java/org/springframework/cloud/kubernetes/fabric8/catalog/watch/Fabric8CatalogWatchWithEndpointSlicesIT.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/java/org/springframework/cloud/kubernetes/fabric8/catalog/watch/Fabric8CatalogWatchWithEndpointSlicesIT.java index 9ffdcc0360..ef026bf0c6 100644 --- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/java/org/springframework/cloud/kubernetes/fabric8/catalog/watch/Fabric8CatalogWatchWithEndpointSlicesIT.java +++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/java/org/springframework/cloud/kubernetes/fabric8/catalog/watch/Fabric8CatalogWatchWithEndpointSlicesIT.java @@ -87,7 +87,7 @@ KubernetesClient kubernetesClient() { @Bean @Primary KubernetesDiscoveryProperties kubernetesDiscoveryProperties() { - return discoveryProperties(true); + return discoveryProperties(true, Set.of(NAMESPACE)); } } diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/java/org/springframework/cloud/kubernetes/fabric8/catalog/watch/Fabric8CatalogWatchWithEndpointsAndNamespaceFilterIT.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/java/org/springframework/cloud/kubernetes/fabric8/catalog/watch/Fabric8CatalogWatchWithEndpointsAndNamespaceFilterIT.java index cd37be1732..ec116ed5b3 100644 --- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/java/org/springframework/cloud/kubernetes/fabric8/catalog/watch/Fabric8CatalogWatchWithEndpointsAndNamespaceFilterIT.java +++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/java/org/springframework/cloud/kubernetes/fabric8/catalog/watch/Fabric8CatalogWatchWithEndpointsAndNamespaceFilterIT.java @@ -96,7 +96,7 @@ KubernetesClient kubernetesClient() { @Bean @Primary KubernetesDiscoveryProperties kubernetesDiscoveryProperties() { - return discoveryProperties(false); + return discoveryProperties(false, Set.of(NAMESPACE, NAMESPACE_A)); } } diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/java/org/springframework/cloud/kubernetes/fabric8/catalog/watch/Fabric8CatalogWatchWithEndpointsIT.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/java/org/springframework/cloud/kubernetes/fabric8/catalog/watch/Fabric8CatalogWatchWithEndpointsIT.java index efed4f5aeb..ab813aef3a 100644 --- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/java/org/springframework/cloud/kubernetes/fabric8/catalog/watch/Fabric8CatalogWatchWithEndpointsIT.java +++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/java/org/springframework/cloud/kubernetes/fabric8/catalog/watch/Fabric8CatalogWatchWithEndpointsIT.java @@ -87,7 +87,7 @@ KubernetesClient kubernetesClient() { @Bean @Primary KubernetesDiscoveryProperties kubernetesDiscoveryProperties() { - return discoveryProperties(false); + return discoveryProperties(false, Set.of(NAMESPACE)); } } From 82b0f7758c0f50ae1e743e0e67bb145ee1a236b2 Mon Sep 17 00:00:00 2001 From: wind57 Date: Sat, 18 Jan 2025 09:36:18 +0200 Subject: [PATCH 2/7] drop tests Signed-off-by: wind57 --- ...c8CatalogWatchEndpointSlicesFilterIT.java} | 4 +- ...va => Fabric8CatalogWatchEndpointsIT.java} | 4 +- ...bric8CatalogWatchWithEndpointSlicesIT.java | 95 ------------------- .../Fabric8CatalogWatchWithEndpointsIT.java | 95 ------------------- 4 files changed, 4 insertions(+), 194 deletions(-) rename spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/java/org/springframework/cloud/kubernetes/fabric8/catalog/watch/{Fabric8CatalogWatchWithEndpointSlicesAndNamespaceFilterIT.java => Fabric8CatalogWatchEndpointSlicesFilterIT.java} (95%) rename spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/java/org/springframework/cloud/kubernetes/fabric8/catalog/watch/{Fabric8CatalogWatchWithEndpointsAndNamespaceFilterIT.java => Fabric8CatalogWatchEndpointsIT.java} (95%) delete mode 100644 spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/java/org/springframework/cloud/kubernetes/fabric8/catalog/watch/Fabric8CatalogWatchWithEndpointSlicesIT.java delete mode 100644 spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/java/org/springframework/cloud/kubernetes/fabric8/catalog/watch/Fabric8CatalogWatchWithEndpointsIT.java diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/java/org/springframework/cloud/kubernetes/fabric8/catalog/watch/Fabric8CatalogWatchWithEndpointSlicesAndNamespaceFilterIT.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/java/org/springframework/cloud/kubernetes/fabric8/catalog/watch/Fabric8CatalogWatchEndpointSlicesFilterIT.java similarity index 95% rename from spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/java/org/springframework/cloud/kubernetes/fabric8/catalog/watch/Fabric8CatalogWatchWithEndpointSlicesAndNamespaceFilterIT.java rename to spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/java/org/springframework/cloud/kubernetes/fabric8/catalog/watch/Fabric8CatalogWatchEndpointSlicesFilterIT.java index 1d7706ed26..8933a76e2d 100644 --- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/java/org/springframework/cloud/kubernetes/fabric8/catalog/watch/Fabric8CatalogWatchWithEndpointSlicesAndNamespaceFilterIT.java +++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/java/org/springframework/cloud/kubernetes/fabric8/catalog/watch/Fabric8CatalogWatchEndpointSlicesFilterIT.java @@ -34,7 +34,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Primary; -import static org.springframework.cloud.kubernetes.fabric8.catalog.watch.Fabric8CatalogWatchWithEndpointSlicesAndNamespaceFilterIT.TestConfig; +import static org.springframework.cloud.kubernetes.fabric8.catalog.watch.Fabric8CatalogWatchEndpointSlicesFilterIT.TestConfig; import static org.springframework.cloud.kubernetes.fabric8.catalog.watch.TestAssertions.assertLogStatement; import static org.springframework.cloud.kubernetes.fabric8.catalog.watch.TestAssertions.invokeAndAssert; @@ -43,7 +43,7 @@ */ @SpringBootTest(classes = { KubernetesCatalogWatchAutoConfiguration.class, TestConfig.class, Application.class }, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -class Fabric8CatalogWatchWithEndpointSlicesAndNamespaceFilterIT extends Fabric8CatalogWatchBase { +class Fabric8CatalogWatchEndpointSlicesFilterIT extends Fabric8CatalogWatchBase { @LocalServerPort private int port; diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/java/org/springframework/cloud/kubernetes/fabric8/catalog/watch/Fabric8CatalogWatchWithEndpointsAndNamespaceFilterIT.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/java/org/springframework/cloud/kubernetes/fabric8/catalog/watch/Fabric8CatalogWatchEndpointsIT.java similarity index 95% rename from spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/java/org/springframework/cloud/kubernetes/fabric8/catalog/watch/Fabric8CatalogWatchWithEndpointsAndNamespaceFilterIT.java rename to spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/java/org/springframework/cloud/kubernetes/fabric8/catalog/watch/Fabric8CatalogWatchEndpointsIT.java index ec116ed5b3..5f01566856 100644 --- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/java/org/springframework/cloud/kubernetes/fabric8/catalog/watch/Fabric8CatalogWatchWithEndpointsAndNamespaceFilterIT.java +++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/java/org/springframework/cloud/kubernetes/fabric8/catalog/watch/Fabric8CatalogWatchEndpointsIT.java @@ -34,7 +34,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Primary; -import static org.springframework.cloud.kubernetes.fabric8.catalog.watch.Fabric8CatalogWatchWithEndpointsAndNamespaceFilterIT.TestConfig; +import static org.springframework.cloud.kubernetes.fabric8.catalog.watch.Fabric8CatalogWatchEndpointsIT.TestConfig; import static org.springframework.cloud.kubernetes.fabric8.catalog.watch.TestAssertions.assertLogStatement; import static org.springframework.cloud.kubernetes.fabric8.catalog.watch.TestAssertions.invokeAndAssert; @@ -43,7 +43,7 @@ */ @SpringBootTest(classes = { KubernetesCatalogWatchAutoConfiguration.class, TestConfig.class, Application.class }, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -class Fabric8CatalogWatchWithEndpointsAndNamespaceFilterIT extends Fabric8CatalogWatchBase { +class Fabric8CatalogWatchEndpointsIT extends Fabric8CatalogWatchBase { @LocalServerPort private int port; diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/java/org/springframework/cloud/kubernetes/fabric8/catalog/watch/Fabric8CatalogWatchWithEndpointSlicesIT.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/java/org/springframework/cloud/kubernetes/fabric8/catalog/watch/Fabric8CatalogWatchWithEndpointSlicesIT.java deleted file mode 100644 index ef026bf0c6..0000000000 --- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/java/org/springframework/cloud/kubernetes/fabric8/catalog/watch/Fabric8CatalogWatchWithEndpointSlicesIT.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * 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.catalog.watch; - -import java.util.Set; - -import io.fabric8.kubernetes.client.KubernetesClient; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.TestConfiguration; -import org.springframework.boot.test.system.CapturedOutput; -import org.springframework.boot.test.web.server.LocalServerPort; -import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; -import org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesCatalogWatchAutoConfiguration; -import org.springframework.cloud.kubernetes.integration.tests.commons.Images; -import org.springframework.cloud.kubernetes.integration.tests.commons.Phase; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Primary; - -import static org.springframework.cloud.kubernetes.fabric8.catalog.watch.Fabric8CatalogWatchWithEndpointSlicesIT.TestConfig; -import static org.springframework.cloud.kubernetes.fabric8.catalog.watch.TestAssertions.assertLogStatement; -import static org.springframework.cloud.kubernetes.fabric8.catalog.watch.TestAssertions.invokeAndAssert; - -/** - * @author wind57 - */ -@SpringBootTest(classes = { KubernetesCatalogWatchAutoConfiguration.class, TestConfig.class, Application.class }, - webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -class Fabric8CatalogWatchWithEndpointSlicesIT extends Fabric8CatalogWatchBase { - - @LocalServerPort - private int port; - - @BeforeEach - void beforeEach() { - Images.loadBusybox(K3S); - util.busybox(NAMESPACE, Phase.CREATE); - } - - @AfterEach - void afterEach() { - // empty on purpose - // busybox is deleted as part of the test itself, thus not seen here - } - - /** - *
-	 *     - we deploy a busybox service with 2 replica pods
-	 *     - we use endpoint slices
-	 *     - we receive an event from KubernetesCatalogWatcher, assert what is inside it
-	 *     - delete the busybox service
-	 *     - assert that we receive an empty response
-	 * 
- */ - @Test - void test(CapturedOutput output) { - assertLogStatement(output, "stateGenerator is of type: Fabric8EndpointSliceV1CatalogWatch"); - invokeAndAssert(util, Set.of(NAMESPACE), port, NAMESPACE); - } - - @TestConfiguration - static class TestConfig { - - @Bean - @Primary - KubernetesClient kubernetesClient() { - return client(); - } - - @Bean - @Primary - KubernetesDiscoveryProperties kubernetesDiscoveryProperties() { - return discoveryProperties(true, Set.of(NAMESPACE)); - } - - } - -} diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/java/org/springframework/cloud/kubernetes/fabric8/catalog/watch/Fabric8CatalogWatchWithEndpointsIT.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/java/org/springframework/cloud/kubernetes/fabric8/catalog/watch/Fabric8CatalogWatchWithEndpointsIT.java deleted file mode 100644 index ab813aef3a..0000000000 --- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/java/org/springframework/cloud/kubernetes/fabric8/catalog/watch/Fabric8CatalogWatchWithEndpointsIT.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * 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.catalog.watch; - -import java.util.Set; - -import io.fabric8.kubernetes.client.KubernetesClient; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.TestConfiguration; -import org.springframework.boot.test.system.CapturedOutput; -import org.springframework.boot.test.web.server.LocalServerPort; -import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; -import org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesCatalogWatchAutoConfiguration; -import org.springframework.cloud.kubernetes.integration.tests.commons.Images; -import org.springframework.cloud.kubernetes.integration.tests.commons.Phase; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Primary; - -import static org.springframework.cloud.kubernetes.fabric8.catalog.watch.Fabric8CatalogWatchWithEndpointsIT.TestConfig; -import static org.springframework.cloud.kubernetes.fabric8.catalog.watch.TestAssertions.assertLogStatement; -import static org.springframework.cloud.kubernetes.fabric8.catalog.watch.TestAssertions.invokeAndAssert; - -/** - * @author wind57 - */ -@SpringBootTest(classes = { KubernetesCatalogWatchAutoConfiguration.class, TestConfig.class, Application.class }, - webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -class Fabric8CatalogWatchWithEndpointsIT extends Fabric8CatalogWatchBase { - - @LocalServerPort - private int port; - - @BeforeEach - void beforeEach() { - Images.loadBusybox(K3S); - util.busybox(NAMESPACE, Phase.CREATE); - } - - @AfterEach - void afterEach() { - // empty on purpose - // busybox is deleted as part of the test itself, thus not seen here - } - - /** - *
-	 *     - we deploy a busybox service with 2 replica pods
-	 *     - we use endpoints
-	 *     - we receive an event from KubernetesCatalogWatcher, assert what is inside it
-	 *     - delete the busybox service
-	 *     - assert that we receive an empty response
-	 * 
- */ - @Test - void test(CapturedOutput output) { - assertLogStatement(output, "stateGenerator is of type: Fabric8EndpointsCatalogWatch"); - invokeAndAssert(util, Set.of(NAMESPACE), port, NAMESPACE); - } - - @TestConfiguration - static class TestConfig { - - @Bean - @Primary - KubernetesClient kubernetesClient() { - return client(); - } - - @Bean - @Primary - KubernetesDiscoveryProperties kubernetesDiscoveryProperties() { - return discoveryProperties(false, Set.of(NAMESPACE)); - } - - } - -} From 94dfad27a313b0406279f84a774523921e1df6a2 Mon Sep 17 00:00:00 2001 From: wind57 Date: Sun, 19 Jan 2025 10:29:31 +0200 Subject: [PATCH 3/7] drop test Signed-off-by: wind57 --- ...abric8DiscoveryDefaultConfigurationIT.java | 60 ------------------- 1 file changed, 60 deletions(-) delete mode 100644 spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/discovery/Fabric8DiscoveryDefaultConfigurationIT.java diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/discovery/Fabric8DiscoveryDefaultConfigurationIT.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/discovery/Fabric8DiscoveryDefaultConfigurationIT.java deleted file mode 100644 index 438ae6e8fa..0000000000 --- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/discovery/Fabric8DiscoveryDefaultConfigurationIT.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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 org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import org.springframework.boot.test.system.CapturedOutput; -import org.springframework.boot.test.web.server.LocalManagementPort; -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.testDefaultConfiguration; - -/** - * @author wind57 - */ -@TestPropertySource(properties = { "logging.level.org.springframework.cloud.client.discovery.health.reactive=DEBUG", - "logging.level.org.springframework.cloud.client.discovery.health=DEBUG", - "logging.level.org.springframework.cloud.kubernetes.fabric8.discovery.reactive=DEBUG", - "logging.level.org.springframework.cloud.kubernetes.fabric8.discovery=DEBUG", - "logging.level.org.springframework.cloud.kubernetes.commons.discovery=DEBUG" }) -class Fabric8DiscoveryDefaultConfigurationIT extends Fabric8DiscoveryBase { - - @LocalManagementPort - private int port; - - @BeforeEach - void beforeEach() { - Images.loadBusybox(K3S); - util.busybox(NAMESPACE, Phase.CREATE); - } - - @AfterEach - void afterEach() { - util.busybox(NAMESPACE, Phase.DELETE); - } - - @Test - void test(CapturedOutput output) { - testDefaultConfiguration(output, port); - } - -} From 6c94c8df2028612d8602580050069760749732a0 Mon Sep 17 00:00:00 2001 From: wind57 Date: Sun, 19 Jan 2025 10:48:55 +0200 Subject: [PATCH 4/7] drop test Signed-off-by: wind57 --- ...ic8DiscoveryFilterMatchOneNamespaceIT.java | 74 ------------------- .../client/discovery/TestAssertions.java | 33 --------- 2 files changed, 107 deletions(-) delete mode 100644 spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/discovery/Fabric8DiscoveryFilterMatchOneNamespaceIT.java diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/discovery/Fabric8DiscoveryFilterMatchOneNamespaceIT.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/discovery/Fabric8DiscoveryFilterMatchOneNamespaceIT.java deleted file mode 100644 index 6b18142e65..0000000000 --- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/discovery/Fabric8DiscoveryFilterMatchOneNamespaceIT.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * 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 org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -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.filterMatchesOneNamespaceViaThePredicate; - -/** - * @author wind57 - */ -@TestPropertySource(properties = { "spring.cloud.kubernetes.discovery.namespaces[0]=a-uat", - "spring.cloud.kubernetes.discovery.namespaces[1]=b-uat", - "spring.cloud.kubernetes.discovery.filter=#root.metadata.namespace matches 'a-uat$'", - "logging.level.org.springframework.cloud.kubernetes.fabric8.discovery=DEBUG" }) -class Fabric8DiscoveryFilterMatchOneNamespaceIT extends Fabric8DiscoveryBase { - - private static final String NAMESPACE_A_UAT = "a-uat"; - - private static final String NAMESPACE_B_UAT = "b-uat"; - - @Autowired - private DiscoveryClient discoveryClient; - - @BeforeEach - void beforeEach() { - Images.loadWiremock(K3S); - - util.createNamespace(NAMESPACE_A_UAT); - util.createNamespace(NAMESPACE_B_UAT); - - util.wiremock(NAMESPACE_A_UAT, Phase.CREATE); - util.wiremock(NAMESPACE_B_UAT, Phase.CREATE); - - } - - @AfterEach - void afterEach() { - - util.wiremock(NAMESPACE_A_UAT, Phase.DELETE); - util.wiremock(NAMESPACE_B_UAT, Phase.DELETE); - - util.deleteNamespace(NAMESPACE_A_UAT); - util.deleteNamespace(NAMESPACE_B_UAT); - } - - @Test - void test() { - filterMatchesOneNamespaceViaThePredicate(discoveryClient); - } - -} diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/discovery/TestAssertions.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/discovery/TestAssertions.java index 278e4fa059..1fdd8272b9 100644 --- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/discovery/TestAssertions.java +++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/discovery/TestAssertions.java @@ -279,39 +279,6 @@ static void filterMatchesBothNamespacesViaThePredicate(DiscoveryClient discovery } - /** - *
-	 *     - service "wiremock" is present in namespace "a-uat"
-	 *     - service "wiremock" is present in namespace "b-uat"
-	 *
-	 *     - we search with a predicate : "#root.metadata.namespace matches 'a-uat$'"
-	 *
-	 *     As such, only service from 'a-uat' namespace matches.
-	 * 
- */ - static void filterMatchesOneNamespaceViaThePredicate(DiscoveryClient discoveryClient) { - - List services = discoveryClient.getServices(); - assertThat(services.size()).isEqualTo(1); - assertThat(services).contains("service-wiremock"); - - List serviceInstances = discoveryClient.getInstances("service-wiremock") - .stream() - .map(x -> (DefaultKubernetesServiceInstance) x) - .toList(); - - assertThat(serviceInstances.size()).isEqualTo(1); - - DefaultKubernetesServiceInstance first = serviceInstances.get(0); - assertThat(first.getServiceId()).isEqualTo("service-wiremock"); - assertThat(first.getInstanceId()).isNotNull(); - assertThat(first.getPort()).isEqualTo(8080); - assertThat(first.getNamespace()).isEqualTo("a-uat"); - assertThat(first.getMetadata()).isEqualTo( - Map.of("app", "service-wiremock", "port.http", "8080", "k8s_namespace", "a-uat", "type", "ClusterIP")); - - } - private static void waitForLogStatement(CapturedOutput output, String message) { await().pollInterval(Duration.ofSeconds(1)) .atMost(Duration.ofSeconds(30)) From f5fbdc8a6630af4d73d9126a4b83b57292ed459f Mon Sep 17 00:00:00 2001 From: wind57 Date: Sun, 19 Jan 2025 10:57:40 +0200 Subject: [PATCH 5/7] inline a test Signed-off-by: wind57 --- .../discovery/Fabric8DiscoveryBlockingIT.java | 20 +++++- .../Fabric8DiscoveryPodMetadataIT.java | 71 ------------------- 2 files changed, 19 insertions(+), 72 deletions(-) delete mode 100644 spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/discovery/Fabric8DiscoveryPodMetadataIT.java diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/discovery/Fabric8DiscoveryBlockingIT.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/discovery/Fabric8DiscoveryBlockingIT.java index 3c4d3cc7d5..9f60a5e913 100644 --- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/discovery/Fabric8DiscoveryBlockingIT.java +++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/discovery/Fabric8DiscoveryBlockingIT.java @@ -20,13 +20,16 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.system.CapturedOutput; import org.springframework.boot.test.web.server.LocalManagementPort; +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.assertBlockingConfiguration; +import static org.springframework.cloud.kubernetes.fabric8.client.discovery.TestAssertions.assertPodMetadata; /** * @author wind57 @@ -39,6 +42,9 @@ class Fabric8DiscoveryBlockingIT extends Fabric8DiscoveryBase { @LocalManagementPort private int port; + @Autowired + private DiscoveryClient discoveryClient; + @BeforeEach void beforeEach() { Images.loadBusybox(K3S); @@ -51,8 +57,20 @@ void afterEach() { } @Test - void test(CapturedOutput output) { + void test(CapturedOutput output) throws Exception { + + String[] busyboxPods = K3S.execInContainer("sh", "-c", "kubectl get pods -l app=busybox -o=name --no-headers") + .getStdout() + .split("\n"); + + String podOne = busyboxPods[0].split("/")[1]; + String podTwo = busyboxPods[1].split("/")[1]; + + K3S.execInContainer("sh", "-c", "kubectl label pods " + podOne + " my-label=my-value"); + K3S.execInContainer("sh", "-c", "kubectl annotate pods " + podTwo + " my-annotation=my-value"); + assertBlockingConfiguration(output, port); + assertPodMetadata(discoveryClient); } } diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/discovery/Fabric8DiscoveryPodMetadataIT.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/discovery/Fabric8DiscoveryPodMetadataIT.java deleted file mode 100644 index 46d0e6ce2f..0000000000 --- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/discovery/Fabric8DiscoveryPodMetadataIT.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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 org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -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 static org.springframework.cloud.kubernetes.fabric8.client.discovery.TestAssertions.assertPodMetadata; - -/** - * @author wind57 - */ -class Fabric8DiscoveryPodMetadataIT extends Fabric8DiscoveryBase { - - @Autowired - private DiscoveryClient discoveryClient; - - @BeforeEach - void beforeEach() { - Images.loadBusybox(K3S); - util.busybox(NAMESPACE, Phase.CREATE); - } - - @AfterEach - void afterEach() { - util.busybox(NAMESPACE, Phase.DELETE); - } - - /** - *
-	 * 		- there is a 'busybox-service' service deployed with two pods
-	 * 		- find each of the pod, add annotation to one, and labels to another
-	 * 		- call DiscoveryClient::getInstances with this serviceId and assert fields returned
-	 * 
- */ - @Test - void test() throws Exception { - String[] busyboxPods = K3S.execInContainer("sh", "-c", "kubectl get pods -l app=busybox -o=name --no-headers") - .getStdout() - .split("\n"); - - String podOne = busyboxPods[0].split("/")[1]; - String podTwo = busyboxPods[1].split("/")[1]; - - K3S.execInContainer("sh", "-c", "kubectl label pods " + podOne + " my-label=my-value"); - K3S.execInContainer("sh", "-c", "kubectl annotate pods " + podTwo + " my-annotation=my-value"); - - assertPodMetadata(discoveryClient); - } - -} From f599aa4205f7de3734c586ba278c4b86b1405f57 Mon Sep 17 00:00:00 2001 From: wind57 Date: Sun, 19 Jan 2025 10:59:04 +0200 Subject: [PATCH 6/7] rename a test Signed-off-by: wind57 --- ...rMatchTwoNamespacesIT.java => Fabric8DiscoveryFilterIT.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/discovery/{Fabric8DiscoveryFilterMatchTwoNamespacesIT.java => Fabric8DiscoveryFilterIT.java} (96%) diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/discovery/Fabric8DiscoveryFilterMatchTwoNamespacesIT.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/discovery/Fabric8DiscoveryFilterIT.java similarity index 96% rename from spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/discovery/Fabric8DiscoveryFilterMatchTwoNamespacesIT.java rename to spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/discovery/Fabric8DiscoveryFilterIT.java index 2fab71e697..dfbe1ad2ac 100644 --- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/discovery/Fabric8DiscoveryFilterMatchTwoNamespacesIT.java +++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/discovery/Fabric8DiscoveryFilterIT.java @@ -35,7 +35,7 @@ "spring.cloud.kubernetes.discovery.namespaces[1]=b-uat", "spring.cloud.kubernetes.discovery.filter=#root.metadata.namespace matches '^.*uat$'", "logging.level.org.springframework.cloud.kubernetes.fabric8.discovery=DEBUG" }) -class Fabric8DiscoveryFilterMatchTwoNamespacesIT extends Fabric8DiscoveryBase { +class Fabric8DiscoveryFilterIT extends Fabric8DiscoveryBase { private static final String NAMESPACE_A_UAT = "a-uat"; From 442aa97ed88e69168eb0eae90f6c9e255ef9e1ff Mon Sep 17 00:00:00 2001 From: wind57 Date: Mon, 20 Jan 2025 18:33:05 +0200 Subject: [PATCH 7/7] re-trigger Signed-off-by: wind57 --- .../src/main/resources/application-no-mount.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/main/resources/application-no-mount.yaml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/main/resources/application-no-mount.yaml index 4e98ed7073..329703db9c 100644 --- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/main/resources/application-no-mount.yaml +++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/main/resources/application-no-mount.yaml @@ -11,4 +11,3 @@ spring: strategy: refresh mode: polling period: 5s -