From 032014e7b841bb3346f2a9a097fe9bd5983a30e9 Mon Sep 17 00:00:00 2001 From: wind57 Date: Sat, 4 Dec 2021 07:59:07 -0800 Subject: [PATCH 001/151] test --- delme.sh | 1 + 1 file changed, 1 insertion(+) create mode 100644 delme.sh diff --git a/delme.sh b/delme.sh new file mode 100644 index 0000000000..707d90cb73 --- /dev/null +++ b/delme.sh @@ -0,0 +1 @@ +dadsa \ No newline at end of file From 10889fd1fc9c5ec3a32699d70d4a0e914aae7577 Mon Sep 17 00:00:00 2001 From: wind57 Date: Thu, 16 Dec 2021 04:15:40 -0800 Subject: [PATCH 002/151] fix @Nested tests not running --- .circleci/config.yml | 2 +- pom.xml | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 2f197c14d8..7eed9f3449 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -44,7 +44,7 @@ jobs: echo $CLASSNAMES TEST_ARG=$(echo $CLASSNAMES | sed 's/ /,/g') echo $TEST_ARG - ./mvnw -s .settings.xml -DfailIfNoTests=false -Dtest=$TEST_ARG -e clean org.jacoco:jacoco-maven-plugin:prepare-agent test -U -P sonar -nsu --batch-mode -Dmaven.test.redirectTestOutputToFile=true -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn + ./mvnw -s .settings.xml -DfailIfNoTests=false -DtestsToRun=$TEST_ARG -e clean org.jacoco:jacoco-maven-plugin:prepare-agent test -U -P sonar -nsu --batch-mode -Dmaven.test.redirectTestOutputToFile=true -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn mkdir -p $HOME/artifacts/junit/ find . -type f -regex ".*/spring-cloud-*.*/target/*.*" -exec cp {} $HOME/artifacts/ \; find . -type f -regex ".*/target/.*-reports/.*" -exec cp {} $HOME/artifacts/junit/ \; diff --git a/pom.xml b/pom.xml index 191dae7c2d..e25caca33c 100644 --- a/pom.xml +++ b/pom.xml @@ -204,6 +204,11 @@ all false + + + + ${testsToRun} + @@ -356,6 +361,11 @@ all false + + + + ${testsToRun} + ${surefireArgLine} From b041c00ea5cac0bb3e7bd43bc75ee470920cc3fe Mon Sep 17 00:00:00 2001 From: wind57 Date: Thu, 13 Jan 2022 15:33:08 +0200 Subject: [PATCH 003/151] trigger again From a34ac473971fca316b05a0b886de000f05220b1e Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 13 Jul 2022 08:43:39 +0000 Subject: [PATCH 004/151] Add renovate.json --- renovate.json | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 renovate.json diff --git a/renovate.json b/renovate.json new file mode 100644 index 0000000000..7bd954555f --- /dev/null +++ b/renovate.json @@ -0,0 +1,6 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "extends": [ + "config:base" + ] +} From 0c3ec3e6af823ad8959cdf1aadd3ce59d600b8ca Mon Sep 17 00:00:00 2001 From: wind57 Date: Sat, 18 Feb 2023 08:59:52 +0200 Subject: [PATCH 005/151] fix --- .../discovery/KubernetesDiscoveryClient.java | 4 ++-- .../KubernetesDiscoveryClientUtils.java | 8 ++----- .../KubernetesDiscoveryClientUtilsTests.java | 21 +++++++------------ 3 files changed, 12 insertions(+), 21 deletions(-) diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java index 916459d764..6dd268f528 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java @@ -104,7 +104,7 @@ public List getInstances(String serviceId) { Objects.requireNonNull(serviceId); List subsetsNS = getEndPointsList(serviceId).stream() - .map(x -> subsetsFromEndpoints(x, () -> client.getNamespace())).toList(); + .map(KubernetesDiscoveryClientUtils::subsetsFromEndpoints).toList(); List instances = new ArrayList<>(); if (!subsetsNS.isEmpty()) { @@ -131,7 +131,7 @@ public List getEndPointsList(String serviceId) { private List findEndPointsFilteredByNamespaces(String serviceId) { List endpoints = new ArrayList<>(); for (String ns : properties.namespaces()) { - endpoints.addAll(getClient().endpoints().inNamespace(ns).withField("metadata.name", serviceId) + endpoints.addAll(client.endpoints().inNamespace(ns).withField("metadata.name", serviceId) .withLabels(properties.serviceLabels()).list().getItems()); } return endpoints; diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtils.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtils.java index 73870207b1..4e699c3937 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtils.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtils.java @@ -20,7 +20,6 @@ import java.util.List; import java.util.Map; import java.util.Optional; -import java.util.function.Supplier; import java.util.stream.Collectors; import io.fabric8.kubernetes.api.model.EndpointPort; @@ -49,11 +48,8 @@ private KubernetesDiscoveryClientUtils() { } - static EndpointSubsetNS subsetsFromEndpoints(Endpoints endpoints, Supplier clientNamespace) { - if (endpoints != null && endpoints.getSubsets() != null) { - return new EndpointSubsetNS(endpoints.getMetadata().getNamespace(), endpoints.getSubsets()); - } - return new EndpointSubsetNS(clientNamespace.get(), List.of()); + static EndpointSubsetNS subsetsFromEndpoints(Endpoints endpoints) { + return new EndpointSubsetNS(endpoints.getMetadata().getNamespace(), endpoints.getSubsets()); } static int endpointsPort(EndpointSubset endpointSubset, String serviceId, KubernetesDiscoveryProperties properties, diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java index dcccde37b8..99f1f35726 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java @@ -46,31 +46,26 @@ @ExtendWith(OutputCaptureExtension.class) class KubernetesDiscoveryClientUtilsTests { - @Test - void testSubsetsFromEndpointsNullEndpoints() { - EndpointSubsetNS result = KubernetesDiscoveryClientUtils.subsetsFromEndpoints(null, () -> "default"); - Assertions.assertNotNull(result); - Assertions.assertEquals(result.endpointSubset(), List.of()); - Assertions.assertEquals(result.namespace(), "default"); - } - @Test void testSubsetsFromEndpointsEmptySubsets() { Endpoints endpoints = new EndpointsBuilder() .withMetadata(new ObjectMetaBuilder().withNamespace("non-default").build()).build(); - EndpointSubsetNS result = KubernetesDiscoveryClientUtils.subsetsFromEndpoints(endpoints, () -> "default"); + EndpointSubsetNS result = KubernetesDiscoveryClientUtils.subsetsFromEndpoints(endpoints); Assertions.assertNotNull(result); Assertions.assertEquals(result.endpointSubset(), List.of()); Assertions.assertEquals(result.namespace(), "non-default"); } @Test - void testSubsetsFromEndpointsNullSubsets() { + void testSubsetsFromEndpointsNonEmptySubsets() { Endpoints endpoints = new EndpointsBuilder().withSubsets((List) null) - .withMetadata(new ObjectMetaBuilder().withNamespace("non-default").build()).build(); - EndpointSubsetNS result = KubernetesDiscoveryClientUtils.subsetsFromEndpoints(endpoints, () -> "default"); + .withMetadata(new ObjectMetaBuilder().withNamespace("default").build()) + .withSubsets(new EndpointSubsetBuilder().withPorts(new EndpointPortBuilder().withPort(8080).build()).build()) + .build(); + EndpointSubsetNS result = KubernetesDiscoveryClientUtils.subsetsFromEndpoints(endpoints); Assertions.assertNotNull(result); - Assertions.assertEquals(result.endpointSubset(), List.of()); + Assertions.assertEquals(result.endpointSubset().size(), 1); + Assertions.assertEquals(result.endpointSubset().get(0).getPorts().get(0).getPort(), 8080); Assertions.assertEquals(result.namespace(), "default"); } From f143df6eb8f19defcb850ffb5da9f44c2b88ed99 Mon Sep 17 00:00:00 2001 From: wind57 Date: Sat, 18 Feb 2023 23:53:07 +0200 Subject: [PATCH 006/151] no targeted tests --- .../kubernetes/fabric8/Fabric8Utils.java | 15 ++++---- .../discovery/KubernetesDiscoveryClient.java | 35 +++++++++---------- .../KubernetesDiscoveryClientUtils.java | 11 ++++++ ...etesDiscoveryClientFilterMetadataTest.java | 21 +++++++---- .../KubernetesDiscoveryClientUtilsTests.java | 3 +- 5 files changed, 51 insertions(+), 34 deletions(-) diff --git a/spring-cloud-kubernetes-fabric8-autoconfig/src/main/java/org/springframework/cloud/kubernetes/fabric8/Fabric8Utils.java b/spring-cloud-kubernetes-fabric8-autoconfig/src/main/java/org/springframework/cloud/kubernetes/fabric8/Fabric8Utils.java index 2aa5fa20b3..dbc0ddd1bb 100644 --- a/spring-cloud-kubernetes-fabric8-autoconfig/src/main/java/org/springframework/cloud/kubernetes/fabric8/Fabric8Utils.java +++ b/spring-cloud-kubernetes-fabric8-autoconfig/src/main/java/org/springframework/cloud/kubernetes/fabric8/Fabric8Utils.java @@ -17,6 +17,7 @@ package org.springframework.cloud.kubernetes.fabric8; import io.fabric8.kubernetes.client.KubernetesClient; +import jakarta.annotation.Nullable; import org.apache.commons.logging.LogFactory; import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider; @@ -39,14 +40,14 @@ private Fabric8Utils() { private static final LogAccessor LOG = new LogAccessor(LogFactory.getLog(Fabric8Utils.class)); /** - * this method does the namespace resolution for both config map and secrets - * implementations. It tries these places to find the namespace: + * this method does the namespace resolution. Namespace is being searched according to the + * order below. * *
-	 *     1. from a normalized source (which can be null)
-	 *     2. from a property 'spring.cloud.kubernetes.client.namespace', if such is present
+	 *     1. from incoming namespace, which can be null.
+	 *     2. from a property 'spring.cloud.kubernetes.client.namespace', if such is present.
 	 *     3. from a String residing in a file denoted by `spring.cloud.kubernetes.client.serviceAccountNamespacePath`
-	 * 	      property, if such is present
+	 * 	      property, if such is present.
 	 * 	   4. from a String residing in `/var/run/secrets/kubernetes.io/serviceaccount/namespace` file,
 	 * 	  	  if such is present (kubernetes default path)
 	 * 	   5. from KubernetesClient::getNamespace, which is implementation specific.
@@ -60,8 +61,8 @@ private Fabric8Utils() {
 	 * @return application namespace
 	 * @throws NamespaceResolutionFailedException when namespace could not be resolved
 	 */
-	public static String getApplicationNamespace(KubernetesClient client, String namespace, String configurationTarget,
-			KubernetesNamespaceProvider provider) {
+	public static String getApplicationNamespace(KubernetesClient client, @Nullable String namespace,
+			String configurationTarget, KubernetesNamespaceProvider provider) {
 
 		if (StringUtils.hasText(namespace)) {
 			LOG.debug(configurationTarget + " namespace : " + namespace);
diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java
index 6dd268f528..9c7d29e77a 100644
--- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java
+++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java
@@ -42,9 +42,9 @@
 import static java.util.stream.Collectors.toMap;
 import static org.springframework.cloud.kubernetes.commons.config.ConfigUtils.keysWithPrefix;
 import static org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryConstants.NAMESPACE_METADATA_KEY;
+import static org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientUtils.endpoints;
 import static org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientUtils.endpointsPort;
 import static org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientUtils.serviceMetadata;
-import static org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientUtils.subsetsFromEndpoints;
 
 /**
  * Kubernetes implementation of {@link DiscoveryClient}.
@@ -107,10 +107,8 @@ public List getInstances(String serviceId) {
 				.map(KubernetesDiscoveryClientUtils::subsetsFromEndpoints).toList();
 
 		List instances = new ArrayList<>();
-		if (!subsetsNS.isEmpty()) {
-			for (EndpointSubsetNS es : subsetsNS) {
-				instances.addAll(getNamespaceServiceInstances(es, serviceId));
-			}
+		for (EndpointSubsetNS es : subsetsNS) {
+			instances.addAll(getNamespaceServiceInstances(es, serviceId));
 		}
 
 		return instances;
@@ -118,23 +116,22 @@ public List getInstances(String serviceId) {
 
 	public List getEndPointsList(String serviceId) {
 		if (properties.allNamespaces()) {
-			return client.endpoints().inAnyNamespace().withField("metadata.name", serviceId)
-					.withLabels(properties.serviceLabels()).list().getItems();
+			LOG.debug(() -> "searching for endpoints in all namespaces");
+			return endpoints(client.endpoints().inAnyNamespace().withNewFilter(), properties, serviceId);
 		}
-		if (properties.namespaces().isEmpty()) {
-			return client.endpoints().withField("metadata.name", serviceId).withLabels(properties.serviceLabels())
-					.list().getItems();
+		else if (properties.namespaces().isEmpty()) {
+			LOG.debug(() -> "searching for endpoints in namespace : " + client.getNamespace());
+			return endpoints(client.endpoints().withNewFilter(), properties, serviceId);
 		}
-		return findEndPointsFilteredByNamespaces(serviceId);
-	}
-
-	private List findEndPointsFilteredByNamespaces(String serviceId) {
-		List endpoints = new ArrayList<>();
-		for (String ns : properties.namespaces()) {
-			endpoints.addAll(client.endpoints().inNamespace(ns).withField("metadata.name", serviceId)
-					.withLabels(properties.serviceLabels()).list().getItems());
+		else {
+			LOG.debug(() -> "searching for endpoints in namespaces : " + properties.namespaces());
+			List endpoints = new ArrayList<>();
+			for (String namespace : properties.namespaces()) {
+				endpoints.addAll(
+						endpoints(client.endpoints().inNamespace(namespace).withNewFilter(), properties, serviceId));
+			}
+			return endpoints;
 		}
-		return endpoints;
 	}
 
 	private List getNamespaceServiceInstances(EndpointSubsetNS es, String serviceId) {
diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtils.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtils.java
index 4e699c3937..46d7008bcc 100644
--- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtils.java
+++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtils.java
@@ -25,7 +25,11 @@
 import io.fabric8.kubernetes.api.model.EndpointPort;
 import io.fabric8.kubernetes.api.model.EndpointSubset;
 import io.fabric8.kubernetes.api.model.Endpoints;
+import io.fabric8.kubernetes.api.model.EndpointsList;
 import io.fabric8.kubernetes.api.model.Service;
+import io.fabric8.kubernetes.client.dsl.FilterNested;
+import io.fabric8.kubernetes.client.dsl.FilterWatchListDeletable;
+import io.fabric8.kubernetes.client.dsl.Resource;
 import org.apache.commons.logging.LogFactory;
 
 import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
@@ -137,6 +141,13 @@ static Map serviceMetadata(String serviceId, Service service,
 		return serviceMetadata;
 	}
 
+	static List endpoints(
+			FilterNested>> filterNested,
+			KubernetesDiscoveryProperties properties, String serviceId) {
+		return filterNested.withField("metadata.name", serviceId).withLabels(properties.serviceLabels()).endFilter()
+				.list().getItems();
+	}
+
 	private static Optional fromMap(Map existingPorts, String key, String message) {
 		Integer fromPrimaryPortName = existingPorts.get(key);
 		if (fromPrimaryPortName == null) {
diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientFilterMetadataTest.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientFilterMetadataTest.java
index 6b0300c9b1..f802cdf848 100644
--- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientFilterMetadataTest.java
+++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientFilterMetadataTest.java
@@ -33,6 +33,7 @@
 import io.fabric8.kubernetes.api.model.ServicePort;
 import io.fabric8.kubernetes.api.model.ServicePortBuilder;
 import io.fabric8.kubernetes.client.KubernetesClient;
+import io.fabric8.kubernetes.client.dsl.FilterNested;
 import io.fabric8.kubernetes.client.dsl.FilterWatchListDeletable;
 import io.fabric8.kubernetes.client.dsl.MixedOperation;
 import io.fabric8.kubernetes.client.dsl.Resource;
@@ -53,6 +54,7 @@
 import static org.mockito.Mockito.when;
 import static org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties.Metadata;
 
+@SuppressWarnings("unchecked")
 class KubernetesDiscoveryClientFilterMetadataTest {
 
 	private static final KubernetesClient CLIENT = Mockito.mock(KubernetesClient.class);
@@ -68,6 +70,9 @@ class KubernetesDiscoveryClientFilterMetadataTest {
 	private final FilterWatchListDeletable> filter = Mockito
 			.mock(FilterWatchListDeletable.class);
 
+	private final FilterNested>> filterNested = Mockito
+			.mock(FilterNested.class);
+
 	@Test
 	void testAllExtraMetadataDisabled() {
 		String serviceId = "s";
@@ -218,10 +223,10 @@ private void setupServiceWithLabelsAndAnnotationsAndPorts(String serviceId, Stri
 		Service service = new ServiceBuilder().withNewMetadata().withNamespace(namespace).withLabels(labels)
 				.withAnnotations(annotations).endMetadata().withNewSpec().withPorts(getServicePorts(ports)).endSpec()
 				.build();
-		when(this.serviceOperation.withName(serviceId)).thenReturn(this.serviceResource);
-		when(this.serviceResource.get()).thenReturn(service);
-		when(CLIENT.services()).thenReturn(this.serviceOperation);
-		when(CLIENT.services().inNamespace(anyString())).thenReturn(this.serviceOperation);
+		when(serviceOperation.withName(serviceId)).thenReturn(serviceResource);
+		when(serviceResource.get()).thenReturn(service);
+		when(CLIENT.services()).thenReturn(serviceOperation);
+		when(CLIENT.services().inNamespace(anyString())).thenReturn(serviceOperation);
 
 		ObjectMeta objectMeta = new ObjectMeta();
 		objectMeta.setNamespace(namespace);
@@ -229,13 +234,15 @@ private void setupServiceWithLabelsAndAnnotationsAndPorts(String serviceId, Stri
 		Endpoints endpoints = new EndpointsBuilder().withMetadata(objectMeta).addNewSubset()
 				.addAllToPorts(getEndpointPorts(ports)).addNewAddress().endAddress().endSubset().build();
 
-		when(CLIENT.endpoints()).thenReturn(this.endpointsOperation);
+		when(CLIENT.endpoints()).thenReturn(endpointsOperation);
+		when(endpointsOperation.withNewFilter()).thenReturn(filterNested);
 
 		EndpointsList endpointsList = new EndpointsList(null, Collections.singletonList(endpoints), null, null);
 		when(filter.list()).thenReturn(endpointsList);
-		when(filter.withLabels(anyMap())).thenReturn(filter);
+		when(filterNested.withLabels(anyMap())).thenReturn(filterNested);
 
-		when(CLIENT.endpoints().withField(eq("metadata.name"), eq(serviceId))).thenReturn(filter);
+		when(filterNested.withField(eq("metadata.name"), eq(serviceId))).thenReturn(filterNested);
+		when(filterNested.endFilter()).thenReturn(filter);
 
 	}
 
diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java
index 99f1f35726..df55a0a192 100644
--- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java
+++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java
@@ -60,7 +60,8 @@ void testSubsetsFromEndpointsEmptySubsets() {
 	void testSubsetsFromEndpointsNonEmptySubsets() {
 		Endpoints endpoints = new EndpointsBuilder().withSubsets((List) null)
 				.withMetadata(new ObjectMetaBuilder().withNamespace("default").build())
-				.withSubsets(new EndpointSubsetBuilder().withPorts(new EndpointPortBuilder().withPort(8080).build()).build())
+				.withSubsets(
+						new EndpointSubsetBuilder().withPorts(new EndpointPortBuilder().withPort(8080).build()).build())
 				.build();
 		EndpointSubsetNS result = KubernetesDiscoveryClientUtils.subsetsFromEndpoints(endpoints);
 		Assertions.assertNotNull(result);

From 7fc0bb9a8e1ba7878402ffccb9f0b7211e3b5d00 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Sun, 19 Feb 2023 15:33:55 +0200
Subject: [PATCH 007/151] added tests

---
 .../KubernetesDiscoveryClientTests.java       | 478 ++++++++++++++++++
 1 file changed, 478 insertions(+)
 create mode 100644 spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientTests.java

diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientTests.java
new file mode 100644
index 0000000000..b40010466f
--- /dev/null
+++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientTests.java
@@ -0,0 +1,478 @@
+/*
+ * Copyright 2013-2023 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.discovery;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import io.fabric8.kubernetes.api.model.Endpoints;
+import io.fabric8.kubernetes.api.model.EndpointsBuilder;
+import io.fabric8.kubernetes.api.model.ObjectMeta;
+import io.fabric8.kubernetes.api.model.ObjectMetaBuilder;
+import io.fabric8.kubernetes.client.Config;
+import io.fabric8.kubernetes.client.KubernetesClient;
+import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+import org.springframework.boot.test.system.CapturedOutput;
+import org.springframework.boot.test.system.OutputCaptureExtension;
+import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
+
+/**
+ * @author wind57
+ */
+@EnableKubernetesMockClient(crud = true, https = false)
+@ExtendWith(OutputCaptureExtension.class)
+class KubernetesDiscoveryClientTests {
+
+	private static KubernetesClient client;
+
+	@BeforeAll
+	static void setUp() {
+		// Configure the kubernetes master url to point to the mock server
+		System.setProperty(Config.KUBERNETES_MASTER_SYSTEM_PROPERTY, client.getConfiguration().getMasterUrl());
+		System.setProperty(Config.KUBERNETES_TRUST_CERT_SYSTEM_PROPERTY, "true");
+		System.setProperty(Config.KUBERNETES_AUTH_TRYKUBECONFIG_SYSTEM_PROPERTY, "false");
+		System.setProperty(Config.KUBERNETES_AUTH_TRYSERVICEACCOUNT_SYSTEM_PROPERTY, "false");
+		System.setProperty(Config.KUBERNETES_NAMESPACE_SYSTEM_PROPERTY, "test");
+		System.setProperty(Config.KUBERNETES_HTTP2_DISABLE, "true");
+	}
+
+	@AfterEach
+	void afterEach() {
+		client.endpoints().inAnyNamespace().delete();
+	}
+
+	/**
+	 * 
+	 *     - all-namespaces = true
+	 *     - there are no endpoints at all
+	 *     - as a result we get an empty list
+	 * 
+ */ + @Test + void testAllNamespacesEmpty(CapturedOutput output) { + boolean allNamespaces = true; + Set namespaces = Set.of(); + Map serviceLabels = Map.of(); + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, + true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); + + KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null); + List result = discoveryClient.getEndPointsList("serviceId"); + Assertions.assertEquals(result.size(), 0); + Assertions.assertTrue(output.getOut().contains("searching for endpoints in all namespaces")); + } + + /** + *
+	 *     - all-namespaces = true
+	 *     - one endpoints with labels : "color=blue" and name "blue-service" exists
+	 *     - we search for labels : "color=blue" and name "blue-service"
+	 *     - we find this endpoints
+	 * 
+ */ + @Test + void testAllNamespacesSingleEndpointsMatchExactLabels(CapturedOutput output) { + + createEndpoints("default", "blue-service", Map.of("color", "blue")); + + boolean allNamespaces = true; + Set namespaces = Set.of(); + Map serviceLabels = Map.of("color", "blue"); + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, + true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); + + KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null); + List result = discoveryClient.getEndPointsList("blue-service"); + Assertions.assertEquals(result.size(), 1); + Assertions.assertTrue(output.getOut().contains("searching for endpoints in all namespaces")); + } + + /** + *
+	 *     - all-namespaces = true
+	 *     - one endpoints with labels : "color=blue, shape=round" and name "blue-service" exists
+	 *     - we search for labels : "color=blue" and name "blue-service"
+	 *     - we find this endpoints
+	 * 
+ */ + @Test + void testAllNamespacesSingleEndpointsMatchPartialLabels(CapturedOutput output) { + + createEndpoints("default", "blue-service", Map.of("color", "blue", "shape", "round")); + + boolean allNamespaces = true; + Set namespaces = Set.of(); + Map serviceLabels = Map.of("color", "blue"); + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, + true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); + + KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null); + List result = discoveryClient.getEndPointsList("blue-service"); + Assertions.assertEquals(result.size(), 1); + Assertions.assertTrue(output.getOut().contains("searching for endpoints in all namespaces")); + } + + /** + *
+	 *     - all-namespaces = true
+	 *     - one endpoints with labels : "color=red, shape=round" and name "blue-service" exists
+	 *     - we search for labels : "color=red" and name "blue-service"
+	 *     - name matches, but labels don't, as such we do not find this endpoints
+	 * 
+ */ + @Test + void testAllNamespacesSingleEndpointsNameMatchesLabelsDont(CapturedOutput output) { + + createEndpoints("default", "blue-service", Map.of("color", "red", "shape", "round")); + + boolean allNamespaces = true; + Set namespaces = Set.of(); + Map serviceLabels = Map.of("color", "blue"); + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, + true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); + + KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null); + List result = discoveryClient.getEndPointsList("blue-service"); + Assertions.assertEquals(result.size(), 0); + Assertions.assertTrue(output.getOut().contains("searching for endpoints in all namespaces")); + } + + /** + *
+	 *     - all-namespaces = true
+	 *     - one endpoints with labels : "color=blue, shape=round" and name "service-one" exists
+	 *     - one endpoints with labels : "color=blue, shape=round" and name "service-two" exists
+	 *     - we search for labels : "color=blue" and name "service-one" and find a single service
+	 * 
+ */ + @Test + void testAllNamespacesTwoEndpointsOneMatches(CapturedOutput output) { + + createEndpoints("default", "service-one", Map.of("color", "blue", "shape", "round")); + createEndpoints("default", "service-two", Map.of("color", "blue", "shape", "round")); + + boolean allNamespaces = true; + Set namespaces = Set.of(); + Map serviceLabels = Map.of("color", "blue"); + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, + true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); + + KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null); + List result = discoveryClient.getEndPointsList("service-one"); + Assertions.assertEquals(result.size(), 1); + Assertions.assertTrue(output.getOut().contains("searching for endpoints in all namespaces")); + } + + /** + *
+	 *     - all-namespaces = true
+	 *     - one endpoints with labels : "color=blue, shape=round" and name "service-one" exists in namespace "a"
+	 *     - one endpoints with labels : "color=blue, shape=round" and name "service-one" exists in namespace "b"
+	 *     - we search for labels : "color=blue" and name "service-one" and find two services
+	 * 
+ */ + @Test + void testAllNamespacesTwoEndpointsInDifferentNamespaces(CapturedOutput output) { + + createEndpoints("a", "service-one", Map.of("color", "blue", "shape", "round")); + createEndpoints("b", "service-one", Map.of("color", "blue", "shape", "round")); + + boolean allNamespaces = true; + Set namespaces = Set.of(); + Map serviceLabels = Map.of("color", "blue"); + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, + true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); + + KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null); + List result = discoveryClient.getEndPointsList("service-one"); + Assertions.assertEquals(result.size(), 2); + Assertions.assertEquals( + result.stream().map(Endpoints::getMetadata).map(ObjectMeta::getNamespace).sorted().toList(), + List.of("a", "b")); + Assertions.assertTrue(output.getOut().contains("searching for endpoints in all namespaces")); + } + + /** + *
+	 *     - all-namespaces = false
+	 *     - there are no endpoints at all
+	 *     - as a result we get an empty list
+	 * 
+ */ + @Test + void testClientNamespaceEmpty(CapturedOutput output) { + boolean allNamespaces = false; + Set namespaces = Set.of(); + Map serviceLabels = Map.of(); + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, + true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); + + KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null); + List result = discoveryClient.getEndPointsList("serviceId"); + Assertions.assertEquals(result.size(), 0); + Assertions.assertTrue(output.getOut().contains("searching for endpoints in namespace : test")); + } + + /** + *
+	 *     - all-namespaces = false
+	 *     - one endpoints with labels : "color=blue" and name "blue-service" exists
+	 *     - we search for labels : "color=blue" and name "blue-service"
+	 *     - we find this endpoints
+	 * 
+ */ + @Test + void testClientNamespaceSingleEndpointsMatchExactLabels(CapturedOutput output) { + + createEndpoints("test", "blue-service", Map.of("color", "blue")); + + boolean allNamespaces = false; + Set namespaces = Set.of(); + Map serviceLabels = Map.of("color", "blue"); + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, + true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); + + KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null); + List result = discoveryClient.getEndPointsList("blue-service"); + Assertions.assertEquals(result.size(), 1); + Assertions.assertTrue(output.getOut().contains("searching for endpoints in namespace : test")); + } + + /** + *
+	 *     - all-namespaces = false
+	 *     - one endpoints with labels : "color=blue, shape=round" and name "blue-service" exists
+	 *     - we search for labels : "color=blue" and name "blue-service"
+	 *     - we find this endpoints
+	 * 
+ */ + @Test + void testClientNamespaceSingleEndpointsMatchPartialLabels(CapturedOutput output) { + + createEndpoints("test", "blue-service", Map.of("color", "blue", "shape", "round")); + + boolean allNamespaces = false; + Set namespaces = Set.of(); + Map serviceLabels = Map.of("color", "blue"); + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, + true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); + + KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null); + List result = discoveryClient.getEndPointsList("blue-service"); + Assertions.assertEquals(result.size(), 1); + Assertions.assertTrue(output.getOut().contains("searching for endpoints in namespace : test")); + } + + /** + *
+	 *     - all-namespaces = false
+	 *     - one endpoints with labels : "color=red, shape=round" and name "blue-service" exists
+	 *     - we search for labels : "color=red" and name "blue-service"
+	 *     - name matches, but labels don't, as such we do not find this endpoints
+	 * 
+ */ + @Test + void testClientNamespaceSingleEndpointsNameMatchesLabelsDont(CapturedOutput output) { + + createEndpoints("test", "blue-service", Map.of("color", "red", "shape", "round")); + + boolean allNamespaces = false; + Set namespaces = Set.of(); + Map serviceLabels = Map.of("color", "blue"); + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, + true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); + + KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null); + List result = discoveryClient.getEndPointsList("blue-service"); + Assertions.assertEquals(result.size(), 0); + Assertions.assertTrue(output.getOut().contains("searching for endpoints in namespace : test")); + } + + /** + *
+	 *     - all-namespaces = false
+	 *     - one endpoints with labels : "color=blue, shape=round" and name "service-one" exists
+	 *     - one endpoints with labels : "color=blue, shape=round" and name "service-two" exists
+	 *     - we search for labels : "color=blue" and name "service-one" and find a single service
+	 * 
+ */ + @Test + void testClientNamespaceTwoEndpointsOneMatches(CapturedOutput output) { + + createEndpoints("test", "service-one", Map.of("color", "blue", "shape", "round")); + createEndpoints("test", "service-two", Map.of("color", "blue", "shape", "round")); + + boolean allNamespaces = false; + Set namespaces = Set.of(); + Map serviceLabels = Map.of("color", "blue"); + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, + true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); + + KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null); + List result = discoveryClient.getEndPointsList("service-one"); + Assertions.assertEquals(result.size(), 1); + Assertions.assertTrue(output.getOut().contains("searching for endpoints in namespace : test")); + } + + /** + *
+	 *     - all-namespaces = false
+	 *     - one endpoints with labels : "color=blue, shape=round" and name "service-one" exists in namespace "test"
+	 *     - one endpoints with labels : "color=blue, shape=round" and name "service-one" exists in namespace "b"
+	 *     - we search for labels : "color=blue" and name "service-one" and find one service
+	 * 
+ */ + @Test + void testClientNamespaceTwoEndpointsInDifferentNamespaces(CapturedOutput output) { + + createEndpoints("test", "service-one", Map.of("color", "blue", "shape", "round")); + createEndpoints("b", "service-one", Map.of("color", "blue", "shape", "round")); + + boolean allNamespaces = false; + Set namespaces = Set.of(); + Map serviceLabels = Map.of("color", "blue"); + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, + true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); + + KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null); + List result = discoveryClient.getEndPointsList("service-one"); + Assertions.assertEquals(result.size(), 1); + Assertions.assertEquals( + result.stream().map(Endpoints::getMetadata).map(ObjectMeta::getNamespace).sorted().toList(), + List.of("test")); + Assertions.assertTrue(output.getOut().contains("searching for endpoints in namespace : test")); + } + + /** + *
+	 *     - all-namespaces = false, selective namespaces = ["test"]
+	 *     - there are no endpoints at all
+	 *     - as a result we get an empty list
+	 * 
+ */ + @Test + void testSelectiveNamespacesEmpty(CapturedOutput output) { + boolean allNamespaces = false; + Set namespaces = Set.of("test"); + Map serviceLabels = Map.of(); + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, + true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); + + KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null); + List result = discoveryClient.getEndPointsList("serviceId"); + Assertions.assertEquals(result.size(), 0); + Assertions.assertTrue(output.getOut().contains("searching for endpoints in namespaces : [test]")); + } + + /** + *
+	 *     - all-namespaces = false, selective namespaces = ["test"]
+	 *     - one endpoints with labels : "color=blue" and name "blue-service" exists in namespace "test"
+	 *     - we search for labels : "color=blue" and name "blue-service"
+	 *     - we find this endpoints
+	 * 
+ */ + @Test + void testSelectiveNamespacesSingleEndpointsMatchExactLabels(CapturedOutput output) { + + createEndpoints("test", "blue-service", Map.of("color", "blue")); + + boolean allNamespaces = false; + Set namespaces = Set.of("test"); + Map serviceLabels = Map.of("color", "blue"); + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, + true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); + + KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null); + List result = discoveryClient.getEndPointsList("blue-service"); + Assertions.assertEquals(result.size(), 1); + Assertions.assertTrue(output.getOut().contains("searching for endpoints in namespaces : [test]")); + } + + /** + *
+	 *     - all-namespaces = false, selective namespaces = ["a", "b']
+	 *     - one endpoints with labels : "color=blue, shape=round" and name "blue-service" exists in namespace "a"
+	 *     - one endpoints with labels : "color=blue, shape=rectangle" and name "blue-service" exists in namespace "b"
+	 *     - we search for labels : "color=blue" and name "blue-service" in namespace "a"
+	 *     - we find this endpoints
+	 * 
+ */ + @Test + void testSelectiveNamespacesMultipleNamespacesSingleMatch(CapturedOutput output) { + + createEndpoints("a", "blue-service", Map.of("color", "blue", "shape", "round")); + createEndpoints("b", "blue-service", Map.of("color", "blue", "shape", "rectangle")); + + boolean allNamespaces = false; + Set namespaces = Set.of("a"); + Map serviceLabels = Map.of("color", "blue"); + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, + true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); + + KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null); + List result = discoveryClient.getEndPointsList("blue-service"); + Assertions.assertEquals(result.size(), 1); + Assertions.assertEquals(result.get(0).getMetadata().getLabels(), Map.of("color", "blue", "shape", "round")); + Assertions.assertTrue(output.getOut().contains("searching for endpoints in namespaces : [a]")); + } + + /** + *
+	 *     - all-namespaces = false, selective namespaces = ["a", "b']
+	 *     - one endpoints with labels : "color=blue" and name "blue-service" exists in namespace "a"
+	 *     - one endpoints with labels : "color=blue" and name "blue-service" exists in namespace "b"
+	 *     - we search for labels : "color=blue" and name "blue-service" in namespace "a" and "b"
+	 *     - we find both endpoints
+	 * 
+ */ + @Test + void testSelectiveNamespacesMultipleNamespacesAllMatch(CapturedOutput output) { + + createEndpoints("a", "blue-service", Map.of("color", "blue")); + createEndpoints("b", "blue-service", Map.of("color", "blue")); + + boolean allNamespaces = false; + Set namespaces = Set.of("a", "b"); + // so that assertion is correct + String namespacesAsString = namespaces.toString(); + Map serviceLabels = Map.of("color", "blue"); + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, + true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); + + KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null); + List result = discoveryClient.getEndPointsList("blue-service"); + Assertions.assertEquals(result.size(), 2); + Assertions + .assertTrue(output.getOut().contains("searching for endpoints in namespaces : " + namespacesAsString)); + } + + private void createEndpoints(String namespace, String name, Map labels) { + client.endpoints().inNamespace(namespace) + .resource(new EndpointsBuilder() + .withMetadata(new ObjectMetaBuilder().withName(name).withLabels(labels).build()).build()) + .create(); + } + +} From 01596ee4d0eb80a5798c8952e927b993fff766fc Mon Sep 17 00:00:00 2001 From: wind57 Date: Mon, 20 Feb 2023 07:20:30 +0200 Subject: [PATCH 008/151] started to add tests --- .../discovery/KubernetesDiscoveryClient.java | 74 ++++++++--------- .../KubernetesDiscoveryClientUtils.java | 15 +++- .../KubernetesDiscoveryClientUtilsTests.java | 79 ++++++++++++++++--- 3 files changed, 111 insertions(+), 57 deletions(-) diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java index 9c7d29e77a..39578f3c17 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java @@ -17,14 +17,12 @@ package org.springframework.cloud.kubernetes.fabric8.discovery; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.function.Predicate; import io.fabric8.kubernetes.api.model.EndpointAddress; -import io.fabric8.kubernetes.api.model.EndpointPort; import io.fabric8.kubernetes.api.model.EndpointSubset; import io.fabric8.kubernetes.api.model.Endpoints; import io.fabric8.kubernetes.api.model.Service; @@ -37,10 +35,7 @@ import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; import org.springframework.core.log.LogAccessor; import org.springframework.util.CollectionUtils; -import org.springframework.util.StringUtils; -import static java.util.stream.Collectors.toMap; -import static org.springframework.cloud.kubernetes.commons.config.ConfigUtils.keysWithPrefix; import static org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryConstants.NAMESPACE_METADATA_KEY; import static org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientUtils.endpoints; import static org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientUtils.endpointsPort; @@ -135,52 +130,45 @@ else if (properties.namespaces().isEmpty()) { } private List getNamespaceServiceInstances(EndpointSubsetNS es, String serviceId) { - String namespace = es.namespace(); + List subsets = es.endpointSubset(); + if (subsets.isEmpty()) { + LOG.debug(() -> "serviceId : " + serviceId + " does not have any subsets"); + return List.of(); + } + + String namespace = es.namespace(); List instances = new ArrayList<>(); - if (!subsets.isEmpty()) { - Service service = client.services().inNamespace(namespace).withName(serviceId).get(); - Map serviceMetadata = serviceMetadata(serviceId, service, properties); - KubernetesDiscoveryProperties.Metadata metadataProps = properties.metadata(); - - for (EndpointSubset s : subsets) { - // Extend the service metadata map with per-endpoint port information (if - // requested) - Map endpointMetadata = new HashMap<>(serviceMetadata); - if (metadataProps.addPorts()) { - Map ports = s.getPorts().stream() - .filter(port -> StringUtils.hasText(port.getName())) - .collect(toMap(EndpointPort::getName, port -> Integer.toString(port.getPort()))); - Map portMetadata = keysWithPrefix(ports, metadataProps.portsPrefix()); - LOG.debug(() -> "Adding port metadata: " + portMetadata); - endpointMetadata.putAll(portMetadata); - } - if (properties.allNamespaces()) { - endpointMetadata.put(NAMESPACE_METADATA_KEY, namespace); - } + Service service = client.services().inNamespace(namespace).withName(serviceId).get(); + Map serviceMetadata = serviceMetadata(serviceId, service, properties, subsets); + + for (EndpointSubset endpointSubset : subsets) { - List addresses = s.getAddresses(); + if (properties.allNamespaces()) { + serviceMetadata.put(NAMESPACE_METADATA_KEY, namespace); + } - if (properties.includeNotReadyAddresses() && !CollectionUtils.isEmpty(s.getNotReadyAddresses())) { - if (addresses == null) { - addresses = new ArrayList<>(); - } - addresses.addAll(s.getNotReadyAddresses()); + List addresses = endpointSubset.getAddresses(); + + if (properties.includeNotReadyAddresses() && !CollectionUtils.isEmpty(endpointSubset.getNotReadyAddresses())) { + if (addresses == null) { + addresses = new ArrayList<>(); } + addresses.addAll(endpointSubset.getNotReadyAddresses()); + } - for (EndpointAddress endpointAddress : addresses) { - int endpointPort = endpointsPort(s, serviceId, properties, service); - String instanceId = null; - if (endpointAddress.getTargetRef() != null) { - instanceId = endpointAddress.getTargetRef().getUid(); - } - instances.add(new DefaultKubernetesServiceInstance(instanceId, serviceId, endpointAddress.getIp(), - endpointPort, endpointMetadata, - servicePortSecureResolver.resolve(new ServicePortSecureResolver.Input(endpointPort, - service.getMetadata().getName(), service.getMetadata().getLabels(), - service.getMetadata().getAnnotations())))); + for (EndpointAddress endpointAddress : addresses) { + int endpointPort = endpointsPort(endpointSubset, serviceId, properties, service); + String instanceId = null; + if (endpointAddress.getTargetRef() != null) { + instanceId = endpointAddress.getTargetRef().getUid(); } + instances.add(new DefaultKubernetesServiceInstance(instanceId, serviceId, endpointAddress.getIp(), + endpointPort, serviceMetadata, + servicePortSecureResolver.resolve(new ServicePortSecureResolver.Input(endpointPort, + service.getMetadata().getName(), service.getMetadata().getLabels(), + service.getMetadata().getAnnotations())))); } } diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtils.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtils.java index 46d7008bcc..8b588815cc 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtils.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtils.java @@ -36,6 +36,7 @@ import org.springframework.core.log.LogAccessor; import org.springframework.util.StringUtils; +import static java.util.stream.Collectors.toMap; import static org.springframework.cloud.kubernetes.commons.config.ConfigUtils.keysWithPrefix; import static org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryConstants.HTTP; import static org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryConstants.HTTPS; @@ -121,8 +122,11 @@ static String primaryPortName(KubernetesDiscoveryProperties properties, Service return primaryPortName; } + /** + * labels, annotations and ports metadata. + */ static Map serviceMetadata(String serviceId, Service service, - KubernetesDiscoveryProperties properties) { + KubernetesDiscoveryProperties properties, List endpointSubsets) { Map serviceMetadata = new HashMap<>(); KubernetesDiscoveryProperties.Metadata metadataProps = properties.metadata(); if (metadataProps.addLabels()) { @@ -138,6 +142,15 @@ static Map serviceMetadata(String serviceId, Service service, serviceMetadata.putAll(annotationMetadata); } + if (metadataProps.addPorts()) { + Map ports = endpointSubsets.stream().flatMap(endpointSubset -> endpointSubset.getPorts().stream()) + .filter(port -> StringUtils.hasText(port.getName())) + .collect(toMap(EndpointPort::getName, port -> Integer.toString(port.getPort()))); + Map portMetadata = keysWithPrefix(ports, properties.metadata().portsPrefix()); + LOG.debug(() -> "Adding port metadata: " + portMetadata + " for serviceId : " + serviceId); + serviceMetadata.putAll(portMetadata); + } + return serviceMetadata; } diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java index df55a0a192..84458a02c7 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java @@ -333,13 +333,16 @@ void testServiceMetadataEmpty() { String labelsPrefix = ""; boolean addAnnotations = false; String annotationsPrefix = ""; + boolean addPorts = false; + String portsPrefix = ""; + KubernetesDiscoveryProperties.Metadata metadata = new KubernetesDiscoveryProperties.Metadata(addLabels, - labelsPrefix, addAnnotations, annotationsPrefix, false, ""); + labelsPrefix, addAnnotations, annotationsPrefix, addPorts, portsPrefix); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, true, "", Set.of(), Map.of(), "", metadata, 0, false); Service service = new ServiceBuilder().build(); - Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties); + Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, List.of()); Assertions.assertEquals(result.size(), 0); } @@ -355,14 +358,17 @@ void testServiceMetadataAddLabelsNoPrefix(CapturedOutput output) { String labelsPrefix = ""; boolean addAnnotations = false; String annotationsPrefix = ""; + boolean addPorts = false; + String portsPrefix = ""; + KubernetesDiscoveryProperties.Metadata metadata = new KubernetesDiscoveryProperties.Metadata(addLabels, - labelsPrefix, addAnnotations, annotationsPrefix, false, ""); + labelsPrefix, addAnnotations, annotationsPrefix, addPorts, portsPrefix); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, true, "", Set.of(), Map.of(), "", metadata, 0, false); Service service = new ServiceBuilder() .withMetadata(new ObjectMetaBuilder().withLabels(Map.of("a", "b")).build()).build(); - Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties); + Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, List.of()); Assertions.assertEquals(result.size(), 1); Assertions.assertEquals(result, Map.of("a", "b")); Assertions.assertTrue(output.getOut().contains("Adding labels metadata: {a=b} for serviceId: my-service")); @@ -380,14 +386,17 @@ void testServiceMetadataAddLabelsWithPrefix(CapturedOutput output) { String labelsPrefix = "prefix-"; boolean addAnnotations = false; String annotationsPrefix = ""; + boolean addPorts = false; + String portsPrefix = ""; + KubernetesDiscoveryProperties.Metadata metadata = new KubernetesDiscoveryProperties.Metadata(addLabels, - labelsPrefix, addAnnotations, annotationsPrefix, false, ""); + labelsPrefix, addAnnotations, annotationsPrefix, addPorts, portsPrefix); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, true, "", Set.of(), Map.of(), "", metadata, 0, false); Service service = new ServiceBuilder() .withMetadata(new ObjectMetaBuilder().withLabels(Map.of("a", "b", "c", "d")).build()).build(); - Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties); + Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, List.of()); Assertions.assertEquals(result.size(), 2); Assertions.assertEquals(result, Map.of("prefix-a", "b", "prefix-c", "d")); // so that result is deterministic in assertion @@ -408,15 +417,18 @@ void testServiceMetadataAddAnnotationsNoPrefix(CapturedOutput output) { String labelsPrefix = ""; boolean addAnnotations = true; String annotationsPrefix = ""; + boolean addPorts = false; + String portsPrefix = ""; + KubernetesDiscoveryProperties.Metadata metadata = new KubernetesDiscoveryProperties.Metadata(addLabels, - labelsPrefix, addAnnotations, annotationsPrefix, false, ""); + labelsPrefix, addAnnotations, annotationsPrefix, addPorts, portsPrefix); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, true, "", Set.of(), Map.of(), "", metadata, 0, false); Service service = new ServiceBuilder().withMetadata( new ObjectMetaBuilder().withAnnotations(Map.of("aa", "bb")).withLabels(Map.of("a", "b")).build()) .build(); - Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties); + Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, List.of()); Assertions.assertEquals(result.size(), 1); Assertions.assertEquals(result, Map.of("aa", "bb")); Assertions @@ -430,19 +442,22 @@ void testServiceMetadataAddAnnotationsNoPrefix(CapturedOutput output) { *
*/ @Test - void testServiceMetadataAddAnnotationsWithPrefixPrefix(CapturedOutput output) { + void testServiceMetadataAddAnnotationsWithPrefix(CapturedOutput output) { boolean addLabels = false; String labelsPrefix = ""; boolean addAnnotations = true; String annotationsPrefix = "prefix-"; + boolean addPorts = false; + String portsPrefix = ""; + KubernetesDiscoveryProperties.Metadata metadata = new KubernetesDiscoveryProperties.Metadata(addLabels, - labelsPrefix, addAnnotations, annotationsPrefix, false, ""); + labelsPrefix, addAnnotations, annotationsPrefix, addPorts, portsPrefix); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, true, "", Set.of(), Map.of(), "", metadata, 0, false); Service service = new ServiceBuilder().withMetadata(new ObjectMetaBuilder() .withAnnotations(Map.of("aa", "bb", "cc", "dd")).withLabels(Map.of("a", "b")).build()).build(); - Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties); + Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, List.of()); Assertions.assertEquals(result.size(), 2); Assertions.assertEquals(result, Map.of("prefix-aa", "bb", "prefix-cc", "dd")); // so that result is deterministic in assertion @@ -463,15 +478,18 @@ void testServiceMetadataAddLabelsAndAnnotationsWithPrefix(CapturedOutput output) String labelsPrefix = "label-"; boolean addAnnotations = true; String annotationsPrefix = "annotation-"; + boolean addPorts = false; + String portsPrefix = ""; + KubernetesDiscoveryProperties.Metadata metadata = new KubernetesDiscoveryProperties.Metadata(addLabels, - labelsPrefix, addAnnotations, annotationsPrefix, false, ""); + labelsPrefix, addAnnotations, annotationsPrefix, addPorts, portsPrefix); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, true, "", Set.of(), Map.of(), "", metadata, 0, false); Service service = new ServiceBuilder().withMetadata(new ObjectMetaBuilder() .withAnnotations(Map.of("aa", "bb", "cc", "dd")).withLabels(Map.of("a", "b", "c", "d")).build()) .build(); - Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties); + Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, List.of()); Assertions.assertEquals(result.size(), 4); Assertions.assertEquals(result, Map.of("annotation-aa", "bb", "annotation-cc", "dd", "label-a", "b", "label-c", "d")); @@ -486,4 +504,39 @@ void testServiceMetadataAddLabelsAndAnnotationsWithPrefix(CapturedOutput output) output.getOut().contains("Adding annotations metadata: " + annotations + " for serviceId: my-service")); } + /** + *
+	 *     - ports without prefix are added
+	 * 
+ */ + @Test + void testServiceMetadataAddPortsWithoutPrefix(CapturedOutput output) { + boolean addLabels = false; + String labelsPrefix = ""; + boolean addAnnotations = false; + String annotationsPrefix = "prefix-"; + boolean addPorts = true; + String portsPrefix = ""; + + KubernetesDiscoveryProperties.Metadata metadata = new KubernetesDiscoveryProperties.Metadata(addLabels, + labelsPrefix, addAnnotations, annotationsPrefix, addPorts, portsPrefix); + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, + true, "", Set.of(), Map.of(), "", metadata, 0, false); + Service service = new ServiceBuilder().withMetadata(new ObjectMetaBuilder() + .withAnnotations(Map.of("aa", "bb", "cc", "dd")).withLabels(Map.of("a", "b")).build()).build(); + + List endpointSubsets = List.of( + new EndpointSubsetBuilder().withPorts(new EndpointPortBuilder().withPort(8081).withName("").build()).build(), + new EndpointSubsetBuilder().withPorts(new EndpointPortBuilder().withPort(8080).withName("https").build()).build() + ); + + Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, List.of()); + Assertions.assertEquals(result.size(), 2); + Assertions.assertEquals(result, Map.of("prefix-aa", "bb", "prefix-cc", "dd")); + // so that result is deterministic in assertion + String annotations = result.toString(); + Assertions.assertTrue( + output.getOut().contains("Adding annotations metadata: " + annotations + " for serviceId: my-service")); + } + } From 2d2152a4dcb064007eb6fbd966f1b0cc9697981f Mon Sep 17 00:00:00 2001 From: wind57 Date: Mon, 20 Feb 2023 09:26:47 +0200 Subject: [PATCH 009/151] checkstyle --- .../fabric8/discovery/KubernetesDiscoveryClient.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java index 41d5aaeeb3..9c7d29e77a 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java @@ -118,15 +118,17 @@ public List getEndPointsList(String serviceId) { if (properties.allNamespaces()) { LOG.debug(() -> "searching for endpoints in all namespaces"); return endpoints(client.endpoints().inAnyNamespace().withNewFilter(), properties, serviceId); - } else if (properties.namespaces().isEmpty()) { + } + else if (properties.namespaces().isEmpty()) { LOG.debug(() -> "searching for endpoints in namespace : " + client.getNamespace()); return endpoints(client.endpoints().withNewFilter(), properties, serviceId); - } else { + } + else { LOG.debug(() -> "searching for endpoints in namespaces : " + properties.namespaces()); List endpoints = new ArrayList<>(); for (String namespace : properties.namespaces()) { endpoints.addAll( - endpoints(client.endpoints().inNamespace(namespace).withNewFilter(), properties, serviceId)); + endpoints(client.endpoints().inNamespace(namespace).withNewFilter(), properties, serviceId)); } return endpoints; } From 164c0a1e849110369906193928fa83b7715a3a85 Mon Sep 17 00:00:00 2001 From: wind57 Date: Mon, 20 Feb 2023 09:44:43 +0200 Subject: [PATCH 010/151] add some tests --- .../KubernetesDiscoveryClientUtilsTests.java | 41 ++++++++++++++++--- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java index 84458a02c7..f3fb174a8a 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java @@ -530,13 +530,44 @@ void testServiceMetadataAddPortsWithoutPrefix(CapturedOutput output) { new EndpointSubsetBuilder().withPorts(new EndpointPortBuilder().withPort(8080).withName("https").build()).build() ); - Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, List.of()); + Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, endpointSubsets); + Assertions.assertEquals(result.size(), 1); + Assertions.assertEquals(result, Map.of("https", "8080")); + Assertions.assertTrue( + output.getOut().contains("Adding port metadata: {https=8080} for serviceId : my-service")); + } + + /** + *
+	 *     - ports without prefix are added
+	 * 
+ */ + @Test + void testServiceMetadataAddPortsWithPrefix(CapturedOutput output) { + boolean addLabels = false; + String labelsPrefix = ""; + boolean addAnnotations = false; + String annotationsPrefix = "prefix-"; + boolean addPorts = true; + String portsPrefix = "prefix-"; + + KubernetesDiscoveryProperties.Metadata metadata = new KubernetesDiscoveryProperties.Metadata(addLabels, + labelsPrefix, addAnnotations, annotationsPrefix, addPorts, portsPrefix); + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, + true, "", Set.of(), Map.of(), "", metadata, 0, false); + Service service = new ServiceBuilder().withMetadata(new ObjectMetaBuilder() + .withAnnotations(Map.of("aa", "bb", "cc", "dd")).withLabels(Map.of("a", "b")).build()).build(); + + List endpointSubsets = List.of( + new EndpointSubsetBuilder().withPorts(new EndpointPortBuilder().withPort(8081).withName("http").build()).build(), + new EndpointSubsetBuilder().withPorts(new EndpointPortBuilder().withPort(8080).withName("https").build()).build() + ); + + Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, endpointSubsets); Assertions.assertEquals(result.size(), 2); - Assertions.assertEquals(result, Map.of("prefix-aa", "bb", "prefix-cc", "dd")); - // so that result is deterministic in assertion - String annotations = result.toString(); + Assertions.assertEquals(result, Map.of("prefix-https", "8080", "prefix-http", "8081")); Assertions.assertTrue( - output.getOut().contains("Adding annotations metadata: " + annotations + " for serviceId: my-service")); + output.getOut().contains("Adding port metadata: {prefix-http=8081, prefix-https=8080} for serviceId : my-service")); } } From abc4c32d51cc49b93fff4f610569ca230954e1d2 Mon Sep 17 00:00:00 2001 From: wind57 Date: Mon, 20 Feb 2023 11:26:22 +0200 Subject: [PATCH 011/151] fix --- .../discovery/KubernetesDiscoveryClient.java | 21 ++- .../KubernetesDiscoveryClientUtils.java | 13 +- .../KubernetesDiscoveryClientUtilsTests.java | 123 +++++++++++------- 3 files changed, 96 insertions(+), 61 deletions(-) diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java index 39578f3c17..a0b84d43b0 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java @@ -36,7 +36,6 @@ import org.springframework.core.log.LogAccessor; import org.springframework.util.CollectionUtils; -import static org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryConstants.NAMESPACE_METADATA_KEY; import static org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientUtils.endpoints; import static org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientUtils.endpointsPort; import static org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientUtils.serviceMetadata; @@ -141,17 +140,14 @@ private List getNamespaceServiceInstances(EndpointSubsetNS es, List instances = new ArrayList<>(); Service service = client.services().inNamespace(namespace).withName(serviceId).get(); - Map serviceMetadata = serviceMetadata(serviceId, service, properties, subsets); + Map serviceMetadata = serviceMetadata(serviceId, service, properties, subsets, namespace); for (EndpointSubset endpointSubset : subsets) { - if (properties.allNamespaces()) { - serviceMetadata.put(NAMESPACE_METADATA_KEY, namespace); - } - List addresses = endpointSubset.getAddresses(); - if (properties.includeNotReadyAddresses() && !CollectionUtils.isEmpty(endpointSubset.getNotReadyAddresses())) { + if (properties.includeNotReadyAddresses() + && !CollectionUtils.isEmpty(endpointSubset.getNotReadyAddresses())) { if (addresses == null) { addresses = new ArrayList<>(); } @@ -164,11 +160,12 @@ private List getNamespaceServiceInstances(EndpointSubsetNS es, if (endpointAddress.getTargetRef() != null) { instanceId = endpointAddress.getTargetRef().getUid(); } - instances.add(new DefaultKubernetesServiceInstance(instanceId, serviceId, endpointAddress.getIp(), - endpointPort, serviceMetadata, - servicePortSecureResolver.resolve(new ServicePortSecureResolver.Input(endpointPort, - service.getMetadata().getName(), service.getMetadata().getLabels(), - service.getMetadata().getAnnotations())))); + instances + .add(new DefaultKubernetesServiceInstance(instanceId, serviceId, endpointAddress.getIp(), + endpointPort, serviceMetadata, + servicePortSecureResolver.resolve(new ServicePortSecureResolver.Input(endpointPort, + service.getMetadata().getName(), service.getMetadata().getLabels(), + service.getMetadata().getAnnotations())))); } } diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtils.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtils.java index 8b588815cc..586e2358ff 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtils.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtils.java @@ -40,6 +40,7 @@ import static org.springframework.cloud.kubernetes.commons.config.ConfigUtils.keysWithPrefix; import static org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryConstants.HTTP; import static org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryConstants.HTTPS; +import static org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryConstants.NAMESPACE_METADATA_KEY; import static org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryConstants.PRIMARY_PORT_NAME_LABEL_KEY; /** @@ -123,10 +124,10 @@ static String primaryPortName(KubernetesDiscoveryProperties properties, Service } /** - * labels, annotations and ports metadata. + * labels, annotations, ports metadata and namespace metadata. */ static Map serviceMetadata(String serviceId, Service service, - KubernetesDiscoveryProperties properties, List endpointSubsets) { + KubernetesDiscoveryProperties properties, List endpointSubsets, String namespace) { Map serviceMetadata = new HashMap<>(); KubernetesDiscoveryProperties.Metadata metadataProps = properties.metadata(); if (metadataProps.addLabels()) { @@ -143,14 +144,16 @@ static Map serviceMetadata(String serviceId, Service service, } if (metadataProps.addPorts()) { - Map ports = endpointSubsets.stream().flatMap(endpointSubset -> endpointSubset.getPorts().stream()) - .filter(port -> StringUtils.hasText(port.getName())) - .collect(toMap(EndpointPort::getName, port -> Integer.toString(port.getPort()))); + Map ports = endpointSubsets.stream() + .flatMap(endpointSubset -> endpointSubset.getPorts().stream()) + .filter(port -> StringUtils.hasText(port.getName())) + .collect(toMap(EndpointPort::getName, port -> Integer.toString(port.getPort()))); Map portMetadata = keysWithPrefix(ports, properties.metadata().portsPrefix()); LOG.debug(() -> "Adding port metadata: " + portMetadata + " for serviceId : " + serviceId); serviceMetadata.putAll(portMetadata); } + serviceMetadata.put(NAMESPACE_METADATA_KEY, namespace); return serviceMetadata; } diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java index f3fb174a8a..d3ff17bdf5 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java @@ -336,14 +336,18 @@ void testServiceMetadataEmpty() { boolean addPorts = false; String portsPrefix = ""; + String namespace = "default"; + KubernetesDiscoveryProperties.Metadata metadata = new KubernetesDiscoveryProperties.Metadata(addLabels, labelsPrefix, addAnnotations, annotationsPrefix, addPorts, portsPrefix); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, true, "", Set.of(), Map.of(), "", metadata, 0, false); Service service = new ServiceBuilder().build(); - Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, List.of()); - Assertions.assertEquals(result.size(), 0); + Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, + List.of(), namespace); + Assertions.assertEquals(result.size(), 1); + Assertions.assertEquals(result, Map.of("k8s_namespace", "default")); } /** @@ -361,6 +365,8 @@ void testServiceMetadataAddLabelsNoPrefix(CapturedOutput output) { boolean addPorts = false; String portsPrefix = ""; + String namespace = "default"; + KubernetesDiscoveryProperties.Metadata metadata = new KubernetesDiscoveryProperties.Metadata(addLabels, labelsPrefix, addAnnotations, annotationsPrefix, addPorts, portsPrefix); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, @@ -368,10 +374,13 @@ void testServiceMetadataAddLabelsNoPrefix(CapturedOutput output) { Service service = new ServiceBuilder() .withMetadata(new ObjectMetaBuilder().withLabels(Map.of("a", "b")).build()).build(); - Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, List.of()); - Assertions.assertEquals(result.size(), 1); - Assertions.assertEquals(result, Map.of("a", "b")); - Assertions.assertTrue(output.getOut().contains("Adding labels metadata: {a=b} for serviceId: my-service")); + Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, + List.of(), namespace); + Assertions.assertEquals(result.size(), 2); + Assertions.assertEquals(result, Map.of("a", "b", "k8s_namespace", "default")); + String labelsMetadata = filterOnK8sNamespace(result); + Assertions.assertTrue( + output.getOut().contains("Adding labels metadata: " + labelsMetadata + " for serviceId: my-service")); } /** @@ -389,6 +398,8 @@ void testServiceMetadataAddLabelsWithPrefix(CapturedOutput output) { boolean addPorts = false; String portsPrefix = ""; + String namespace = "default"; + KubernetesDiscoveryProperties.Metadata metadata = new KubernetesDiscoveryProperties.Metadata(addLabels, labelsPrefix, addAnnotations, annotationsPrefix, addPorts, portsPrefix); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, @@ -396,13 +407,14 @@ void testServiceMetadataAddLabelsWithPrefix(CapturedOutput output) { Service service = new ServiceBuilder() .withMetadata(new ObjectMetaBuilder().withLabels(Map.of("a", "b", "c", "d")).build()).build(); - Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, List.of()); - Assertions.assertEquals(result.size(), 2); - Assertions.assertEquals(result, Map.of("prefix-a", "b", "prefix-c", "d")); + Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, + List.of(), namespace); + Assertions.assertEquals(result.size(), 3); + Assertions.assertEquals(result, Map.of("prefix-a", "b", "prefix-c", "d", "k8s_namespace", "default")); // so that result is deterministic in assertion - String labels = result.toString(); + String labelsMetadata = filterOnK8sNamespace(result); Assertions.assertTrue( - output.getOut().contains("Adding labels metadata: " + labels + " for serviceId: my-service")); + output.getOut().contains("Adding labels metadata: " + labelsMetadata + " for serviceId: my-service")); } /** @@ -420,6 +432,8 @@ void testServiceMetadataAddAnnotationsNoPrefix(CapturedOutput output) { boolean addPorts = false; String portsPrefix = ""; + String namespace = "default"; + KubernetesDiscoveryProperties.Metadata metadata = new KubernetesDiscoveryProperties.Metadata(addLabels, labelsPrefix, addAnnotations, annotationsPrefix, addPorts, portsPrefix); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, @@ -428,9 +442,10 @@ void testServiceMetadataAddAnnotationsNoPrefix(CapturedOutput output) { new ObjectMetaBuilder().withAnnotations(Map.of("aa", "bb")).withLabels(Map.of("a", "b")).build()) .build(); - Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, List.of()); - Assertions.assertEquals(result.size(), 1); - Assertions.assertEquals(result, Map.of("aa", "bb")); + Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, + List.of(), namespace); + Assertions.assertEquals(result.size(), 2); + Assertions.assertEquals(result, Map.of("aa", "bb", "k8s_namespace", "default")); Assertions .assertTrue(output.getOut().contains("Adding annotations metadata: {aa=bb} for serviceId: my-service")); } @@ -450,6 +465,8 @@ void testServiceMetadataAddAnnotationsWithPrefix(CapturedOutput output) { boolean addPorts = false; String portsPrefix = ""; + String namespace = "default"; + KubernetesDiscoveryProperties.Metadata metadata = new KubernetesDiscoveryProperties.Metadata(addLabels, labelsPrefix, addAnnotations, annotationsPrefix, addPorts, portsPrefix); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, @@ -457,11 +474,12 @@ void testServiceMetadataAddAnnotationsWithPrefix(CapturedOutput output) { Service service = new ServiceBuilder().withMetadata(new ObjectMetaBuilder() .withAnnotations(Map.of("aa", "bb", "cc", "dd")).withLabels(Map.of("a", "b")).build()).build(); - Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, List.of()); - Assertions.assertEquals(result.size(), 2); - Assertions.assertEquals(result, Map.of("prefix-aa", "bb", "prefix-cc", "dd")); + Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, + List.of(), namespace); + Assertions.assertEquals(result.size(), 3); + Assertions.assertEquals(result, Map.of("prefix-aa", "bb", "prefix-cc", "dd", "k8s_namespace", "default")); // so that result is deterministic in assertion - String annotations = result.toString(); + String annotations = filterOnK8sNamespace(result); Assertions.assertTrue( output.getOut().contains("Adding annotations metadata: " + annotations + " for serviceId: my-service")); } @@ -481,6 +499,8 @@ void testServiceMetadataAddLabelsAndAnnotationsWithPrefix(CapturedOutput output) boolean addPorts = false; String portsPrefix = ""; + String namespace = "default"; + KubernetesDiscoveryProperties.Metadata metadata = new KubernetesDiscoveryProperties.Metadata(addLabels, labelsPrefix, addAnnotations, annotationsPrefix, addPorts, portsPrefix); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, @@ -489,10 +509,11 @@ void testServiceMetadataAddLabelsAndAnnotationsWithPrefix(CapturedOutput output) .withAnnotations(Map.of("aa", "bb", "cc", "dd")).withLabels(Map.of("a", "b", "c", "d")).build()) .build(); - Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, List.of()); - Assertions.assertEquals(result.size(), 4); - Assertions.assertEquals(result, - Map.of("annotation-aa", "bb", "annotation-cc", "dd", "label-a", "b", "label-c", "d")); + Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, + List.of(), namespace); + Assertions.assertEquals(result.size(), 5); + Assertions.assertEquals(result, Map.of("annotation-aa", "bb", "annotation-cc", "dd", "label-a", "b", "label-c", + "d", "k8s_namespace", "default")); // so that result is deterministic in assertion String labels = result.entrySet().stream().filter(en -> en.getKey().contains("label")) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)).toString(); @@ -518,23 +539,27 @@ void testServiceMetadataAddPortsWithoutPrefix(CapturedOutput output) { boolean addPorts = true; String portsPrefix = ""; + String namespace = "default"; + KubernetesDiscoveryProperties.Metadata metadata = new KubernetesDiscoveryProperties.Metadata(addLabels, - labelsPrefix, addAnnotations, annotationsPrefix, addPorts, portsPrefix); + labelsPrefix, addAnnotations, annotationsPrefix, addPorts, portsPrefix); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - true, "", Set.of(), Map.of(), "", metadata, 0, false); + true, "", Set.of(), Map.of(), "", metadata, 0, false); Service service = new ServiceBuilder().withMetadata(new ObjectMetaBuilder() - .withAnnotations(Map.of("aa", "bb", "cc", "dd")).withLabels(Map.of("a", "b")).build()).build(); + .withAnnotations(Map.of("aa", "bb", "cc", "dd")).withLabels(Map.of("a", "b")).build()).build(); List endpointSubsets = List.of( - new EndpointSubsetBuilder().withPorts(new EndpointPortBuilder().withPort(8081).withName("").build()).build(), - new EndpointSubsetBuilder().withPorts(new EndpointPortBuilder().withPort(8080).withName("https").build()).build() - ); + new EndpointSubsetBuilder().withPorts(new EndpointPortBuilder().withPort(8081).withName("").build()) + .build(), + new EndpointSubsetBuilder() + .withPorts(new EndpointPortBuilder().withPort(8080).withName("https").build()).build()); - Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, endpointSubsets); - Assertions.assertEquals(result.size(), 1); - Assertions.assertEquals(result, Map.of("https", "8080")); - Assertions.assertTrue( - output.getOut().contains("Adding port metadata: {https=8080} for serviceId : my-service")); + Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, + endpointSubsets, namespace); + Assertions.assertEquals(result.size(), 2); + Assertions.assertEquals(result, Map.of("https", "8080", "k8s_namespace", "default")); + Assertions + .assertTrue(output.getOut().contains("Adding port metadata: {https=8080} for serviceId : my-service")); } /** @@ -551,23 +576,33 @@ void testServiceMetadataAddPortsWithPrefix(CapturedOutput output) { boolean addPorts = true; String portsPrefix = "prefix-"; + String namespace = "default"; + KubernetesDiscoveryProperties.Metadata metadata = new KubernetesDiscoveryProperties.Metadata(addLabels, - labelsPrefix, addAnnotations, annotationsPrefix, addPorts, portsPrefix); + labelsPrefix, addAnnotations, annotationsPrefix, addPorts, portsPrefix); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - true, "", Set.of(), Map.of(), "", metadata, 0, false); + true, "", Set.of(), Map.of(), "", metadata, 0, false); Service service = new ServiceBuilder().withMetadata(new ObjectMetaBuilder() - .withAnnotations(Map.of("aa", "bb", "cc", "dd")).withLabels(Map.of("a", "b")).build()).build(); + .withAnnotations(Map.of("aa", "bb", "cc", "dd")).withLabels(Map.of("a", "b")).build()).build(); List endpointSubsets = List.of( - new EndpointSubsetBuilder().withPorts(new EndpointPortBuilder().withPort(8081).withName("http").build()).build(), - new EndpointSubsetBuilder().withPorts(new EndpointPortBuilder().withPort(8080).withName("https").build()).build() - ); + new EndpointSubsetBuilder().withPorts(new EndpointPortBuilder().withPort(8081).withName("http").build()) + .build(), + new EndpointSubsetBuilder() + .withPorts(new EndpointPortBuilder().withPort(8080).withName("https").build()).build()); + + Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, + endpointSubsets, namespace); + Assertions.assertEquals(result.size(), 3); + Assertions.assertEquals(result, + Map.of("prefix-https", "8080", "prefix-http", "8081", "k8s_namespace", "default")); + Assertions.assertTrue(output.getOut() + .contains("Adding port metadata: {prefix-http=8081, prefix-https=8080} for serviceId : my-service")); + } - Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, endpointSubsets); - Assertions.assertEquals(result.size(), 2); - Assertions.assertEquals(result, Map.of("prefix-https", "8080", "prefix-http", "8081")); - Assertions.assertTrue( - output.getOut().contains("Adding port metadata: {prefix-http=8081, prefix-https=8080} for serviceId : my-service")); + private String filterOnK8sNamespace(Map result) { + return result.entrySet().stream().filter(en -> !en.getKey().contains("k8s_namespace")) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)).toString(); } } From 99d17bf2452979a2b41427adaa7d4adbb04aaaff Mon Sep 17 00:00:00 2001 From: wind57 Date: Mon, 20 Feb 2023 13:14:42 +0200 Subject: [PATCH 012/151] fix tests --- ...ernetesDiscoveryClientFilterMetadataTest.java | 16 ++++++++-------- .../KubernetesDiscoveryClientTests.java | 1 + 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientFilterMetadataTest.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientFilterMetadataTest.java index f802cdf848..bce45f2797 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientFilterMetadataTest.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientFilterMetadataTest.java @@ -88,7 +88,7 @@ void testAllExtraMetadataDisabled() { List instances = discoveryClient.getInstances(serviceId); assertThat(instances).hasSize(1); - assertThat(instances.get(0).getMetadata()).isEmpty(); + assertThat(instances.get(0).getMetadata()).isEqualTo(Map.of("k8s_namespace", "ns")); } @Test @@ -106,7 +106,7 @@ void testLabelsEnabled() { List instances = discoveryClient.getInstances(serviceId); assertThat(instances).hasSize(1); - assertThat(instances.get(0).getMetadata()).containsOnly(entry("l1", "v1"), entry("l2", "v2")); + assertThat(instances.get(0).getMetadata()).containsOnly(entry("l1", "v1"), entry("l2", "v2"), entry("k8s_namespace", "ns")); } @Test @@ -124,7 +124,7 @@ void testLabelsEnabledWithPrefix() { List instances = discoveryClient.getInstances(serviceId); assertThat(instances).hasSize(1); - assertThat(instances.get(0).getMetadata()).containsOnly(entry("l_l1", "v1"), entry("l_l2", "v2")); + assertThat(instances.get(0).getMetadata()).containsOnly(entry("l_l1", "v1"), entry("l_l2", "v2"), entry("k8s_namespace", "ns")); } @Test @@ -142,7 +142,7 @@ void testAnnotationsEnabled() { List instances = discoveryClient.getInstances(serviceId); assertThat(instances).hasSize(1); - assertThat(instances.get(0).getMetadata()).containsOnly(entry("a1", "v1"), entry("a2", "v2")); + assertThat(instances.get(0).getMetadata()).containsOnly(entry("a1", "v1"), entry("a2", "v2"), entry("k8s_namespace", "ns")); } @Test @@ -160,7 +160,7 @@ void testAnnotationsEnabledWithPrefix() { List instances = discoveryClient.getInstances(serviceId); assertThat(instances).hasSize(1); - assertThat(instances.get(0).getMetadata()).containsOnly(entry("a_a1", "v1"), entry("a_a2", "v2")); + assertThat(instances.get(0).getMetadata()).containsOnly(entry("a_a1", "v1"), entry("a_a2", "v2"), entry("k8s_namespace", "ns")); } @Test @@ -178,7 +178,7 @@ void testPortsEnabled() { List instances = discoveryClient.getInstances(serviceId); assertThat(instances).hasSize(1); - assertThat(instances.get(0).getMetadata()).containsOnly(entry("http", "80")); + assertThat(instances.get(0).getMetadata()).containsOnly(entry("http", "80"), entry("k8s_namespace", "ns")); } @Test @@ -196,7 +196,7 @@ void testPortsEnabledWithPrefix() { List instances = discoveryClient.getInstances(serviceId); assertThat(instances).hasSize(1); - assertThat(instances.get(0).getMetadata()).containsOnly(entry("p_http", "80")); + assertThat(instances.get(0).getMetadata()).containsOnly(entry("p_http", "80"), entry("k8s_namespace", "ns")); } @Test @@ -215,7 +215,7 @@ void testLabelsAndAnnotationsAndPortsEnabledWithPrefix() { List instances = discoveryClient.getInstances(serviceId); assertThat(instances).hasSize(1); assertThat(instances.get(0).getMetadata()).containsOnly(entry("a_a1", "an1"), entry("a_a2", "an2"), - entry("l_l1", "la1"), entry("p_http", "80")); + entry("l_l1", "la1"), entry("p_http", "80"), entry("k8s_namespace", "ns")); } private void setupServiceWithLabelsAndAnnotationsAndPorts(String serviceId, String namespace, diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientTests.java index b40010466f..2d02f4b5c2 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientTests.java @@ -407,6 +407,7 @@ void testSelectiveNamespacesSingleEndpointsMatchExactLabels(CapturedOutput outpu KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null); List result = discoveryClient.getEndPointsList("blue-service"); Assertions.assertEquals(result.size(), 1); + System.out.println("1111 ->" + output.getOut() + "<-"); Assertions.assertTrue(output.getOut().contains("searching for endpoints in namespaces : [test]")); } From 436fd0cfb2b7aa98f0ee2877d8a07c42bf458d4f Mon Sep 17 00:00:00 2001 From: wind57 Date: Mon, 20 Feb 2023 13:19:23 +0200 Subject: [PATCH 013/151] format code --- .../discovery/KubernetesDiscoveryClient.java | 14 +++-- .../KubernetesDiscoveryClientUtils.java | 7 ++- .../KubernetesDiscoveryClientUtilsTests.java | 58 +++++++++++-------- 3 files changed, 46 insertions(+), 33 deletions(-) diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java index 39578f3c17..e8b3afd9c8 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java @@ -151,7 +151,8 @@ private List getNamespaceServiceInstances(EndpointSubsetNS es, List addresses = endpointSubset.getAddresses(); - if (properties.includeNotReadyAddresses() && !CollectionUtils.isEmpty(endpointSubset.getNotReadyAddresses())) { + if (properties.includeNotReadyAddresses() + && !CollectionUtils.isEmpty(endpointSubset.getNotReadyAddresses())) { if (addresses == null) { addresses = new ArrayList<>(); } @@ -164,11 +165,12 @@ private List getNamespaceServiceInstances(EndpointSubsetNS es, if (endpointAddress.getTargetRef() != null) { instanceId = endpointAddress.getTargetRef().getUid(); } - instances.add(new DefaultKubernetesServiceInstance(instanceId, serviceId, endpointAddress.getIp(), - endpointPort, serviceMetadata, - servicePortSecureResolver.resolve(new ServicePortSecureResolver.Input(endpointPort, - service.getMetadata().getName(), service.getMetadata().getLabels(), - service.getMetadata().getAnnotations())))); + instances + .add(new DefaultKubernetesServiceInstance(instanceId, serviceId, endpointAddress.getIp(), + endpointPort, serviceMetadata, + servicePortSecureResolver.resolve(new ServicePortSecureResolver.Input(endpointPort, + service.getMetadata().getName(), service.getMetadata().getLabels(), + service.getMetadata().getAnnotations())))); } } diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtils.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtils.java index 8b588815cc..688c12911a 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtils.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtils.java @@ -143,9 +143,10 @@ static Map serviceMetadata(String serviceId, Service service, } if (metadataProps.addPorts()) { - Map ports = endpointSubsets.stream().flatMap(endpointSubset -> endpointSubset.getPorts().stream()) - .filter(port -> StringUtils.hasText(port.getName())) - .collect(toMap(EndpointPort::getName, port -> Integer.toString(port.getPort()))); + Map ports = endpointSubsets.stream() + .flatMap(endpointSubset -> endpointSubset.getPorts().stream()) + .filter(port -> StringUtils.hasText(port.getName())) + .collect(toMap(EndpointPort::getName, port -> Integer.toString(port.getPort()))); Map portMetadata = keysWithPrefix(ports, properties.metadata().portsPrefix()); LOG.debug(() -> "Adding port metadata: " + portMetadata + " for serviceId : " + serviceId); serviceMetadata.putAll(portMetadata); diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java index f3fb174a8a..15f0eaf6b7 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java @@ -342,7 +342,8 @@ void testServiceMetadataEmpty() { true, "", Set.of(), Map.of(), "", metadata, 0, false); Service service = new ServiceBuilder().build(); - Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, List.of()); + Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, + List.of()); Assertions.assertEquals(result.size(), 0); } @@ -368,7 +369,8 @@ void testServiceMetadataAddLabelsNoPrefix(CapturedOutput output) { Service service = new ServiceBuilder() .withMetadata(new ObjectMetaBuilder().withLabels(Map.of("a", "b")).build()).build(); - Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, List.of()); + Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, + List.of()); Assertions.assertEquals(result.size(), 1); Assertions.assertEquals(result, Map.of("a", "b")); Assertions.assertTrue(output.getOut().contains("Adding labels metadata: {a=b} for serviceId: my-service")); @@ -396,7 +398,8 @@ void testServiceMetadataAddLabelsWithPrefix(CapturedOutput output) { Service service = new ServiceBuilder() .withMetadata(new ObjectMetaBuilder().withLabels(Map.of("a", "b", "c", "d")).build()).build(); - Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, List.of()); + Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, + List.of()); Assertions.assertEquals(result.size(), 2); Assertions.assertEquals(result, Map.of("prefix-a", "b", "prefix-c", "d")); // so that result is deterministic in assertion @@ -428,7 +431,8 @@ void testServiceMetadataAddAnnotationsNoPrefix(CapturedOutput output) { new ObjectMetaBuilder().withAnnotations(Map.of("aa", "bb")).withLabels(Map.of("a", "b")).build()) .build(); - Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, List.of()); + Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, + List.of()); Assertions.assertEquals(result.size(), 1); Assertions.assertEquals(result, Map.of("aa", "bb")); Assertions @@ -457,7 +461,8 @@ void testServiceMetadataAddAnnotationsWithPrefix(CapturedOutput output) { Service service = new ServiceBuilder().withMetadata(new ObjectMetaBuilder() .withAnnotations(Map.of("aa", "bb", "cc", "dd")).withLabels(Map.of("a", "b")).build()).build(); - Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, List.of()); + Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, + List.of()); Assertions.assertEquals(result.size(), 2); Assertions.assertEquals(result, Map.of("prefix-aa", "bb", "prefix-cc", "dd")); // so that result is deterministic in assertion @@ -489,7 +494,8 @@ void testServiceMetadataAddLabelsAndAnnotationsWithPrefix(CapturedOutput output) .withAnnotations(Map.of("aa", "bb", "cc", "dd")).withLabels(Map.of("a", "b", "c", "d")).build()) .build(); - Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, List.of()); + Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, + List.of()); Assertions.assertEquals(result.size(), 4); Assertions.assertEquals(result, Map.of("annotation-aa", "bb", "annotation-cc", "dd", "label-a", "b", "label-c", "d")); @@ -519,22 +525,24 @@ void testServiceMetadataAddPortsWithoutPrefix(CapturedOutput output) { String portsPrefix = ""; KubernetesDiscoveryProperties.Metadata metadata = new KubernetesDiscoveryProperties.Metadata(addLabels, - labelsPrefix, addAnnotations, annotationsPrefix, addPorts, portsPrefix); + labelsPrefix, addAnnotations, annotationsPrefix, addPorts, portsPrefix); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - true, "", Set.of(), Map.of(), "", metadata, 0, false); + true, "", Set.of(), Map.of(), "", metadata, 0, false); Service service = new ServiceBuilder().withMetadata(new ObjectMetaBuilder() - .withAnnotations(Map.of("aa", "bb", "cc", "dd")).withLabels(Map.of("a", "b")).build()).build(); + .withAnnotations(Map.of("aa", "bb", "cc", "dd")).withLabels(Map.of("a", "b")).build()).build(); List endpointSubsets = List.of( - new EndpointSubsetBuilder().withPorts(new EndpointPortBuilder().withPort(8081).withName("").build()).build(), - new EndpointSubsetBuilder().withPorts(new EndpointPortBuilder().withPort(8080).withName("https").build()).build() - ); + new EndpointSubsetBuilder().withPorts(new EndpointPortBuilder().withPort(8081).withName("").build()) + .build(), + new EndpointSubsetBuilder() + .withPorts(new EndpointPortBuilder().withPort(8080).withName("https").build()).build()); - Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, endpointSubsets); + Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, + endpointSubsets); Assertions.assertEquals(result.size(), 1); Assertions.assertEquals(result, Map.of("https", "8080")); - Assertions.assertTrue( - output.getOut().contains("Adding port metadata: {https=8080} for serviceId : my-service")); + Assertions + .assertTrue(output.getOut().contains("Adding port metadata: {https=8080} for serviceId : my-service")); } /** @@ -552,22 +560,24 @@ void testServiceMetadataAddPortsWithPrefix(CapturedOutput output) { String portsPrefix = "prefix-"; KubernetesDiscoveryProperties.Metadata metadata = new KubernetesDiscoveryProperties.Metadata(addLabels, - labelsPrefix, addAnnotations, annotationsPrefix, addPorts, portsPrefix); + labelsPrefix, addAnnotations, annotationsPrefix, addPorts, portsPrefix); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - true, "", Set.of(), Map.of(), "", metadata, 0, false); + true, "", Set.of(), Map.of(), "", metadata, 0, false); Service service = new ServiceBuilder().withMetadata(new ObjectMetaBuilder() - .withAnnotations(Map.of("aa", "bb", "cc", "dd")).withLabels(Map.of("a", "b")).build()).build(); + .withAnnotations(Map.of("aa", "bb", "cc", "dd")).withLabels(Map.of("a", "b")).build()).build(); List endpointSubsets = List.of( - new EndpointSubsetBuilder().withPorts(new EndpointPortBuilder().withPort(8081).withName("http").build()).build(), - new EndpointSubsetBuilder().withPorts(new EndpointPortBuilder().withPort(8080).withName("https").build()).build() - ); + new EndpointSubsetBuilder().withPorts(new EndpointPortBuilder().withPort(8081).withName("http").build()) + .build(), + new EndpointSubsetBuilder() + .withPorts(new EndpointPortBuilder().withPort(8080).withName("https").build()).build()); - Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, endpointSubsets); + Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, + endpointSubsets); Assertions.assertEquals(result.size(), 2); Assertions.assertEquals(result, Map.of("prefix-https", "8080", "prefix-http", "8081")); - Assertions.assertTrue( - output.getOut().contains("Adding port metadata: {prefix-http=8081, prefix-https=8080} for serviceId : my-service")); + Assertions.assertTrue(output.getOut() + .contains("Adding port metadata: {prefix-http=8081, prefix-https=8080} for serviceId : my-service")); } } From dc6c48991dd14fcc413c8543fdea5b43ee446704 Mon Sep 17 00:00:00 2001 From: wind57 Date: Mon, 20 Feb 2023 13:29:24 +0200 Subject: [PATCH 014/151] add logback for test --- .../src/test/resources/logback-test.xml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 spring-cloud-kubernetes-fabric8-discovery/src/test/resources/logback-test.xml diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/resources/logback-test.xml b/spring-cloud-kubernetes-fabric8-discovery/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..d43090e740 --- /dev/null +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/resources/logback-test.xml @@ -0,0 +1,18 @@ + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n + + + + + + + + + + + + + + From 8ca2df70954860c50e597d8f7f0de5ad1d863d26 Mon Sep 17 00:00:00 2001 From: wind57 Date: Mon, 20 Feb 2023 19:54:08 +0200 Subject: [PATCH 015/151] remove sysout --- .../fabric8/discovery/KubernetesDiscoveryClientTests.java | 1 - 1 file changed, 1 deletion(-) diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientTests.java index 2d02f4b5c2..b40010466f 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientTests.java @@ -407,7 +407,6 @@ void testSelectiveNamespacesSingleEndpointsMatchExactLabels(CapturedOutput outpu KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null); List result = discoveryClient.getEndPointsList("blue-service"); Assertions.assertEquals(result.size(), 1); - System.out.println("1111 ->" + output.getOut() + "<-"); Assertions.assertTrue(output.getOut().contains("searching for endpoints in namespaces : [test]")); } From 2b4bdc8dddc7eb6668e8fd0ed2df8731b3235181 Mon Sep 17 00:00:00 2001 From: wind57 Date: Mon, 20 Feb 2023 21:26:47 +0200 Subject: [PATCH 016/151] trigger build From 3ef6fa1dbc58bd2043dd037b00c7fe5a63fbb50b Mon Sep 17 00:00:00 2001 From: wind57 Date: Tue, 21 Feb 2023 09:17:09 +0200 Subject: [PATCH 017/151] trigger build From e4b94ce9a6c6f377566b0e079ac3804127188eda Mon Sep 17 00:00:00 2001 From: wind57 Date: Tue, 21 Feb 2023 11:52:00 +0200 Subject: [PATCH 018/151] fix --- .../discovery/KubernetesDiscoveryClient.java | 17 +--- .../KubernetesDiscoveryClientUtils.java | 18 +++++ .../KubernetesDiscoveryClientUtilsTests.java | 79 +++++++++++++++++++ 3 files changed, 101 insertions(+), 13 deletions(-) diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java index a0b84d43b0..f47961d976 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java @@ -34,8 +34,8 @@ import org.springframework.cloud.kubernetes.commons.discovery.DefaultKubernetesServiceInstance; import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; import org.springframework.core.log.LogAccessor; -import org.springframework.util.CollectionUtils; +import static org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientUtils.addresses; import static org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientUtils.endpoints; import static org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientUtils.endpointsPort; import static org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientUtils.serviceMetadata; @@ -143,19 +143,10 @@ private List getNamespaceServiceInstances(EndpointSubsetNS es, Map serviceMetadata = serviceMetadata(serviceId, service, properties, subsets, namespace); for (EndpointSubset endpointSubset : subsets) { - - List addresses = endpointSubset.getAddresses(); - - if (properties.includeNotReadyAddresses() - && !CollectionUtils.isEmpty(endpointSubset.getNotReadyAddresses())) { - if (addresses == null) { - addresses = new ArrayList<>(); - } - addresses.addAll(endpointSubset.getNotReadyAddresses()); - } - + int endpointPort = endpointsPort(endpointSubset, serviceId, properties, service); + List addresses = addresses(endpointSubset, properties); for (EndpointAddress endpointAddress : addresses) { - int endpointPort = endpointsPort(endpointSubset, serviceId, properties, service); + String instanceId = null; if (endpointAddress.getTargetRef() != null) { instanceId = endpointAddress.getTargetRef().getUid(); diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtils.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtils.java index 586e2358ff..559e4670ac 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtils.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtils.java @@ -16,12 +16,14 @@ package org.springframework.cloud.kubernetes.fabric8.discovery; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; import java.util.stream.Collectors; +import io.fabric8.kubernetes.api.model.EndpointAddress; import io.fabric8.kubernetes.api.model.EndpointPort; import io.fabric8.kubernetes.api.model.EndpointSubset; import io.fabric8.kubernetes.api.model.Endpoints; @@ -34,6 +36,7 @@ import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; import org.springframework.core.log.LogAccessor; +import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; import static java.util.stream.Collectors.toMap; @@ -164,6 +167,21 @@ static List endpoints( .list().getItems(); } + static List addresses(EndpointSubset endpointSubset, KubernetesDiscoveryProperties properties) { + List addresses = Optional.ofNullable(endpointSubset.getAddresses()).map(ArrayList::new) + .orElse(new ArrayList<>()); + + if (properties.includeNotReadyAddresses()) { + List notReadyAddresses = endpointSubset.getNotReadyAddresses(); + if (CollectionUtils.isEmpty(notReadyAddresses)) { + return addresses; + } + addresses.addAll(notReadyAddresses); + } + + return addresses; + } + private static Optional fromMap(Map existingPorts, String key, String message) { Integer fromPrimaryPortName = existingPorts.get(key); if (fromPrimaryPortName == null) { diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java index d3ff17bdf5..7e6bec52cf 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java @@ -21,6 +21,8 @@ import java.util.Set; import java.util.stream.Collectors; +import io.fabric8.kubernetes.api.model.EndpointAddress; +import io.fabric8.kubernetes.api.model.EndpointAddressBuilder; import io.fabric8.kubernetes.api.model.EndpointPortBuilder; import io.fabric8.kubernetes.api.model.EndpointSubset; import io.fabric8.kubernetes.api.model.EndpointSubsetBuilder; @@ -600,6 +602,83 @@ void testServiceMetadataAddPortsWithPrefix(CapturedOutput output) { .contains("Adding port metadata: {prefix-http=8081, prefix-https=8080} for serviceId : my-service")); } + /** + *
+	 *      - ready addresses are empty
+	 *      - not ready addresses are not included
+	 * 
+ */ + @Test + void testEmptyAddresses() { + boolean includeNotReadyAddresses = false; + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, + includeNotReadyAddresses, "", Set.of(), Map.of(), "", null, 0, false); + EndpointSubset endpointSubset = new EndpointSubsetBuilder().build(); + List addresses = KubernetesDiscoveryClientUtils.addresses(endpointSubset, properties); + Assertions.assertEquals(addresses.size(), 0); + } + + /** + *
+	 *      - ready addresses has two entries
+	 *      - not ready addresses are not included
+	 * 
+ */ + @Test + void testReadyAddressesOnly() { + boolean includeNotReadyAddresses = false; + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, + includeNotReadyAddresses, "", Set.of(), Map.of(), "", null, 0, false); + EndpointSubset endpointSubset = new EndpointSubsetBuilder() + .withAddresses(new EndpointAddressBuilder().withHostname("one").build(), + new EndpointAddressBuilder().withHostname("two").build()) + .build(); + List addresses = KubernetesDiscoveryClientUtils.addresses(endpointSubset, properties); + Assertions.assertEquals(addresses.size(), 2); + } + + /** + *
+	 *      - ready addresses has two entries
+	 *      - not ready addresses has a single entry, but we do not take it
+	 * 
+ */ + @Test + void testReadyAddressesTakenNotReadyAddressesNotTaken() { + boolean includeNotReadyAddresses = false; + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, + includeNotReadyAddresses, "", Set.of(), Map.of(), "", null, 0, false); + EndpointSubset endpointSubset = new EndpointSubsetBuilder() + .withAddresses(new EndpointAddressBuilder().withHostname("one").build(), + new EndpointAddressBuilder().withHostname("two").build()) + .withNotReadyAddresses(new EndpointAddressBuilder().withHostname("three").build()).build(); + List addresses = KubernetesDiscoveryClientUtils.addresses(endpointSubset, properties); + Assertions.assertEquals(addresses.size(), 2); + List hostNames = addresses.stream().map(EndpointAddress::getHostname).sorted().toList(); + Assertions.assertEquals(hostNames, List.of("one", "two")); + } + + /** + *
+	 *      - ready addresses has two entries
+	 *      - not ready addresses has a single entry, but we do not take it
+	 * 
+ */ + @Test + void testBothAddressesTaken() { + boolean includeNotReadyAddresses = true; + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, + includeNotReadyAddresses, "", Set.of(), Map.of(), "", null, 0, false); + EndpointSubset endpointSubset = new EndpointSubsetBuilder() + .withAddresses(new EndpointAddressBuilder().withHostname("one").build(), + new EndpointAddressBuilder().withHostname("two").build()) + .withNotReadyAddresses(new EndpointAddressBuilder().withHostname("three").build()).build(); + List addresses = KubernetesDiscoveryClientUtils.addresses(endpointSubset, properties); + Assertions.assertEquals(addresses.size(), 3); + List hostNames = addresses.stream().map(EndpointAddress::getHostname).sorted().toList(); + Assertions.assertEquals(hostNames, List.of("one", "three", "two")); + } + private String filterOnK8sNamespace(Map result) { return result.entrySet().stream().filter(en -> !en.getKey().contains("k8s_namespace")) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)).toString(); From 4b4efbda3cad9b566ab74e4675d2821140d9e5c3 Mon Sep 17 00:00:00 2001 From: wind57 Date: Thu, 23 Feb 2023 09:29:48 +0200 Subject: [PATCH 019/151] add namespace --- .../discovery/KubernetesDiscoveryClient.java | 16 +++-------- .../KubernetesDiscoveryClientUtils.java | 17 ++++++++++++ .../KubernetesDiscoveryClientUtilsTests.java | 27 +++++++++++++++++++ 3 files changed, 48 insertions(+), 12 deletions(-) diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java index f47961d976..3751d31cdf 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java @@ -31,13 +31,13 @@ import org.springframework.cloud.client.ServiceInstance; import org.springframework.cloud.client.discovery.DiscoveryClient; -import org.springframework.cloud.kubernetes.commons.discovery.DefaultKubernetesServiceInstance; import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; import org.springframework.core.log.LogAccessor; import static org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientUtils.addresses; import static org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientUtils.endpoints; import static org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientUtils.endpointsPort; +import static org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientUtils.serviceInstance; import static org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientUtils.serviceMetadata; /** @@ -146,17 +146,9 @@ private List getNamespaceServiceInstances(EndpointSubsetNS es, int endpointPort = endpointsPort(endpointSubset, serviceId, properties, service); List addresses = addresses(endpointSubset, properties); for (EndpointAddress endpointAddress : addresses) { - - String instanceId = null; - if (endpointAddress.getTargetRef() != null) { - instanceId = endpointAddress.getTargetRef().getUid(); - } - instances - .add(new DefaultKubernetesServiceInstance(instanceId, serviceId, endpointAddress.getIp(), - endpointPort, serviceMetadata, - servicePortSecureResolver.resolve(new ServicePortSecureResolver.Input(endpointPort, - service.getMetadata().getName(), service.getMetadata().getLabels(), - service.getMetadata().getAnnotations())))); + ServiceInstance serviceInstance = serviceInstance(servicePortSecureResolver, service, endpointAddress, + endpointPort, serviceId, serviceMetadata, namespace); + instances.add(serviceInstance); } } diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtils.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtils.java index 559e4670ac..beedc0200a 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtils.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtils.java @@ -28,12 +28,15 @@ import io.fabric8.kubernetes.api.model.EndpointSubset; import io.fabric8.kubernetes.api.model.Endpoints; import io.fabric8.kubernetes.api.model.EndpointsList; +import io.fabric8.kubernetes.api.model.ObjectReference; import io.fabric8.kubernetes.api.model.Service; import io.fabric8.kubernetes.client.dsl.FilterNested; import io.fabric8.kubernetes.client.dsl.FilterWatchListDeletable; import io.fabric8.kubernetes.client.dsl.Resource; import org.apache.commons.logging.LogFactory; +import org.springframework.cloud.client.ServiceInstance; +import org.springframework.cloud.kubernetes.commons.discovery.DefaultKubernetesServiceInstance; import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; import org.springframework.core.log.LogAccessor; import org.springframework.util.CollectionUtils; @@ -182,6 +185,20 @@ static List addresses(EndpointSubset endpointSubset, Kubernetes return addresses; } + static ServiceInstance serviceInstance(ServicePortSecureResolver servicePortSecureResolver, Service service, EndpointAddress endpointAddress, + int endpointPort, String serviceId, Map serviceMetadata, String namespace) { + // instanceId is usually the pod-uid as seen in the .metadata.uid + String instanceId = Optional.ofNullable(endpointAddress.getTargetRef()) + .map(ObjectReference::getUid).orElse(null); + + boolean secured = servicePortSecureResolver.resolve(new ServicePortSecureResolver.Input(endpointPort, + service.getMetadata().getName(), service.getMetadata().getLabels(), + service.getMetadata().getAnnotations())); + + return new DefaultKubernetesServiceInstance(instanceId, serviceId, endpointAddress.getIp(), + endpointPort, serviceMetadata, secured, namespace, null); + } + private static Optional fromMap(Map existingPorts, String key, String message) { Integer fromPrimaryPortName = existingPorts.get(key); if (fromPrimaryPortName == null) { diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java index 7e6bec52cf..b7e210720c 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java @@ -38,6 +38,8 @@ import org.springframework.boot.test.system.CapturedOutput; import org.springframework.boot.test.system.OutputCaptureExtension; +import org.springframework.cloud.client.ServiceInstance; +import org.springframework.cloud.kubernetes.commons.discovery.DefaultKubernetesServiceInstance; import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; import static org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryConstants.PRIMARY_PORT_NAME_LABEL_KEY; @@ -679,6 +681,31 @@ void testBothAddressesTaken() { Assertions.assertEquals(hostNames, List.of("one", "three", "two")); } + @Test + void testServiceInstance() { + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, + false, "", Set.of(), Map.of(), "", null, 0, false); + ServicePortSecureResolver resolver = new ServicePortSecureResolver(properties); + Service service = new ServiceBuilder().withMetadata(new ObjectMeta()).build(); + EndpointAddress address = new EndpointAddressBuilder().withNewTargetRef().withUid("123").endTargetRef() + .withIp("127.0.0.1").build(); + + ServiceInstance serviceInstance = KubernetesDiscoveryClientUtils.serviceInstance(resolver, service, address, 8080, "my-service", + Map.of("a", "b"), "k8s"); + Assertions.assertTrue(serviceInstance instanceof DefaultKubernetesServiceInstance); + DefaultKubernetesServiceInstance defaultInstance = (DefaultKubernetesServiceInstance) serviceInstance; + Assertions.assertEquals(defaultInstance.getInstanceId(), "123"); + Assertions.assertEquals(defaultInstance.getServiceId(), "my-service"); + Assertions.assertEquals(defaultInstance.getHost(), "127.0.0.1"); + Assertions.assertEquals(defaultInstance.getPort(), 8080); + Assertions.assertFalse(defaultInstance.isSecure()); + Assertions.assertEquals(defaultInstance.getUri().toASCIIString(), "http://127.0.0.1:8080"); + Assertions.assertEquals(defaultInstance.getMetadata(), Map.of("a", "b")); + Assertions.assertEquals(defaultInstance.getScheme(), "http"); + Assertions.assertEquals(defaultInstance.getNamespace(), "k8s"); + Assertions.assertNull(defaultInstance.getCluster()); + } + private String filterOnK8sNamespace(Map result) { return result.entrySet().stream().filter(en -> !en.getKey().contains("k8s_namespace")) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)).toString(); From 5d77a9e744073111573cf51c70319795547fd230 Mon Sep 17 00:00:00 2001 From: wind57 Date: Thu, 23 Feb 2023 09:31:30 +0200 Subject: [PATCH 020/151] formatting --- .../discovery/KubernetesDiscoveryClient.java | 2 +- .../KubernetesDiscoveryClientUtils.java | 19 ++++++++++--------- .../KubernetesDiscoveryClientUtilsTests.java | 8 ++++---- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java index 3751d31cdf..2e2b748261 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java @@ -147,7 +147,7 @@ private List getNamespaceServiceInstances(EndpointSubsetNS es, List addresses = addresses(endpointSubset, properties); for (EndpointAddress endpointAddress : addresses) { ServiceInstance serviceInstance = serviceInstance(servicePortSecureResolver, service, endpointAddress, - endpointPort, serviceId, serviceMetadata, namespace); + endpointPort, serviceId, serviceMetadata, namespace); instances.add(serviceInstance); } } diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtils.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtils.java index beedc0200a..e2825215cf 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtils.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtils.java @@ -185,18 +185,19 @@ static List addresses(EndpointSubset endpointSubset, Kubernetes return addresses; } - static ServiceInstance serviceInstance(ServicePortSecureResolver servicePortSecureResolver, Service service, EndpointAddress endpointAddress, - int endpointPort, String serviceId, Map serviceMetadata, String namespace) { + static ServiceInstance serviceInstance(ServicePortSecureResolver servicePortSecureResolver, Service service, + EndpointAddress endpointAddress, int endpointPort, String serviceId, Map serviceMetadata, + String namespace) { // instanceId is usually the pod-uid as seen in the .metadata.uid - String instanceId = Optional.ofNullable(endpointAddress.getTargetRef()) - .map(ObjectReference::getUid).orElse(null); + String instanceId = Optional.ofNullable(endpointAddress.getTargetRef()).map(ObjectReference::getUid) + .orElse(null); - boolean secured = servicePortSecureResolver.resolve(new ServicePortSecureResolver.Input(endpointPort, - service.getMetadata().getName(), service.getMetadata().getLabels(), - service.getMetadata().getAnnotations())); + boolean secured = servicePortSecureResolver + .resolve(new ServicePortSecureResolver.Input(endpointPort, service.getMetadata().getName(), + service.getMetadata().getLabels(), service.getMetadata().getAnnotations())); - return new DefaultKubernetesServiceInstance(instanceId, serviceId, endpointAddress.getIp(), - endpointPort, serviceMetadata, secured, namespace, null); + return new DefaultKubernetesServiceInstance(instanceId, serviceId, endpointAddress.getIp(), endpointPort, + serviceMetadata, secured, namespace, null); } private static Optional fromMap(Map existingPorts, String key, String message) { diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java index b7e210720c..9d41b95f8c 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java @@ -684,14 +684,14 @@ void testBothAddressesTaken() { @Test void testServiceInstance() { KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - false, "", Set.of(), Map.of(), "", null, 0, false); + false, "", Set.of(), Map.of(), "", null, 0, false); ServicePortSecureResolver resolver = new ServicePortSecureResolver(properties); Service service = new ServiceBuilder().withMetadata(new ObjectMeta()).build(); EndpointAddress address = new EndpointAddressBuilder().withNewTargetRef().withUid("123").endTargetRef() - .withIp("127.0.0.1").build(); + .withIp("127.0.0.1").build(); - ServiceInstance serviceInstance = KubernetesDiscoveryClientUtils.serviceInstance(resolver, service, address, 8080, "my-service", - Map.of("a", "b"), "k8s"); + ServiceInstance serviceInstance = KubernetesDiscoveryClientUtils.serviceInstance(resolver, service, address, + 8080, "my-service", Map.of("a", "b"), "k8s"); Assertions.assertTrue(serviceInstance instanceof DefaultKubernetesServiceInstance); DefaultKubernetesServiceInstance defaultInstance = (DefaultKubernetesServiceInstance) serviceInstance; Assertions.assertEquals(defaultInstance.getInstanceId(), "123"); From aea361a7102ae8c0186ee0dc4432ac5bfe2963ed Mon Sep 17 00:00:00 2001 From: wind57 Date: Thu, 23 Feb 2023 16:20:07 +0200 Subject: [PATCH 021/151] dirty --- .../KubernetesDiscoveryProperties.java | 8 +- .../Fabric8ExternalNameServiceProvider.java | 74 +++++++++++++++++++ .../discovery/KubernetesDiscoveryClient.java | 4 + 3 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8ExternalNameServiceProvider.java diff --git a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/KubernetesDiscoveryProperties.java b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/KubernetesDiscoveryProperties.java index 6001e79db6..c0d7478259 100644 --- a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/KubernetesDiscoveryProperties.java +++ b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/KubernetesDiscoveryProperties.java @@ -43,6 +43,8 @@ * @param primaryPortName If set then the port with a given name is used as primary when * multiple ports are defined for a service. * @param useEndpointSlices use EndpointSlice instead of Endpoints + * @param includeExternalNameServices - should the discovery also search for services that + * have "type: ExternalName" in their spec. */ // @formatter:off @ConfigurationProperties("spring.cloud.kubernetes.discovery") @@ -56,14 +58,16 @@ public record KubernetesDiscoveryProperties( @DefaultValue Map serviceLabels, String primaryPortName, @DefaultValue Metadata metadata, @DefaultValue("" + DEFAULT_ORDER) int order, - boolean useEndpointSlices) { + boolean useEndpointSlices, + boolean includeExternalNameServices) { // @formatter:on /** * Default instance. */ public static final KubernetesDiscoveryProperties DEFAULT = new KubernetesDiscoveryProperties(true, false, Set.of(), - true, 60, false, null, Set.of(), Map.of(), null, KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, false); + true, 60, false, null, Set.of(), Map.of(), null, KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, false, + false); /** * @param addLabels include labels as metadata diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8ExternalNameServiceProvider.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8ExternalNameServiceProvider.java new file mode 100644 index 0000000000..8fd1e78fe2 --- /dev/null +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8ExternalNameServiceProvider.java @@ -0,0 +1,74 @@ +/* + * Copyright 2012-2023 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.discovery; + +import io.fabric8.kubernetes.api.model.Endpoints; +import io.fabric8.kubernetes.client.KubernetesClient; +import org.apache.commons.logging.LogFactory; +import org.springframework.cloud.client.ServiceInstance; +import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; +import org.springframework.core.log.LogAccessor; + +import java.util.ArrayList; +import java.util.List; + +import static org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientUtils.endpoints; + +/** + * Provides instances of services that have "spec.type: ExternalName". + * + * @author wind57 + */ +final class Fabric8ExternalNameServiceProvider { + + private static final LogAccessor LOG = new LogAccessor(LogFactory.getLog(Fabric8ExternalNameServiceProvider.class)); + + private final KubernetesDiscoveryProperties properties = null; + + private final KubernetesClient client = null; + + private Fabric8ExternalNameServiceProvider() { + + } + + List externalServiceInstances() { + if (!properties.includeExternalNameServices()) { + LOG.debug(() -> "skipping external name services look-up"); + return List.of(); + } + + if (properties.allNamespaces()) { + LOG.debug(() -> "searching for endpoints in all namespaces"); + return client.services().inAnyNamespace().withNewFilter(), properties; + } +// else if (properties.namespaces().isEmpty()) { +// LOG.debug(() -> "searching for endpoints in namespace : " + client.getNamespace()); +// return endpoints(client.endpoints().withNewFilter(), properties, serviceId); +// } +// else { +// LOG.debug(() -> "searching for endpoints in namespaces : " + properties.namespaces()); +// List endpoints = new ArrayList<>(); +// for (String namespace : properties.namespaces()) { +// endpoints.addAll( +// endpoints(client.endpoints().inNamespace(namespace).withNewFilter(), properties, serviceId)); +// } +// return endpoints; +// } + } + +} + + diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java index 2e2b748261..4108e11828 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java @@ -105,6 +105,10 @@ public List getInstances(String serviceId) { instances.addAll(getNamespaceServiceInstances(es, serviceId)); } + if (properties.includeExternalNameServices()) { + LOG.debug(() -> "will search for 'ExternalName' type of services"); + } + return instances; } From 3339b5a747fb88311ef44601fb51a8d89c17a5e8 Mon Sep 17 00:00:00 2001 From: wind57 Date: Fri, 24 Feb 2023 16:47:26 +0200 Subject: [PATCH 022/151] dirty --- .../commons/discovery/KubernetesDiscoveryProperties.java | 2 +- .../discovery/KubernetesDiscoveryPropertiesTests.java | 5 ++++- .../discovery/Fabric8ExternalNameServiceProvider.java | 9 +++++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/KubernetesDiscoveryProperties.java b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/KubernetesDiscoveryProperties.java index c0d7478259..af828bfa4e 100644 --- a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/KubernetesDiscoveryProperties.java +++ b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/KubernetesDiscoveryProperties.java @@ -43,7 +43,7 @@ * @param primaryPortName If set then the port with a given name is used as primary when * multiple ports are defined for a service. * @param useEndpointSlices use EndpointSlice instead of Endpoints - * @param includeExternalNameServices - should the discovery also search for services that + * @param includeExternalNameServices should the discovery also search for services that * have "type: ExternalName" in their spec. */ // @formatter:off diff --git a/spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/discovery/KubernetesDiscoveryPropertiesTests.java b/spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/discovery/KubernetesDiscoveryPropertiesTests.java index 55c29f64c4..f3d62f1cda 100644 --- a/spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/discovery/KubernetesDiscoveryPropertiesTests.java +++ b/spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/discovery/KubernetesDiscoveryPropertiesTests.java @@ -53,6 +53,7 @@ void testBindingWhenNoPropertiesProvided() { assertThat(props.primaryPortName()).isNull(); assertThat(props.order()).isZero(); assertThat(props.useEndpointSlices()).isFalse(); + assertThat(props.includeExternalNameServices()).isFalse(); }); } @@ -64,7 +65,8 @@ void testBindingWhenSomePropertiesProvided() { "spring.cloud.kubernetes.discovery.metadata.labelsPrefix=labelsPrefix", "spring.cloud.kubernetes.discovery.use-endpoint-slices=true", "spring.cloud.kubernetes.discovery.namespaces[0]=ns1", - "spring.cloud.kubernetes.discovery.namespaces[1]=ns2") + "spring.cloud.kubernetes.discovery.namespaces[1]=ns2", + "spring.cloud.kubernetes.discovery.include-external-name-services=true") .run(context -> { KubernetesDiscoveryProperties props = context.getBean(KubernetesDiscoveryProperties.class); assertThat(props).isNotNull(); @@ -84,6 +86,7 @@ void testBindingWhenSomePropertiesProvided() { assertThat(props.primaryPortName()).isNull(); assertThat(props.order()).isZero(); assertThat(props.useEndpointSlices()).isTrue(); + assertThat(props.includeExternalNameServices()).isTrue(); }); } diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8ExternalNameServiceProvider.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8ExternalNameServiceProvider.java index 8fd1e78fe2..69af9fcbfa 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8ExternalNameServiceProvider.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8ExternalNameServiceProvider.java @@ -36,12 +36,13 @@ final class Fabric8ExternalNameServiceProvider { private static final LogAccessor LOG = new LogAccessor(LogFactory.getLog(Fabric8ExternalNameServiceProvider.class)); - private final KubernetesDiscoveryProperties properties = null; + private final KubernetesDiscoveryProperties properties; - private final KubernetesClient client = null; - - private Fabric8ExternalNameServiceProvider() { + private final KubernetesClient client; + Fabric8ExternalNameServiceProvider(KubernetesDiscoveryProperties properties, KubernetesClient client) { + this.properties = properties; + this.client = client; } List externalServiceInstances() { From 92b2e0af23d20df76cb897bf5dfda38a1ca144c1 Mon Sep 17 00:00:00 2001 From: wind57 Date: Sat, 25 Feb 2023 16:15:00 +0200 Subject: [PATCH 023/151] first --- .../fabric8/discovery/EndpointSubsetNS.java | 2 +- ...overyClientPredicateAutoConfiguration.java | 71 ++ .../Fabric8DiscoveryServicesAdapter.java | 92 -- .../Fabric8EndpointSliceV1CatalogWatch.java | 38 +- .../Fabric8EndpointsCatalogWatch.java | 2 +- ...ava => Fabric8KubernetesCatalogWatch.java} | 10 +- ...ernetesCatalogWatchAutoConfiguration.java} | 8 +- ... => Fabric8KubernetesDiscoveryClient.java} | 69 +- ...etesDiscoveryClientAutoConfiguration.java} | 30 +- ...ntConfigClientBootstrapConfiguration.java} | 4 +- ...abric8KubernetesDiscoveryClientUtils.java} | 83 +- ...ic8KubernetesReactiveDiscoveryClient.java} | 22 +- ...tiveDiscoveryClientAutoConfiguration.java} | 36 +- .../KubernetesClientServicesFunction.java | 48 - ...ernetesClientServicesFunctionProvider.java | 47 - .../discovery/ServicePortSecureResolver.java | 9 +- .../main/resources/META-INF/spring.factories | 2 +- ...ot.autoconfigure.AutoConfiguration.imports | 7 +- .../Fabric8DiscoveryServicesAdapterTests.java | 864 +++++++-------- ...abric8EndpointsAndEndpointSlicesTests.java | 20 +- ...atalogWatchEndpointSlicesSupportTests.java | 8 +- ...rnetesCatalogWatchEndpointSlicesTests.java | 16 +- ...8KubernetesCatalogWatchEndpointsTests.java | 16 +- ...CatalogServicesWatchConfigurationTest.java | 4 +- ...oConfigurationApplicationContextTests.java | 75 +- .../discovery/KubernetesCatalogWatchTest.java | 6 +- ...oConfigurationApplicationContextTests.java | 280 ++--- ...lientAutoConfigurationPropertiesTests.java | 10 +- ...DiscoveryClientAutoConfigurationTests.java | 2 +- ...nfigClientBootstrapConfigurationTests.java | 8 +- ...etesDiscoveryClientFilterMetadataTest.java | 458 ++++---- .../KubernetesDiscoveryClientFilterTest.java | 192 ++-- .../KubernetesDiscoveryClientTest.java | 986 +++++++++--------- .../KubernetesDiscoveryClientTests.java | 32 +- .../KubernetesDiscoveryClientUtilsTests.java | 50 +- ...oConfigurationApplicationContextTests.java | 177 ++++ ...DiscoveryClientAutoConfigurationTests.java | 9 +- ...ubernetesReactiveDiscoveryClientTests.java | 264 +++++ ...oConfigurationApplicationContextTests.java | 175 ---- ...ubernetesReactiveDiscoveryClientTests.java | 263 ----- .../configmap/Fabric8DiscoveryController.java | 6 +- 41 files changed, 2196 insertions(+), 2305 deletions(-) create mode 100644 spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryClientPredicateAutoConfiguration.java delete mode 100644 spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryServicesAdapter.java rename spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/{KubernetesCatalogWatch.java => Fabric8KubernetesCatalogWatch.java} (94%) rename spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/{KubernetesCatalogWatchAutoConfiguration.java => Fabric8KubernetesCatalogWatchAutoConfiguration.java} (87%) rename spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/{KubernetesDiscoveryClient.java => Fabric8KubernetesDiscoveryClient.java} (65%) rename spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/{KubernetesDiscoveryClientAutoConfiguration.java => Fabric8KubernetesDiscoveryClientAutoConfiguration.java} (78%) rename spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/{KubernetesDiscoveryClientConfigClientBootstrapConfiguration.java => Fabric8KubernetesDiscoveryClientConfigClientBootstrapConfiguration.java} (87%) rename spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/{KubernetesDiscoveryClientUtils.java => Fabric8KubernetesDiscoveryClientUtils.java} (74%) rename spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/{reactive/KubernetesReactiveDiscoveryClient.java => Fabric8KubernetesReactiveDiscoveryClient.java} (56%) rename spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/{reactive/KubernetesReactiveDiscoveryClientAutoConfiguration.java => Fabric8KubernetesReactiveDiscoveryClientAutoConfiguration.java} (70%) delete mode 100644 spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesClientServicesFunction.java delete mode 100644 spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesClientServicesFunctionProvider.java create mode 100644 spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesReactiveDiscoveryClientAutoConfigurationApplicationContextTests.java rename spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/{reactive => }/KubernetesReactiveDiscoveryClientAutoConfigurationTests.java (90%) create mode 100644 spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesReactiveDiscoveryClientTests.java delete mode 100644 spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/reactive/KubernetesReactiveDiscoveryClientAutoConfigurationApplicationContextTests.java delete mode 100644 spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/reactive/KubernetesReactiveDiscoveryClientTests.java diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/EndpointSubsetNS.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/EndpointSubsetNS.java index 8a7de4b74a..8cb1faaebe 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/EndpointSubsetNS.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/EndpointSubsetNS.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-2023 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. diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryClientPredicateAutoConfiguration.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryClientPredicateAutoConfiguration.java new file mode 100644 index 0000000000..97b92a6a99 --- /dev/null +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryClientPredicateAutoConfiguration.java @@ -0,0 +1,71 @@ +/* + * Copyright 2012-2023 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.discovery; + +import io.fabric8.kubernetes.api.model.Service; +import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.boot.autoconfigure.condition.ConditionalOnCloudPlatform; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.cloud.CloudPlatform; +import org.springframework.cloud.client.ConditionalOnBlockingDiscoveryEnabled; +import org.springframework.cloud.client.ConditionalOnDiscoveryEnabled; +import org.springframework.cloud.kubernetes.commons.discovery.ConditionalOnKubernetesDiscoveryEnabled; +import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; +import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryPropertiesAutoConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.expression.Expression; +import org.springframework.expression.spel.standard.SpelExpressionParser; +import org.springframework.expression.spel.support.SimpleEvaluationContext; + +import java.util.Optional; +import java.util.function.Predicate; + +/** + * @author wind57 + */ +@Configuration(proxyBeanMethods = false) +@ConditionalOnDiscoveryEnabled +@ConditionalOnKubernetesDiscoveryEnabled +@ConditionalOnBlockingDiscoveryEnabled +@ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES) +@AutoConfigureAfter(KubernetesDiscoveryPropertiesAutoConfiguration.class) +class Fabric8DiscoveryClientPredicateAutoConfiguration { + + @Bean + @ConditionalOnMissingBean + Predicate predicate(KubernetesDiscoveryProperties properties) { + SpelExpressionParser parser = new SpelExpressionParser(); + SimpleEvaluationContext evaluationContext = SimpleEvaluationContext.forReadOnlyDataBinding() + .withInstanceMethods().build(); + + String spelExpression = properties.filter(); + Predicate predicate; + if (spelExpression == null || spelExpression.isEmpty()) { + predicate = service -> true; + } + else { + Expression filterExpr = parser.parseExpression(spelExpression); + predicate = service -> { + Boolean include = filterExpr.getValue(evaluationContext, service, Boolean.class); + return Optional.ofNullable(include).orElse(false); + }; + } + return predicate; + } + +} diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryServicesAdapter.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryServicesAdapter.java deleted file mode 100644 index 5cc5420b2a..0000000000 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryServicesAdapter.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2012-2022 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.discovery; - -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.function.Function; -import java.util.function.Predicate; - -import io.fabric8.kubernetes.api.model.Service; -import io.fabric8.kubernetes.client.KubernetesClient; - -import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; -import org.springframework.expression.Expression; -import org.springframework.expression.spel.standard.SpelExpressionParser; -import org.springframework.expression.spel.support.SimpleEvaluationContext; - -/** - * Adapts a {@link KubernetesClientServicesFunction} to a Function that takes a - * KubernetesClient as input and returns a List of Services(s), plus adds functionality - * not supported by it. - * - * @author wind57 - */ -final class Fabric8DiscoveryServicesAdapter implements Function> { - - private static final SpelExpressionParser PARSER = new SpelExpressionParser(); - - private static final SimpleEvaluationContext EVALUATION_CONTEXT = SimpleEvaluationContext.forReadOnlyDataBinding() - .withInstanceMethods().build(); - - private final KubernetesClientServicesFunction function; - - private final KubernetesDiscoveryProperties properties; - - private final Predicate filter; - - Fabric8DiscoveryServicesAdapter(KubernetesClientServicesFunction function, KubernetesDiscoveryProperties properties, - Predicate filter) { - this.function = function; - this.properties = properties; - if (filter == null) { - this.filter = filter(); - } - else { - this.filter = filter; - } - } - - @Override - public List apply(KubernetesClient client) { - if (!properties.namespaces().isEmpty()) { - List services = new ArrayList<>(); - properties.namespaces().forEach(namespace -> services.addAll(client.services().inNamespace(namespace) - .withLabels(properties.serviceLabels()).list().getItems().stream().filter(filter).toList())); - return services; - } - return function.apply(client).list().getItems().stream().filter(filter).toList(); - } - - Predicate filter() { - String spelExpression = properties.filter(); - Predicate predicate; - if (spelExpression == null || spelExpression.isEmpty()) { - predicate = service -> true; - } - else { - Expression filterExpr = PARSER.parseExpression(spelExpression); - predicate = service -> { - Boolean include = filterExpr.getValue(EVALUATION_CONTEXT, service, Boolean.class); - return Optional.ofNullable(include).orElse(false); - }; - } - return predicate; - } - -} diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8EndpointSliceV1CatalogWatch.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8EndpointSliceV1CatalogWatch.java index 2e503ffead..e1a3f8a01a 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8EndpointSliceV1CatalogWatch.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8EndpointSliceV1CatalogWatch.java @@ -16,7 +16,6 @@ package org.springframework.cloud.kubernetes.fabric8.discovery; -import java.util.ArrayList; import java.util.List; import java.util.function.Function; import java.util.stream.Stream; @@ -24,12 +23,9 @@ import io.fabric8.kubernetes.api.model.ObjectReference; import io.fabric8.kubernetes.api.model.discovery.v1.Endpoint; import io.fabric8.kubernetes.api.model.discovery.v1.EndpointSlice; -import io.fabric8.kubernetes.client.KubernetesClient; -import org.apache.commons.logging.LogFactory; import org.springframework.cloud.kubernetes.commons.discovery.EndpointNameAndNamespace; -import org.springframework.cloud.kubernetes.fabric8.Fabric8Utils; -import org.springframework.core.log.LogAccessor; +import static org.springframework.cloud.kubernetes.fabric8.discovery.Fabric8KubernetesDiscoveryClientUtils.endpointSlices; /** * Implementation that is based on EndpointSlice V1. @@ -39,32 +35,10 @@ final class Fabric8EndpointSliceV1CatalogWatch implements Function> { - private static final LogAccessor LOG = new LogAccessor(LogFactory.getLog(Fabric8EndpointSliceV1CatalogWatch.class)); - @Override public List apply(Fabric8CatalogWatchContext context) { - // take only pods that have endpoints - List endpointSlices; - KubernetesClient client = context.kubernetesClient(); - - if (context.properties().allNamespaces()) { - LOG.debug(() -> "discovering endpoint slices in all namespaces"); - endpointSlices = client.discovery().v1().endpointSlices().inAnyNamespace() - .withLabels(context.properties().serviceLabels()).list().getItems(); - } - else if (!context.properties().namespaces().isEmpty()) { - LOG.debug(() -> "discovering endpoint slices in " + context.properties().namespaces()); - List inner = new ArrayList<>(context.properties().namespaces().size()); - context.properties().namespaces() - .forEach(namespace -> inner.addAll(endpointSlices(context, namespace, client))); - endpointSlices = inner; - } - else { - String namespace = Fabric8Utils.getApplicationNamespace(context.kubernetesClient(), null, "catalog-watcher", - context.namespaceProvider()); - LOG.debug(() -> "discovering endpoint slices in namespace : " + namespace); - endpointSlices = endpointSlices(context, namespace, client); - } + List endpointSlices = endpointSlices(context.properties(), context.kubernetesClient(), + context.namespaceProvider(), "catalog-watcher"); Stream references = endpointSlices.stream().map(EndpointSlice::getEndpoints) .flatMap(List::stream).map(Endpoint::getTargetRef); @@ -73,10 +47,4 @@ else if (!context.properties().namespaces().isEmpty()) { } - private List endpointSlices(Fabric8CatalogWatchContext context, String namespace, - KubernetesClient client) { - return client.discovery().v1().endpointSlices().inNamespace(namespace) - .withLabels(context.properties().serviceLabels()).list().getItems(); - } - } diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8EndpointsCatalogWatch.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8EndpointsCatalogWatch.java index 5b3132670e..55a60b1d01 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8EndpointsCatalogWatch.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8EndpointsCatalogWatch.java @@ -28,7 +28,7 @@ import org.springframework.cloud.kubernetes.commons.discovery.EndpointNameAndNamespace; -import static org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientUtils.endpoints; +import static org.springframework.cloud.kubernetes.fabric8.discovery.Fabric8KubernetesDiscoveryClientUtils.endpoints; /** * Implementation that is based on Endpoints. diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesCatalogWatch.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatch.java similarity index 94% rename from spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesCatalogWatch.java rename to spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatch.java index 7ab4e56d23..b3a098b8fe 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesCatalogWatch.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatch.java @@ -42,21 +42,21 @@ /** * @author Oleg Vyukov */ -public class KubernetesCatalogWatch implements ApplicationEventPublisherAware { +final class Fabric8KubernetesCatalogWatch implements ApplicationEventPublisherAware { private static final String DISCOVERY_GROUP_VERSION = DISCOVERY_GROUP + "/" + DISCOVERY_VERSION; - private static final LogAccessor LOG = new LogAccessor(LogFactory.getLog(KubernetesCatalogWatch.class)); + private static final LogAccessor LOG = new LogAccessor(LogFactory.getLog(Fabric8KubernetesCatalogWatch.class)); private final Fabric8CatalogWatchContext context; private Function> stateGenerator; - private volatile List catalogEndpointsState = null; + private volatile List catalogEndpointsState; private ApplicationEventPublisher publisher; - public KubernetesCatalogWatch(KubernetesClient kubernetesClient, KubernetesDiscoveryProperties properties, + public Fabric8KubernetesCatalogWatch(KubernetesClient kubernetesClient, KubernetesDiscoveryProperties properties, KubernetesNamespaceProvider namespaceProvider) { context = new Fabric8CatalogWatchContext(kubernetesClient, properties, namespaceProvider); } @@ -67,7 +67,7 @@ public void setApplicationEventPublisher(ApplicationEventPublisher publisher) { } @Scheduled(fixedDelayString = "${spring.cloud.kubernetes.discovery.catalogServicesWatchDelay:30000}") - public void catalogServicesWatch() { + void catalogServicesWatch() { try { List currentState = stateGenerator.apply(context); diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesCatalogWatchAutoConfiguration.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchAutoConfiguration.java similarity index 87% rename from spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesCatalogWatchAutoConfiguration.java rename to spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchAutoConfiguration.java index 2d7b940b13..4967cf0c9a 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesCatalogWatchAutoConfiguration.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchAutoConfiguration.java @@ -42,13 +42,13 @@ @ConditionalOnKubernetesCatalogEnabled @ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES) @AutoConfigureAfter({ Fabric8AutoConfiguration.class, KubernetesDiscoveryPropertiesAutoConfiguration.class }) -public class KubernetesCatalogWatchAutoConfiguration { +class Fabric8KubernetesCatalogWatchAutoConfiguration { @Bean @ConditionalOnMissingBean - public KubernetesCatalogWatch kubernetesCatalogWatch(KubernetesClient client, - KubernetesDiscoveryProperties properties, Environment environment) { - return new KubernetesCatalogWatch(client, properties, new KubernetesNamespaceProvider(environment)); + Fabric8KubernetesCatalogWatch kubernetesCatalogWatch(KubernetesClient client, + KubernetesDiscoveryProperties properties, Environment environment) { + return new Fabric8KubernetesCatalogWatch(client, properties, new KubernetesNamespaceProvider(environment)); } } diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClient.java similarity index 65% rename from spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java rename to spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClient.java index 48a42a2acb..f9fe76bae6 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClient.java @@ -33,15 +33,14 @@ import org.springframework.cloud.client.discovery.DiscoveryClient; import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider; import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; -import org.springframework.context.EnvironmentAware; -import org.springframework.core.env.Environment; import org.springframework.core.log.LogAccessor; -import static org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientUtils.addresses; -import static org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientUtils.endpoints; -import static org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientUtils.endpointsPort; -import static org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientUtils.serviceInstance; -import static org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientUtils.serviceMetadata; +import static org.springframework.cloud.kubernetes.fabric8.discovery.Fabric8KubernetesDiscoveryClientUtils.addresses; +import static org.springframework.cloud.kubernetes.fabric8.discovery.Fabric8KubernetesDiscoveryClientUtils.endpoints; +import static org.springframework.cloud.kubernetes.fabric8.discovery.Fabric8KubernetesDiscoveryClientUtils.endpointsPort; +import static org.springframework.cloud.kubernetes.fabric8.discovery.Fabric8KubernetesDiscoveryClientUtils.serviceInstance; +import static org.springframework.cloud.kubernetes.fabric8.discovery.Fabric8KubernetesDiscoveryClientUtils.serviceMetadata; +import static org.springframework.cloud.kubernetes.fabric8.discovery.Fabric8KubernetesDiscoveryClientUtils.services; /** * Kubernetes implementation of {@link DiscoveryClient}. @@ -49,48 +48,31 @@ * @author Ioannis Canellos * @author Tim Ysewyn */ -public class KubernetesDiscoveryClient implements DiscoveryClient, EnvironmentAware { +final class Fabric8KubernetesDiscoveryClient implements DiscoveryClient { - private static final LogAccessor LOG = new LogAccessor(LogFactory.getLog(KubernetesDiscoveryClient.class)); + private static final LogAccessor LOG = new LogAccessor(LogFactory.getLog(Fabric8KubernetesDiscoveryClient.class)); private final KubernetesDiscoveryProperties properties; - private final KubernetesClientServicesFunction kubernetesClientServicesFunction; - private final ServicePortSecureResolver servicePortSecureResolver; - private final Fabric8DiscoveryServicesAdapter adapter; + private final KubernetesClient client; - private KubernetesClient client; + private final KubernetesNamespaceProvider namespaceProvider; - private KubernetesNamespaceProvider namespaceProvider; + private final Predicate predicate; - public KubernetesDiscoveryClient(KubernetesClient client, + Fabric8KubernetesDiscoveryClient(KubernetesClient client, KubernetesDiscoveryProperties kubernetesDiscoveryProperties, - KubernetesClientServicesFunction kubernetesClientServicesFunction) { - - this(client, kubernetesDiscoveryProperties, kubernetesClientServicesFunction, null, - new ServicePortSecureResolver(kubernetesDiscoveryProperties)); - } - - KubernetesDiscoveryClient(KubernetesClient client, KubernetesDiscoveryProperties kubernetesDiscoveryProperties, - KubernetesClientServicesFunction kubernetesClientServicesFunction, Predicate filter, - ServicePortSecureResolver servicePortSecureResolver) { + ServicePortSecureResolver servicePortSecureResolver, + KubernetesNamespaceProvider namespaceProvider, + Predicate predicate) { this.client = client; this.properties = kubernetesDiscoveryProperties; this.servicePortSecureResolver = servicePortSecureResolver; - this.kubernetesClientServicesFunction = kubernetesClientServicesFunction; - this.adapter = new Fabric8DiscoveryServicesAdapter(kubernetesClientServicesFunction, - kubernetesDiscoveryProperties, filter); - } - - public KubernetesClient getClient() { - return this.client; - } - - public void setClient(KubernetesClient client) { - this.client = client; + this.namespaceProvider = namespaceProvider; + this.predicate = predicate; } @Override @@ -103,7 +85,7 @@ public List getInstances(String serviceId) { Objects.requireNonNull(serviceId); List subsetsNS = getEndPointsList(serviceId).stream() - .map(KubernetesDiscoveryClientUtils::subsetsFromEndpoints).toList(); + .map(Fabric8KubernetesDiscoveryClientUtils::subsetsFromEndpoints).toList(); List instances = new ArrayList<>(); for (EndpointSubsetNS es : subsetsNS) { @@ -146,13 +128,8 @@ private List getNamespaceServiceInstances(EndpointSubsetNS es, @Override public List getServices() { - return adapter.apply(client).stream().map(s -> s.getMetadata().getName()).toList(); - } - - @Deprecated(forRemoval = true) - public List getServices(Predicate filter) { - return new Fabric8DiscoveryServicesAdapter(kubernetesClientServicesFunction, properties, filter).apply(client) - .stream().map(s -> s.getMetadata().getName()).toList(); + return services(properties, client, namespaceProvider, predicate, "fabric8 discovery") + .stream().map(service -> service.getMetadata().getName()).toList(); } @Override @@ -160,10 +137,4 @@ public int getOrder() { return properties.order(); } - @Deprecated(forRemoval = true) - @Override - public final void setEnvironment(Environment environment) { - namespaceProvider = new KubernetesNamespaceProvider(environment); - } - } diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientAutoConfiguration.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAutoConfiguration.java similarity index 78% rename from spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientAutoConfiguration.java rename to spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAutoConfiguration.java index d834a1eaf0..abc8ea7e96 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientAutoConfiguration.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAutoConfiguration.java @@ -16,6 +16,7 @@ package org.springframework.cloud.kubernetes.fabric8.discovery; +import io.fabric8.kubernetes.api.model.Service; import io.fabric8.kubernetes.client.KubernetesClient; import org.springframework.boot.actuate.health.HealthIndicator; @@ -30,6 +31,7 @@ import org.springframework.cloud.client.ConditionalOnDiscoveryEnabled; import org.springframework.cloud.client.ConditionalOnDiscoveryHealthIndicatorEnabled; import org.springframework.cloud.client.discovery.simple.SimpleDiscoveryClientAutoConfiguration; +import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider; import org.springframework.cloud.kubernetes.commons.PodUtils; import org.springframework.cloud.kubernetes.commons.discovery.ConditionalOnKubernetesDiscoveryEnabled; import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryClientHealthIndicatorInitializer; @@ -41,6 +43,8 @@ import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; +import java.util.function.Predicate; + /** * Auto configuration for discovery clients. * @@ -53,29 +57,25 @@ @ConditionalOnBlockingDiscoveryEnabled @ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES) @AutoConfigureBefore({ SimpleDiscoveryClientAutoConfiguration.class, CommonsClientAutoConfiguration.class }) -@AutoConfigureAfter({ Fabric8AutoConfiguration.class, KubernetesDiscoveryPropertiesAutoConfiguration.class }) -public class KubernetesDiscoveryClientAutoConfiguration { - - @Bean - @ConditionalOnMissingBean - public KubernetesClientServicesFunction servicesFunction(KubernetesDiscoveryProperties properties, - Environment environment) { - return KubernetesClientServicesFunctionProvider.servicesFunction(properties, environment); - } +@AutoConfigureAfter({ Fabric8AutoConfiguration.class, KubernetesDiscoveryPropertiesAutoConfiguration.class, + Fabric8DiscoveryClientPredicateAutoConfiguration.class}) +class Fabric8KubernetesDiscoveryClientAutoConfiguration { @Bean @ConditionalOnMissingBean - public KubernetesDiscoveryClient kubernetesDiscoveryClient(KubernetesClient client, - KubernetesDiscoveryProperties properties, - KubernetesClientServicesFunction kubernetesClientServicesFunction) { - return new KubernetesDiscoveryClient(client, properties, kubernetesClientServicesFunction, null, - new ServicePortSecureResolver(properties)); + Fabric8KubernetesDiscoveryClient kubernetesDiscoveryClient(KubernetesClient client, + KubernetesDiscoveryProperties properties, Predicate predicate, Environment environment) { + ServicePortSecureResolver servicePortSecureResolver = new ServicePortSecureResolver(properties); + KubernetesNamespaceProvider namespaceProvider = new KubernetesNamespaceProvider(environment); + return new Fabric8KubernetesDiscoveryClient( + client, properties, servicePortSecureResolver, namespaceProvider, predicate + ); } @Bean @ConditionalOnClass({ HealthIndicator.class }) @ConditionalOnDiscoveryHealthIndicatorEnabled - public KubernetesDiscoveryClientHealthIndicatorInitializer indicatorInitializer( + KubernetesDiscoveryClientHealthIndicatorInitializer indicatorInitializer( ApplicationEventPublisher applicationEventPublisher, PodUtils podUtils) { return new KubernetesDiscoveryClientHealthIndicatorInitializer(podUtils, applicationEventPublisher); } diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientConfigClientBootstrapConfiguration.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientConfigClientBootstrapConfiguration.java similarity index 87% rename from spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientConfigClientBootstrapConfiguration.java rename to spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientConfigClientBootstrapConfiguration.java index 7ab708f20d..ab3b05673e 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientConfigClientBootstrapConfiguration.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientConfigClientBootstrapConfiguration.java @@ -28,7 +28,7 @@ */ @Configuration(proxyBeanMethods = false) @ConditionalOnProperty("spring.cloud.config.discovery.enabled") -@Import({ Fabric8AutoConfiguration.class, KubernetesDiscoveryClientAutoConfiguration.class }) -public class KubernetesDiscoveryClientConfigClientBootstrapConfiguration { +@Import({ Fabric8AutoConfiguration.class, Fabric8KubernetesDiscoveryClientAutoConfiguration.class }) +class Fabric8KubernetesDiscoveryClientConfigClientBootstrapConfiguration { } diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtils.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtils.java similarity index 74% rename from spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtils.java rename to spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtils.java index d84b1cf324..c6b42d0138 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtils.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtils.java @@ -21,6 +21,7 @@ import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.function.Predicate; import java.util.stream.Collectors; import io.fabric8.kubernetes.api.model.EndpointAddress; @@ -30,10 +31,14 @@ import io.fabric8.kubernetes.api.model.EndpointsList; import io.fabric8.kubernetes.api.model.ObjectReference; import io.fabric8.kubernetes.api.model.Service; +import io.fabric8.kubernetes.api.model.ServiceList; +import io.fabric8.kubernetes.api.model.discovery.v1.EndpointSlice; +import io.fabric8.kubernetes.api.model.discovery.v1.EndpointSliceList; import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.kubernetes.client.dsl.FilterNested; import io.fabric8.kubernetes.client.dsl.FilterWatchListDeletable; import io.fabric8.kubernetes.client.dsl.Resource; +import io.fabric8.kubernetes.client.dsl.ServiceResource; import jakarta.annotation.Nullable; import org.apache.commons.logging.LogFactory; @@ -56,11 +61,11 @@ /** * @author wind57 */ -final class KubernetesDiscoveryClientUtils { +final class Fabric8KubernetesDiscoveryClientUtils { - private static final LogAccessor LOG = new LogAccessor(LogFactory.getLog(KubernetesDiscoveryClientUtils.class)); + private static final LogAccessor LOG = new LogAccessor(LogFactory.getLog(Fabric8KubernetesDiscoveryClientUtils.class)); - private KubernetesDiscoveryClientUtils() { + private Fabric8KubernetesDiscoveryClientUtils() { } @@ -167,6 +172,56 @@ static Map serviceMetadata(String serviceId, Service service, return serviceMetadata; } + static List services(KubernetesDiscoveryProperties properties, KubernetesClient client, + KubernetesNamespaceProvider namespaceProvider, Predicate predicate, String target) { + + List services; + + if (properties.allNamespaces()) { + LOG.debug(() -> "discovering services in all namespaces"); + services = filteredServices(client.services().inAnyNamespace().withNewFilter(), properties, predicate); + } + else if (!properties.namespaces().isEmpty()) { + LOG.debug(() -> "discovering services in namespaces : " + properties.namespaces()); + List inner = new ArrayList<>(properties.namespaces().size()); + properties.namespaces().forEach(namespace -> inner.addAll(filteredServices( + client.services().inNamespace(namespace).withNewFilter(), properties, predicate))); + services = inner; + } + else { + String namespace = Fabric8Utils.getApplicationNamespace(client, null, target, namespaceProvider); + LOG.debug(() -> "discovering services in namespace : " + namespace); + services = filteredServices(client.services().inNamespace(namespace).withNewFilter(), properties, predicate); + } + + return services; + } + + static List endpointSlices(KubernetesDiscoveryProperties properties, KubernetesClient client, + KubernetesNamespaceProvider namespaceProvider, String target) { + + List endpointSlices; + + if (properties.allNamespaces()) { + LOG.debug(() -> "discovering endpoint slices in all namespaces"); + endpointSlices = filteredEndpointSlices(client.discovery().v1().endpointSlices().inAnyNamespace().withNewFilter(), properties); + } + else if (!properties.namespaces().isEmpty()) { + LOG.debug(() -> "discovering endpoint slices in namespaces : " + properties.namespaces()); + List inner = new ArrayList<>(properties.namespaces().size()); + properties.namespaces().forEach(namespace -> inner.addAll(filteredEndpointSlices( + client.discovery().v1().endpointSlices().inNamespace(namespace).withNewFilter(), properties))); + endpointSlices = inner; + } + else { + String namespace = Fabric8Utils.getApplicationNamespace(client, null, target, namespaceProvider); + LOG.debug(() -> "discovering endpoint slices in namespace : " + namespace); + endpointSlices = filteredEndpointSlices(client.discovery().v1().endpointSlices().inNamespace(namespace).withNewFilter(), properties); + } + + return endpointSlices; + } + static List endpoints(KubernetesDiscoveryProperties properties, KubernetesClient client, KubernetesNamespaceProvider namespaceProvider, String target, @Nullable String serviceName) { @@ -242,6 +297,28 @@ static ServiceInstance serviceInstance(ServicePortSecureResolver servicePortSecu serviceMetadata, secured, namespace, null); } + private static List filteredEndpointSlices( + FilterNested>> filterNested, + KubernetesDiscoveryProperties properties) { + + FilterNested>> partial = filterNested + .withLabels(properties.serviceLabels()); + + return partial.endFilter().list().getItems(); + + } + + private static List filteredServices( + FilterNested>> filterNested, + KubernetesDiscoveryProperties properties, Predicate predicate) { + + FilterNested>> partial = filterNested + .withLabels(properties.serviceLabels()); + + return partial.endFilter().list().getItems().stream().filter(predicate).toList(); + + } + private static Optional fromMap(Map existingPorts, String key, String message) { Integer fromPrimaryPortName = existingPorts.get(key); if (fromPrimaryPortName == null) { diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/reactive/KubernetesReactiveDiscoveryClient.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClient.java similarity index 56% rename from spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/reactive/KubernetesReactiveDiscoveryClient.java rename to spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClient.java index f6f7c57da4..02b79e8cd1 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/reactive/KubernetesReactiveDiscoveryClient.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClient.java @@ -14,33 +14,27 @@ * limitations under the License. */ -package org.springframework.cloud.kubernetes.fabric8.discovery.reactive; +package org.springframework.cloud.kubernetes.fabric8.discovery; -import io.fabric8.kubernetes.client.KubernetesClient; import reactor.core.publisher.Flux; import reactor.core.scheduler.Schedulers; import org.springframework.cloud.client.ServiceInstance; import org.springframework.cloud.client.discovery.ReactiveDiscoveryClient; -import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; -import org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesClientServicesFunction; -import org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClient; import org.springframework.util.Assert; /** * Kubernetes implementation of {@link ReactiveDiscoveryClient}. Currently relies on the - * {@link KubernetesDiscoveryClient} for feature parity. + * {@link Fabric8KubernetesDiscoveryClient} for feature parity. * * @author Tim Ysewyn */ -public class KubernetesReactiveDiscoveryClient implements ReactiveDiscoveryClient { +final class Fabric8KubernetesReactiveDiscoveryClient implements ReactiveDiscoveryClient { - private final KubernetesDiscoveryClient kubernetesDiscoveryClient; + private final Fabric8KubernetesDiscoveryClient fabric8KubernetesDiscoveryClient; - public KubernetesReactiveDiscoveryClient(KubernetesClient client, KubernetesDiscoveryProperties properties, - KubernetesClientServicesFunction kubernetesClientServicesFunction) { - this.kubernetesDiscoveryClient = new KubernetesDiscoveryClient(client, properties, - kubernetesClientServicesFunction); + Fabric8KubernetesReactiveDiscoveryClient(Fabric8KubernetesDiscoveryClient fabric8KubernetesDiscoveryClient) { + this.fabric8KubernetesDiscoveryClient = fabric8KubernetesDiscoveryClient; } @Override @@ -51,13 +45,13 @@ public String description() { @Override public Flux getInstances(String serviceId) { Assert.notNull(serviceId, "[Assertion failed] - the object argument must not be null"); - return Flux.defer(() -> Flux.fromIterable(kubernetesDiscoveryClient.getInstances(serviceId))) + return Flux.defer(() -> Flux.fromIterable(fabric8KubernetesDiscoveryClient.getInstances(serviceId))) .subscribeOn(Schedulers.boundedElastic()); } @Override public Flux getServices() { - return Flux.defer(() -> Flux.fromIterable(kubernetesDiscoveryClient.getServices())) + return Flux.defer(() -> Flux.fromIterable(fabric8KubernetesDiscoveryClient.getServices())) .subscribeOn(Schedulers.boundedElastic()); } diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/reactive/KubernetesReactiveDiscoveryClientAutoConfiguration.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientAutoConfiguration.java similarity index 70% rename from spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/reactive/KubernetesReactiveDiscoveryClientAutoConfiguration.java rename to spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientAutoConfiguration.java index 73b8c29220..27baec9613 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/reactive/KubernetesReactiveDiscoveryClientAutoConfiguration.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientAutoConfiguration.java @@ -14,8 +14,9 @@ * limitations under the License. */ -package org.springframework.cloud.kubernetes.fabric8.discovery.reactive; +package org.springframework.cloud.kubernetes.fabric8.discovery; +import io.fabric8.kubernetes.api.model.Service; import io.fabric8.kubernetes.client.KubernetesClient; import org.springframework.boot.autoconfigure.AutoConfigureAfter; @@ -32,16 +33,16 @@ import org.springframework.cloud.client.discovery.health.DiscoveryClientHealthIndicatorProperties; import org.springframework.cloud.client.discovery.health.reactive.ReactiveDiscoveryClientHealthIndicator; import org.springframework.cloud.client.discovery.simple.reactive.SimpleReactiveDiscoveryClientAutoConfiguration; +import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider; import org.springframework.cloud.kubernetes.commons.discovery.ConditionalOnKubernetesDiscoveryEnabled; import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryPropertiesAutoConfiguration; -import org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesClientServicesFunction; -import org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesClientServicesFunctionProvider; -import org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientAutoConfiguration; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; +import java.util.function.Predicate; + /** * Auto configuration for reactive discovery client. * @@ -55,29 +56,26 @@ @AutoConfigureBefore({ SimpleReactiveDiscoveryClientAutoConfiguration.class, ReactiveCommonsClientAutoConfiguration.class }) @AutoConfigureAfter({ ReactiveCompositeDiscoveryClientAutoConfiguration.class, - KubernetesDiscoveryClientAutoConfiguration.class, KubernetesDiscoveryPropertiesAutoConfiguration.class }) -public class KubernetesReactiveDiscoveryClientAutoConfiguration { - - @Bean - @ConditionalOnMissingBean - public KubernetesClientServicesFunction servicesFunction(KubernetesDiscoveryProperties properties, - Environment environment) { - return KubernetesClientServicesFunctionProvider.servicesFunction(properties, environment); - } + Fabric8KubernetesDiscoveryClientAutoConfiguration.class, KubernetesDiscoveryPropertiesAutoConfiguration.class }) +class Fabric8KubernetesReactiveDiscoveryClientAutoConfiguration { @Bean @ConditionalOnMissingBean - public KubernetesReactiveDiscoveryClient kubernetesReactiveDiscoveryClient(KubernetesClient client, - KubernetesDiscoveryProperties properties, - KubernetesClientServicesFunction kubernetesClientServicesFunction) { - return new KubernetesReactiveDiscoveryClient(client, properties, kubernetesClientServicesFunction); + Fabric8KubernetesReactiveDiscoveryClient kubernetesReactiveDiscoveryClient(KubernetesClient client, + KubernetesDiscoveryProperties properties, Predicate predicate, Environment environment) { + ServicePortSecureResolver servicePortSecureResolver = new ServicePortSecureResolver(properties); + KubernetesNamespaceProvider namespaceProvider = new KubernetesNamespaceProvider(environment); + Fabric8KubernetesDiscoveryClient fabric8KubernetesDiscoveryClient = new Fabric8KubernetesDiscoveryClient( + client, properties, servicePortSecureResolver, namespaceProvider, predicate + ); + return new Fabric8KubernetesReactiveDiscoveryClient(fabric8KubernetesDiscoveryClient); } @Bean @ConditionalOnClass(name = "org.springframework.boot.actuate.health.ReactiveHealthIndicator") @ConditionalOnDiscoveryHealthIndicatorEnabled - public ReactiveDiscoveryClientHealthIndicator kubernetesReactiveDiscoveryClientHealthIndicator( - KubernetesReactiveDiscoveryClient client, DiscoveryClientHealthIndicatorProperties properties) { + ReactiveDiscoveryClientHealthIndicator kubernetesReactiveDiscoveryClientHealthIndicator( + Fabric8KubernetesReactiveDiscoveryClient client, DiscoveryClientHealthIndicatorProperties properties) { return new ReactiveDiscoveryClientHealthIndicator(client, properties); } diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesClientServicesFunction.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesClientServicesFunction.java deleted file mode 100644 index e06aa948df..0000000000 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesClientServicesFunction.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2013-2019 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.discovery; - -import java.util.function.Function; - -import io.fabric8.kubernetes.api.model.Service; -import io.fabric8.kubernetes.api.model.ServiceList; -import io.fabric8.kubernetes.client.KubernetesClient; -import io.fabric8.kubernetes.client.dsl.FilterWatchListDeletable; -import io.fabric8.kubernetes.client.dsl.ServiceResource; - -/** - * A regular java.util.function that is used to hide the complexity of the - * KubernetesClient interfaces. - * - * It's meant to be used to abstract things like: - * - * client.services() client.services().withLabel("key", "value") - * client.services().withoutLabel("key") - * - * The result of the application of the function can then be used for example to list the - * services like so: - * - * function.apply(client).list() - * - * See KubernetesDiscoveryClientAutoConfiguration.servicesFunction - * - * @author Georgios Andrianakis - */ -public interface KubernetesClientServicesFunction - extends Function>> { - -} diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesClientServicesFunctionProvider.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesClientServicesFunctionProvider.java deleted file mode 100644 index 583db5e9e1..0000000000 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesClientServicesFunctionProvider.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2013-2023 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.discovery; - -import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider; -import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; -import org.springframework.cloud.kubernetes.fabric8.Fabric8Utils; -import org.springframework.core.env.Environment; - -/** - * @author wind57 - */ -public final class KubernetesClientServicesFunctionProvider { - - private KubernetesClientServicesFunctionProvider() { - } - - public static KubernetesClientServicesFunction servicesFunction(KubernetesDiscoveryProperties properties, - Environment environment) { - - if (properties.allNamespaces()) { - return (client) -> client.services().inAnyNamespace().withLabels(properties.serviceLabels()); - } - - return client -> { - String namespace = Fabric8Utils.getApplicationNamespace(client, null, "discovery-service", - new KubernetesNamespaceProvider(environment)); - return client.services().inNamespace(namespace).withLabels(properties.serviceLabels()); - }; - - } - -} diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/ServicePortSecureResolver.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/ServicePortSecureResolver.java index b775cc1c77..f4feb58811 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/ServicePortSecureResolver.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/ServicePortSecureResolver.java @@ -24,7 +24,7 @@ import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; import org.springframework.core.log.LogAccessor; -class ServicePortSecureResolver { +final class ServicePortSecureResolver { private static final LogAccessor LOG = new LogAccessor(LogFactory.getLog(ServicePortSecureResolver.class)); @@ -83,12 +83,7 @@ private static void logEntry(String serviceName, Integer port, String reason) { record Input(Integer port, String serviceName, Map serviceLabels, Map serviceAnnotations) { - // used only for testing - Input(Integer port, String serviceName) { - this(port, serviceName, null, null); - } - - Input(Integer port, String serviceName, Map serviceLabels, + public Input(Integer port, String serviceName, Map serviceLabels, Map serviceAnnotations) { this.port = port; this.serviceName = serviceName; diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/resources/META-INF/spring.factories b/spring-cloud-kubernetes-fabric8-discovery/src/main/resources/META-INF/spring.factories index 7262a09151..8ea4e0620d 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/resources/META-INF/spring.factories +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/resources/META-INF/spring.factories @@ -1,2 +1,2 @@ org.springframework.cloud.bootstrap.BootstrapConfiguration=\ -org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientConfigClientBootstrapConfiguration +org.springframework.cloud.kubernetes.fabric8.discovery.Fabric8KubernetesDiscoveryClientConfigClientBootstrapConfiguration diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/spring-cloud-kubernetes-fabric8-discovery/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index 2c7e95bc99..e1b4224bad 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -1,3 +1,4 @@ -org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesCatalogWatchAutoConfiguration -org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientAutoConfiguration -org.springframework.cloud.kubernetes.fabric8.discovery.reactive.KubernetesReactiveDiscoveryClientAutoConfiguration +org.springframework.cloud.kubernetes.fabric8.discovery.Fabric8KubernetesCatalogWatchAutoConfiguration +org.springframework.cloud.kubernetes.fabric8.discovery.Fabric8KubernetesDiscoveryClientAutoConfiguration +org.springframework.cloud.kubernetes.fabric8.discovery.Fabric8KubernetesReactiveDiscoveryClientAutoConfiguration +org.springframework.cloud.kubernetes.fabric8.discovery.Fabric8DiscoveryClientPredicateAutoConfiguration diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryServicesAdapterTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryServicesAdapterTests.java index df45b1edc6..81326f2b6e 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryServicesAdapterTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryServicesAdapterTests.java @@ -43,437 +43,437 @@ @EnableKubernetesMockClient(crud = true, https = false) class Fabric8DiscoveryServicesAdapterTests { - private static KubernetesClient client; - - private static MockedStatic utils; - - @BeforeEach - void beforeEach() { - utils = Mockito.mockStatic(Fabric8Utils.class); - } - - @AfterEach - void afterEach() { - client.services().inAnyNamespace().delete(); - utils.close(); - } - - /** - *
-	 *     - all-namespaces = true
-	 *     - labels = {}
-	 *     - filter = null
-	 *
-	 *     - serviceA exists in namespaceA with labels = {color=red}
-	 *     - serviceB exists in namespaceB with labels = {color=blue}
-	 *
-	 *     - we get both services as a result.
-	 * 
- */ - @Test - void testAllNamespacesWithoutLabelsWithoutFilter() { - boolean allNamespaces = true; - Map labels = Map.of(); - String spelFilter = null; - - MockEnvironment environment = new MockEnvironment(); - - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), - true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false); - - Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( - new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, - null); - - service("namespaceA", "serviceA", Map.of("color", "red")); - service("namespaceB", "serviceB", Map.of("color", "blue")); - - List result = adapter.apply(client); - Assertions.assertEquals(result.size(), 2); - Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); - Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); - Assertions.assertEquals(result.get(1).getMetadata().getName(), "serviceB"); - Assertions.assertEquals(result.get(1).getMetadata().getNamespace(), "namespaceB"); - } - - /** - *
-	 *     - all-namespaces = true
-	 *     - labels = {color=red}
-	 *     - filter = null
-	 *
-	 *     - serviceA exists in namespaceA with labels = {color=red}
-	 *     - serviceB exists in namespaceB with labels = {color=blue}
-	 *
-	 *     - we get only serviceA as a result.
-	 * 
- */ - @Test - void testAllNamespacesWithLabelsWithoutFilter() { - boolean allNamespaces = true; - Map labels = Map.of("color", "red"); - String spelFilter = null; - - MockEnvironment environment = new MockEnvironment(); - - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), - true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false); - - Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( - new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, - null); - - service("namespaceA", "serviceA", Map.of("color", "red")); - service("namespaceB", "serviceB", Map.of("color", "blue")); - - List result = adapter.apply(client); - Assertions.assertEquals(result.size(), 1); - Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); - Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); - } - - /** - *
-	 *     - all-namespaces = true
-	 *     - labels = {}
-	 *     - filter = "#root.metadata.namespace matches '^.+A$'"
-	 *       (ends in A)
-	 *
-	 *     - serviceA exists in namespaceA with labels = {color=red}
-	 *     - serviceB exists in namespaceB with labels = {color=blue}
-	 *
-	 *     - we get only serviceA as a result.
-	 * 
- */ - @Test - void testAllNamespacesWithoutLabelsWithNamespaceFilter() { - boolean allNamespaces = true; - Map labels = Map.of(); - String spelFilter = """ - #root.metadata.namespace matches "^.+A$" - """; - - MockEnvironment environment = new MockEnvironment(); - - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), - true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false); - - Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( - new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, - null); - - service("namespaceA", "serviceA", Map.of("color", "red")); - service("namespaceB", "serviceB", Map.of("color", "blue")); - - List result = adapter.apply(client); - Assertions.assertEquals(result.size(), 1); - Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); - Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); - } - - /** - *
-	 *     - all-namespaces = true
-	 *     - labels = {}
-	 *     - filter = "#root.metadata.namespace matches '^namespace[A|B]$'"
-	 *       (namespaceA or namespaceB)
-	 *
-	 *     - serviceA exists in namespaceA with labels = {color=red}
-	 *     - serviceB exists in namespaceB with labels = {color=blue}
-	 *     - serviceC exists in namespaceC with labels = {color=purple}
-	 *
-	 *     - we get only serviceA and serviceB as a result.
-	 * 
- */ - @Test - void testAllNamespacesWithoutLabelsWithNamespacesFilter() { - boolean allNamespaces = true; - Map labels = Map.of(); - String spelFilter = """ - #root.metadata.namespace matches "^namespace[A|B]$" - """; - - MockEnvironment environment = new MockEnvironment(); - - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), - true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false); - - Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( - new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, - null); - - service("namespaceA", "serviceA", Map.of("color", "red")); - service("namespaceB", "serviceB", Map.of("color", "blue")); - service("namespaceC", "serviceC", Map.of("color", "purple")); - - List result = adapter.apply(client); - Assertions.assertEquals(result.size(), 2); - Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); - Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); - Assertions.assertEquals(result.get(1).getMetadata().getName(), "serviceB"); - Assertions.assertEquals(result.get(1).getMetadata().getNamespace(), "namespaceB"); - } - - /** - *
-	 *     - all-namespaces = false
-	 *     - specific namespace = namespaceA
-	 *     - labels = {}
-	 *
-	 *     - serviceA exists in namespaceA with labels = {color=red}
-	 *     - serviceB exists in namespaceB with labels = {color=blue}
-	 *
-	 *     - we get only serviceA as a result.
-	 * 
- */ - @Test - void testSpecificNamespaceWithoutLabelsWithoutFilter() { - boolean allNamespaces = false; - Map labels = Map.of(); - String spelFilter = null; - - MockEnvironment environment = new MockEnvironment(); - - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), - true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false); - - Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( - new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, - null); - - utils.when(() -> Fabric8Utils.getApplicationNamespace(Mockito.any(KubernetesClient.class), - Mockito.nullable(String.class), Mockito.anyString(), Mockito.any(KubernetesNamespaceProvider.class))) - .thenReturn("namespaceA"); - - service("namespaceA", "serviceA", Map.of("color", "red")); - service("namespaceB", "serviceB", Map.of("color", "blue")); - - List result = adapter.apply(client); - Assertions.assertEquals(result.size(), 1); - Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); - Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); - } - - /** - *
-	 *     - all-namespaces = false
-	 *     - specific namespace = namespaceA
-	 *     - labels = {color = purple}
-	 *
-	 *     - serviceA exists in namespaceA with labels = {color=red}
-	 *     - serviceB exists in namespaceA with labels = {color=purple}
-	 *     - serviceC exists in namespaceC with labels = {color=purple}
-	 *
-	 *     - we get only serviceB as a result, even if such labels are also
-	 *       present on a different service (but it's in a different namespace).
-	 * 
- */ - @Test - void testSpecificNamespaceWithLabelsWithoutFilter() { - boolean allNamespaces = false; - Map labels = Map.of("color", "purple"); - String spelFilter = null; - - MockEnvironment environment = new MockEnvironment(); - - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), - true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false); - - Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( - new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, - null); - - utils.when(() -> Fabric8Utils.getApplicationNamespace(Mockito.any(KubernetesClient.class), - Mockito.nullable(String.class), Mockito.anyString(), Mockito.any(KubernetesNamespaceProvider.class))) - .thenReturn("namespaceA"); - - service("namespaceA", "serviceA", Map.of("color", "red")); - service("namespaceA", "serviceB", Map.of("color", "purple")); - service("namespaceC", "serviceC", Map.of("color", "purple")); - - List result = adapter.apply(client); - Assertions.assertEquals(result.size(), 1); - Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceB"); - Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); - } - - /** - *
-	 *     - all-namespaces = false
-	 *     - specific namespace = namespaceA
-	 *     - labels = {}
-	 *     - filter = "#root.metadata.labels.containsKey("number")"
-	 *       (namespaceA or namespaceB)
-	 *
-	 *     - serviceA exists in namespaceA with labels = {color=red, number=1}
-	 *     - serviceB exists in namespaceA with labels = {color=purple, cycle=create}
-	 *     - serviceC exists in namespaceC with labels = {color=purple, number=1}
-	 *
-	 *     - we get only serviceB as a result (because of the filter) even if such labels are also
-	 *       present on a different service (but it's in a different namespace).
-	 * 
- */ - @Test - void testSpecificNamespaceWithoutLabelsWithFilter() { - boolean allNamespaces = false; - Map labels = Map.of(); - String spelFilter = """ - #root.metadata.labels.containsKey("number") - """.stripLeading(); - - MockEnvironment environment = new MockEnvironment(); - - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), - true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false); - - Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( - new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, - null); - - utils.when(() -> Fabric8Utils.getApplicationNamespace(Mockito.any(KubernetesClient.class), - Mockito.nullable(String.class), Mockito.anyString(), Mockito.any(KubernetesNamespaceProvider.class))) - .thenReturn("namespaceA"); - - service("namespaceA", "serviceA", Map.of("color", "red", "number", "1")); - service("namespaceA", "serviceB", Map.of("color", "purple", "cycle", "create")); - service("namespaceC", "serviceC", Map.of("color", "purple", "number", "1")); - - List result = adapter.apply(client); - Assertions.assertEquals(result.size(), 1); - Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); - Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); - Assertions.assertEquals(result.get(0).getMetadata().getLabels(), Map.of("color", "red", "number", "1")); - } - - /** - *
-	 *     - all-namespaces = false
-	 *     - some namespaces = [namespaceA, namespaceB]
-	 *     - labels = {}
-	 *     - filter = null
-	 *
-	 *     - serviceA exists in namespaceA with labels = {}
-	 *     - serviceB exists in namespaceB with labels = {}
-	 *     - serviceC exists in namespaceC with labels = {}
-	 *
-	 *     - we get serviceA and serviceB as a result, because their namespaces match.
-	 * 
- */ - @Test - void testSomeNamespacesWithoutLabelsWithoutFilter() { - boolean allNamespaces = false; - Set someNamespaces = Set.of("namespaceA", "namespaceB"); - Map labels = Map.of(); - String spelFilter = null; - - MockEnvironment environment = new MockEnvironment(); - - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, - someNamespaces, true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false); - - Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( - new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, - null); - - service("namespaceA", "serviceA", Map.of()); - service("namespaceB", "serviceB", Map.of()); - service("namespaceC", "serviceC", Map.of()); - - List result = adapter.apply(client); - Assertions.assertEquals(result.size(), 2); - result = result.stream().sorted(Comparator.comparing(x -> x.getMetadata().getName())).toList(); - Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); - Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); - Assertions.assertEquals(result.get(1).getMetadata().getName(), "serviceB"); - Assertions.assertEquals(result.get(1).getMetadata().getNamespace(), "namespaceB"); - } - - /** - *
-	 *     - all-namespaces = false
-	 *     - some namespaces = [namespaceA, namespaceB]
-	 *     - labels = {color=purple}
-	 *     - filter = null
-	 *
-	 *     - serviceA exists in namespaceA with labels = {color=purple}
-	 *     - serviceB exists in namespaceB with labels = {color=red}
-	 *     - serviceC exists in namespaceC with labels = {color=purple}
-	 *
-	 *     - we get serviceA as a result
-	 * 
- */ - @Test - void testSomeNamespacesWithLabelsWithoutFilter() { - boolean allNamespaces = false; - Set someNamespaces = Set.of("namespaceA", "namespaceB"); - Map labels = Map.of("color", "purple"); - String spelFilter = null; - - MockEnvironment environment = new MockEnvironment(); - - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, - someNamespaces, true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false); - - Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( - new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, - null); - - service("namespaceA", "serviceA", Map.of("color", "purple")); - service("namespaceB", "serviceB", Map.of("color", "red")); - service("namespaceC", "serviceC", Map.of("color", "purple")); - - List result = adapter.apply(client); - Assertions.assertEquals(result.size(), 1); - Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); - Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); - } - - /** - *
-	 *     - all-namespaces = false
-	 *     - some namespaces = [namespaceA, namespaceB]
-	 *     - labels = {color=purple}
-	 *     - filter = #root.metadata.labels.containsKey("number")
-	 *
-	 *     - serviceA exists in namespaceA with labels = {color=purple}
-	 *     - serviceB exists in namespaceB with labels = {color=red}
-	 *     - serviceC exists in namespaceC with labels = {color=purple}
-	 *
-	 *     - we get serviceA as a result
-	 * 
- */ - @Test - void testSomeNamespacesWithLabelsWithFilter() { - boolean allNamespaces = false; - Set someNamespaces = Set.of("namespaceA", "namespaceB"); - Map labels = Map.of("color", "purple"); - String spelFilter = """ - #root.metadata.labels.containsKey("number") - """.stripLeading(); - - MockEnvironment environment = new MockEnvironment(); - - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, - someNamespaces, true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false); - - Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( - new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, - null); - - service("namespaceA", "serviceA", Map.of("color", "purple", "number", "1")); - service("namespaceB", "serviceB", Map.of("color", "purple", "cycle", "create")); - service("namespaceC", "serviceC", Map.of("color", "purple", "number", "1")); - - List result = adapter.apply(client); - Assertions.assertEquals(result.size(), 1); - Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); - Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); - } - - private void service(String namespace, String name, Map labels) { - client.services().inNamespace(namespace) - .resource(new ServiceBuilder().withNewMetadata().withName(name).withLabels(labels).and().build()) - .create(); - } +// private static KubernetesClient client; +// +// private static MockedStatic utils; +// +// @BeforeEach +// void beforeEach() { +// utils = Mockito.mockStatic(Fabric8Utils.class); +// } +// +// @AfterEach +// void afterEach() { +// client.services().inAnyNamespace().delete(); +// utils.close(); +// } +// +// /** +// *
+//	 *     - all-namespaces = true
+//	 *     - labels = {}
+//	 *     - filter = null
+//	 *
+//	 *     - serviceA exists in namespaceA with labels = {color=red}
+//	 *     - serviceB exists in namespaceB with labels = {color=blue}
+//	 *
+//	 *     - we get both services as a result.
+//	 * 
+// */ +// @Test +// void testAllNamespacesWithoutLabelsWithoutFilter() { +// boolean allNamespaces = true; +// Map labels = Map.of(); +// String spelFilter = null; +// +// MockEnvironment environment = new MockEnvironment(); +// +// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), +// true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false); +// +// Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( +// new Fabric8KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, +// null); +// +// service("namespaceA", "serviceA", Map.of("color", "red")); +// service("namespaceB", "serviceB", Map.of("color", "blue")); +// +// List result = adapter.apply(client); +// Assertions.assertEquals(result.size(), 2); +// Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); +// Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); +// Assertions.assertEquals(result.get(1).getMetadata().getName(), "serviceB"); +// Assertions.assertEquals(result.get(1).getMetadata().getNamespace(), "namespaceB"); +// } +// +// /** +// *
+//	 *     - all-namespaces = true
+//	 *     - labels = {color=red}
+//	 *     - filter = null
+//	 *
+//	 *     - serviceA exists in namespaceA with labels = {color=red}
+//	 *     - serviceB exists in namespaceB with labels = {color=blue}
+//	 *
+//	 *     - we get only serviceA as a result.
+//	 * 
+// */ +// @Test +// void testAllNamespacesWithLabelsWithoutFilter() { +// boolean allNamespaces = true; +// Map labels = Map.of("color", "red"); +// String spelFilter = null; +// +// MockEnvironment environment = new MockEnvironment(); +// +// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), +// true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false); +// +// Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( +// new Fabric8KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, +// null); +// +// service("namespaceA", "serviceA", Map.of("color", "red")); +// service("namespaceB", "serviceB", Map.of("color", "blue")); +// +// List result = adapter.apply(client); +// Assertions.assertEquals(result.size(), 1); +// Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); +// Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); +// } +// +// /** +// *
+//	 *     - all-namespaces = true
+//	 *     - labels = {}
+//	 *     - filter = "#root.metadata.namespace matches '^.+A$'"
+//	 *       (ends in A)
+//	 *
+//	 *     - serviceA exists in namespaceA with labels = {color=red}
+//	 *     - serviceB exists in namespaceB with labels = {color=blue}
+//	 *
+//	 *     - we get only serviceA as a result.
+//	 * 
+// */ +// @Test +// void testAllNamespacesWithoutLabelsWithNamespaceFilter() { +// boolean allNamespaces = true; +// Map labels = Map.of(); +// String spelFilter = """ +// #root.metadata.namespace matches "^.+A$" +// """; +// +// MockEnvironment environment = new MockEnvironment(); +// +// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), +// true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false); +// +// Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( +// new Fabric8KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, +// null); +// +// service("namespaceA", "serviceA", Map.of("color", "red")); +// service("namespaceB", "serviceB", Map.of("color", "blue")); +// +// List result = adapter.apply(client); +// Assertions.assertEquals(result.size(), 1); +// Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); +// Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); +// } +// +// /** +// *
+//	 *     - all-namespaces = true
+//	 *     - labels = {}
+//	 *     - filter = "#root.metadata.namespace matches '^namespace[A|B]$'"
+//	 *       (namespaceA or namespaceB)
+//	 *
+//	 *     - serviceA exists in namespaceA with labels = {color=red}
+//	 *     - serviceB exists in namespaceB with labels = {color=blue}
+//	 *     - serviceC exists in namespaceC with labels = {color=purple}
+//	 *
+//	 *     - we get only serviceA and serviceB as a result.
+//	 * 
+// */ +// @Test +// void testAllNamespacesWithoutLabelsWithNamespacesFilter() { +// boolean allNamespaces = true; +// Map labels = Map.of(); +// String spelFilter = """ +// #root.metadata.namespace matches "^namespace[A|B]$" +// """; +// +// MockEnvironment environment = new MockEnvironment(); +// +// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), +// true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false); +// +// Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( +// new Fabric8KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, +// null); +// +// service("namespaceA", "serviceA", Map.of("color", "red")); +// service("namespaceB", "serviceB", Map.of("color", "blue")); +// service("namespaceC", "serviceC", Map.of("color", "purple")); +// +// List result = adapter.apply(client); +// Assertions.assertEquals(result.size(), 2); +// Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); +// Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); +// Assertions.assertEquals(result.get(1).getMetadata().getName(), "serviceB"); +// Assertions.assertEquals(result.get(1).getMetadata().getNamespace(), "namespaceB"); +// } +// +// /** +// *
+//	 *     - all-namespaces = false
+//	 *     - specific namespace = namespaceA
+//	 *     - labels = {}
+//	 *
+//	 *     - serviceA exists in namespaceA with labels = {color=red}
+//	 *     - serviceB exists in namespaceB with labels = {color=blue}
+//	 *
+//	 *     - we get only serviceA as a result.
+//	 * 
+// */ +// @Test +// void testSpecificNamespaceWithoutLabelsWithoutFilter() { +// boolean allNamespaces = false; +// Map labels = Map.of(); +// String spelFilter = null; +// +// MockEnvironment environment = new MockEnvironment(); +// +// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), +// true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false); +// +// Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( +// new Fabric8KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, +// null); +// +// utils.when(() -> Fabric8Utils.getApplicationNamespace(Mockito.any(KubernetesClient.class), +// Mockito.nullable(String.class), Mockito.anyString(), Mockito.any(KubernetesNamespaceProvider.class))) +// .thenReturn("namespaceA"); +// +// service("namespaceA", "serviceA", Map.of("color", "red")); +// service("namespaceB", "serviceB", Map.of("color", "blue")); +// +// List result = adapter.apply(client); +// Assertions.assertEquals(result.size(), 1); +// Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); +// Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); +// } +// +// /** +// *
+//	 *     - all-namespaces = false
+//	 *     - specific namespace = namespaceA
+//	 *     - labels = {color = purple}
+//	 *
+//	 *     - serviceA exists in namespaceA with labels = {color=red}
+//	 *     - serviceB exists in namespaceA with labels = {color=purple}
+//	 *     - serviceC exists in namespaceC with labels = {color=purple}
+//	 *
+//	 *     - we get only serviceB as a result, even if such labels are also
+//	 *       present on a different service (but it's in a different namespace).
+//	 * 
+// */ +// @Test +// void testSpecificNamespaceWithLabelsWithoutFilter() { +// boolean allNamespaces = false; +// Map labels = Map.of("color", "purple"); +// String spelFilter = null; +// +// MockEnvironment environment = new MockEnvironment(); +// +// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), +// true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false); +// +// Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( +// new Fabric8KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, +// null); +// +// utils.when(() -> Fabric8Utils.getApplicationNamespace(Mockito.any(KubernetesClient.class), +// Mockito.nullable(String.class), Mockito.anyString(), Mockito.any(KubernetesNamespaceProvider.class))) +// .thenReturn("namespaceA"); +// +// service("namespaceA", "serviceA", Map.of("color", "red")); +// service("namespaceA", "serviceB", Map.of("color", "purple")); +// service("namespaceC", "serviceC", Map.of("color", "purple")); +// +// List result = adapter.apply(client); +// Assertions.assertEquals(result.size(), 1); +// Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceB"); +// Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); +// } +// +// /** +// *
+//	 *     - all-namespaces = false
+//	 *     - specific namespace = namespaceA
+//	 *     - labels = {}
+//	 *     - filter = "#root.metadata.labels.containsKey("number")"
+//	 *       (namespaceA or namespaceB)
+//	 *
+//	 *     - serviceA exists in namespaceA with labels = {color=red, number=1}
+//	 *     - serviceB exists in namespaceA with labels = {color=purple, cycle=create}
+//	 *     - serviceC exists in namespaceC with labels = {color=purple, number=1}
+//	 *
+//	 *     - we get only serviceB as a result (because of the filter) even if such labels are also
+//	 *       present on a different service (but it's in a different namespace).
+//	 * 
+// */ +// @Test +// void testSpecificNamespaceWithoutLabelsWithFilter() { +// boolean allNamespaces = false; +// Map labels = Map.of(); +// String spelFilter = """ +// #root.metadata.labels.containsKey("number") +// """.stripLeading(); +// +// MockEnvironment environment = new MockEnvironment(); +// +// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), +// true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false); +// +// Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( +// new Fabric8KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, +// null); +// +// utils.when(() -> Fabric8Utils.getApplicationNamespace(Mockito.any(KubernetesClient.class), +// Mockito.nullable(String.class), Mockito.anyString(), Mockito.any(KubernetesNamespaceProvider.class))) +// .thenReturn("namespaceA"); +// +// service("namespaceA", "serviceA", Map.of("color", "red", "number", "1")); +// service("namespaceA", "serviceB", Map.of("color", "purple", "cycle", "create")); +// service("namespaceC", "serviceC", Map.of("color", "purple", "number", "1")); +// +// List result = adapter.apply(client); +// Assertions.assertEquals(result.size(), 1); +// Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); +// Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); +// Assertions.assertEquals(result.get(0).getMetadata().getLabels(), Map.of("color", "red", "number", "1")); +// } +// +// /** +// *
+//	 *     - all-namespaces = false
+//	 *     - some namespaces = [namespaceA, namespaceB]
+//	 *     - labels = {}
+//	 *     - filter = null
+//	 *
+//	 *     - serviceA exists in namespaceA with labels = {}
+//	 *     - serviceB exists in namespaceB with labels = {}
+//	 *     - serviceC exists in namespaceC with labels = {}
+//	 *
+//	 *     - we get serviceA and serviceB as a result, because their namespaces match.
+//	 * 
+// */ +// @Test +// void testSomeNamespacesWithoutLabelsWithoutFilter() { +// boolean allNamespaces = false; +// Set someNamespaces = Set.of("namespaceA", "namespaceB"); +// Map labels = Map.of(); +// String spelFilter = null; +// +// MockEnvironment environment = new MockEnvironment(); +// +// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, +// someNamespaces, true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false); +// +// Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( +// new Fabric8KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, +// null); +// +// service("namespaceA", "serviceA", Map.of()); +// service("namespaceB", "serviceB", Map.of()); +// service("namespaceC", "serviceC", Map.of()); +// +// List result = adapter.apply(client); +// Assertions.assertEquals(result.size(), 2); +// result = result.stream().sorted(Comparator.comparing(x -> x.getMetadata().getName())).toList(); +// Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); +// Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); +// Assertions.assertEquals(result.get(1).getMetadata().getName(), "serviceB"); +// Assertions.assertEquals(result.get(1).getMetadata().getNamespace(), "namespaceB"); +// } +// +// /** +// *
+//	 *     - all-namespaces = false
+//	 *     - some namespaces = [namespaceA, namespaceB]
+//	 *     - labels = {color=purple}
+//	 *     - filter = null
+//	 *
+//	 *     - serviceA exists in namespaceA with labels = {color=purple}
+//	 *     - serviceB exists in namespaceB with labels = {color=red}
+//	 *     - serviceC exists in namespaceC with labels = {color=purple}
+//	 *
+//	 *     - we get serviceA as a result
+//	 * 
+// */ +// @Test +// void testSomeNamespacesWithLabelsWithoutFilter() { +// boolean allNamespaces = false; +// Set someNamespaces = Set.of("namespaceA", "namespaceB"); +// Map labels = Map.of("color", "purple"); +// String spelFilter = null; +// +// MockEnvironment environment = new MockEnvironment(); +// +// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, +// someNamespaces, true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false); +// +// Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( +// new Fabric8KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, +// null); +// +// service("namespaceA", "serviceA", Map.of("color", "purple")); +// service("namespaceB", "serviceB", Map.of("color", "red")); +// service("namespaceC", "serviceC", Map.of("color", "purple")); +// +// List result = adapter.apply(client); +// Assertions.assertEquals(result.size(), 1); +// Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); +// Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); +// } +// +// /** +// *
+//	 *     - all-namespaces = false
+//	 *     - some namespaces = [namespaceA, namespaceB]
+//	 *     - labels = {color=purple}
+//	 *     - filter = #root.metadata.labels.containsKey("number")
+//	 *
+//	 *     - serviceA exists in namespaceA with labels = {color=purple}
+//	 *     - serviceB exists in namespaceB with labels = {color=red}
+//	 *     - serviceC exists in namespaceC with labels = {color=purple}
+//	 *
+//	 *     - we get serviceA as a result
+//	 * 
+// */ +// @Test +// void testSomeNamespacesWithLabelsWithFilter() { +// boolean allNamespaces = false; +// Set someNamespaces = Set.of("namespaceA", "namespaceB"); +// Map labels = Map.of("color", "purple"); +// String spelFilter = """ +// #root.metadata.labels.containsKey("number") +// """.stripLeading(); +// +// MockEnvironment environment = new MockEnvironment(); +// +// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, +// someNamespaces, true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false); +// +// Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( +// new Fabric8KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, +// null); +// +// service("namespaceA", "serviceA", Map.of("color", "purple", "number", "1")); +// service("namespaceB", "serviceB", Map.of("color", "purple", "cycle", "create")); +// service("namespaceC", "serviceC", Map.of("color", "purple", "number", "1")); +// +// List result = adapter.apply(client); +// Assertions.assertEquals(result.size(), 1); +// Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); +// Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); +// } +// +// private void service(String namespace, String name, Map labels) { +// client.services().inNamespace(namespace) +// .resource(new ServiceBuilder().withNewMetadata().withName(name).withLabels(labels).and().build()) +// .create(); +// } } diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8EndpointsAndEndpointSlicesTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8EndpointsAndEndpointSlicesTests.java index a289b42c5c..0d7829e10e 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8EndpointsAndEndpointSlicesTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8EndpointsAndEndpointSlicesTests.java @@ -233,13 +233,13 @@ void afterEach() { */ abstract void testTwoNamespacesOutOfThree(); - KubernetesCatalogWatch createWatcherInAllNamespacesWithLabels(Map labels, Set namespaces, - boolean endpointSlices) { + Fabric8KubernetesCatalogWatch createWatcherInAllNamespacesWithLabels(Map labels, Set namespaces, + boolean endpointSlices) { boolean allNamespaces = true; KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, true, 60, false, "", Set.of(), labels, "", null, 0, endpointSlices); - KubernetesCatalogWatch watch = new KubernetesCatalogWatch(mockClient(), properties, NAMESPACE_PROVIDER); + Fabric8KubernetesCatalogWatch watch = new Fabric8KubernetesCatalogWatch(mockClient(), properties, NAMESPACE_PROVIDER); if (endpointSlices) { watch = Mockito.spy(watch); @@ -252,15 +252,15 @@ KubernetesCatalogWatch createWatcherInAllNamespacesWithLabels(Map labels, - boolean endpointSlices) { + Fabric8KubernetesCatalogWatch createWatcherInSpecificNamespaceWithLabels(String namespace, Map labels, + boolean endpointSlices) { when(NAMESPACE_PROVIDER.getNamespace()).thenReturn(namespace); boolean allNamespaces = false; KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, Set.of(namespace), true, 60, false, "", Set.of(), labels, "", null, 0, endpointSlices); - KubernetesCatalogWatch watch = new KubernetesCatalogWatch(mockClient(), properties, NAMESPACE_PROVIDER); + Fabric8KubernetesCatalogWatch watch = new Fabric8KubernetesCatalogWatch(mockClient(), properties, NAMESPACE_PROVIDER); if (endpointSlices) { watch = Mockito.spy(watch); @@ -273,13 +273,13 @@ KubernetesCatalogWatch createWatcherInSpecificNamespaceWithLabels(String namespa } - KubernetesCatalogWatch createWatcherInSpecificNamespacesWithLabels(Set namespaces, - Map labels, boolean endpointSlices) { + Fabric8KubernetesCatalogWatch createWatcherInSpecificNamespacesWithLabels(Set namespaces, + Map labels, boolean endpointSlices) { // all-namespaces = false KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, namespaces, true, 60, false, "", Set.of(), labels, "", null, 0, false); - KubernetesCatalogWatch watch = new KubernetesCatalogWatch(mockClient(), properties, NAMESPACE_PROVIDER); + Fabric8KubernetesCatalogWatch watch = new Fabric8KubernetesCatalogWatch(mockClient(), properties, NAMESPACE_PROVIDER); if (endpointSlices) { watch = Mockito.spy(watch); @@ -317,7 +317,7 @@ static void endpointSlice(String namespace, Map labels, String p } - static void invokeAndAssert(KubernetesCatalogWatch watch, List state) { + static void invokeAndAssert(Fabric8KubernetesCatalogWatch watch, List state) { watch.catalogServicesWatch(); verify(APPLICATION_EVENT_PUBLISHER).publishEvent(HEARTBEAT_EVENT_ARGUMENT_CAPTOR.capture()); diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchEndpointSlicesSupportTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchEndpointSlicesSupportTests.java index 54cfbc8d69..1f372258c9 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchEndpointSlicesSupportTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchEndpointSlicesSupportTests.java @@ -68,7 +68,7 @@ void testEndpointSlicesEnabledButNotSupportedViaApiGroups() { APIGroupList groupList = new APIGroupListBuilder().build(); mockServer.expect().withPath("/apis").andReturn(200, groupList).always(); - KubernetesCatalogWatch watch = new KubernetesCatalogWatch(mockClient, properties, NAMESPACE_PROVIDER); + Fabric8KubernetesCatalogWatch watch = new Fabric8KubernetesCatalogWatch(mockClient, properties, NAMESPACE_PROVIDER); IllegalArgumentException ex = Assertions.assertThrows(IllegalArgumentException.class, watch::postConstruct); Assertions.assertEquals("EndpointSlices are not supported on the cluster", ex.getMessage()); } @@ -94,7 +94,7 @@ void testEndpointSlicesEnabledButNotSupportedViaApiVersions() { APIResourceList apiResourceList = new APIResourceListBuilder().build(); mockServer.expect().withPath("/apis/discovery.k8s.io/v1").andReturn(200, apiResourceList).always(); - KubernetesCatalogWatch watch = new KubernetesCatalogWatch(mockClient, properties, NAMESPACE_PROVIDER); + Fabric8KubernetesCatalogWatch watch = new Fabric8KubernetesCatalogWatch(mockClient, properties, NAMESPACE_PROVIDER); IllegalArgumentException ex = Assertions.assertThrows(IllegalArgumentException.class, watch::postConstruct); Assertions.assertEquals("EndpointSlices are not supported on the cluster", ex.getMessage()); } @@ -107,7 +107,7 @@ void testEndpointSlicesEnabledButNotSupportedViaApiVersions() { void testEndpointsSupport() { KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, false, "", Set.of(), Map.of(), "", null, 0, false); - KubernetesCatalogWatch watch = new KubernetesCatalogWatch(mockClient, properties, NAMESPACE_PROVIDER); + Fabric8KubernetesCatalogWatch watch = new Fabric8KubernetesCatalogWatch(mockClient, properties, NAMESPACE_PROVIDER); Assertions.assertEquals(Fabric8EndpointsCatalogWatch.class, watch.stateGenerator().getClass()); } @@ -120,7 +120,7 @@ void testEndpointsSupport() { void testEndpointSlicesSupport() { KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, false, "", Set.of(), Map.of(), "", null, 0, true); - KubernetesCatalogWatch watch = new KubernetesCatalogWatch(mockClient, properties, NAMESPACE_PROVIDER); + Fabric8KubernetesCatalogWatch watch = new Fabric8KubernetesCatalogWatch(mockClient, properties, NAMESPACE_PROVIDER); GroupVersionForDiscovery forDiscovery = new GroupVersionForDiscoveryBuilder() .withGroupVersion("discovery.k8s.io/v1").build(); diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchEndpointSlicesTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchEndpointSlicesTests.java index 62b213fbb6..cd371e06ea 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchEndpointSlicesTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchEndpointSlicesTests.java @@ -42,7 +42,7 @@ class Fabric8KubernetesCatalogWatchEndpointSlicesTests extends Fabric8EndpointsA @Override void testInSpecificNamespaceWithServiceLabels() { - KubernetesCatalogWatch watch = createWatcherInSpecificNamespaceWithLabels("namespaceA", Map.of("color", "blue"), + Fabric8KubernetesCatalogWatch watch = createWatcherInSpecificNamespaceWithLabels("namespaceA", Map.of("color", "blue"), ENDPOINT_SLICES); endpointSlice("namespaceA", Map.of(), "podA"); @@ -58,7 +58,7 @@ void testInSpecificNamespaceWithServiceLabels() { @Override void testInSpecificNamespaceWithoutServiceLabels() { - KubernetesCatalogWatch watch = createWatcherInSpecificNamespaceWithLabels("namespaceA", Map.of(), + Fabric8KubernetesCatalogWatch watch = createWatcherInSpecificNamespaceWithLabels("namespaceA", Map.of(), ENDPOINT_SLICES); endpointSlice("namespaceA", Map.of(), "podA"); @@ -77,7 +77,7 @@ void testInSpecificNamespaceWithoutServiceLabels() { @Override void testInAllNamespacesWithServiceLabels() { - KubernetesCatalogWatch watch = createWatcherInAllNamespacesWithLabels(Map.of("color", "blue"), Set.of(), + Fabric8KubernetesCatalogWatch watch = createWatcherInAllNamespacesWithLabels(Map.of("color", "blue"), Set.of(), ENDPOINT_SLICES); endpointSlice("namespaceA", Map.of(), "podA"); @@ -94,7 +94,7 @@ void testInAllNamespacesWithServiceLabels() { @Override void testInAllNamespacesWithoutServiceLabels() { - KubernetesCatalogWatch watch = createWatcherInAllNamespacesWithLabels(Map.of(), Set.of(), ENDPOINT_SLICES); + Fabric8KubernetesCatalogWatch watch = createWatcherInAllNamespacesWithLabels(Map.of(), Set.of(), ENDPOINT_SLICES); endpointSlice("namespaceA", Map.of(), "podA"); endpointSlice("namespaceA", Map.of("color", "blue"), "podB"); @@ -112,7 +112,7 @@ void testInAllNamespacesWithoutServiceLabels() { @Override void testAllNamespacesTrueOtherBranchesNotCalled() { - KubernetesCatalogWatch watch = createWatcherInAllNamespacesWithLabels(Map.of("color", "blue"), Set.of("B"), + Fabric8KubernetesCatalogWatch watch = createWatcherInAllNamespacesWithLabels(Map.of("color", "blue"), Set.of("B"), ENDPOINT_SLICES); endpointSlice("namespaceA", Map.of(), "podA"); @@ -129,7 +129,7 @@ void testAllNamespacesTrueOtherBranchesNotCalled() { @Override void testAllNamespacesFalseNamespacesPresent() { - KubernetesCatalogWatch watch = createWatcherInSpecificNamespacesWithLabels(Set.of("namespaceA"), + Fabric8KubernetesCatalogWatch watch = createWatcherInSpecificNamespacesWithLabels(Set.of("namespaceA"), Map.of("color", "blue"), ENDPOINT_SLICES); endpointSlice("namespaceA", Map.of(), "podA"); @@ -145,7 +145,7 @@ void testAllNamespacesFalseNamespacesPresent() { @Override void testAllNamespacesFalseNamespacesNotPresent() { - KubernetesCatalogWatch watch = createWatcherInSpecificNamespaceWithLabels("namespaceA", Map.of("color", "blue"), + Fabric8KubernetesCatalogWatch watch = createWatcherInSpecificNamespaceWithLabels("namespaceA", Map.of("color", "blue"), ENDPOINT_SLICES); endpointSlice("namespaceA", Map.of(), "podA"); @@ -161,7 +161,7 @@ void testAllNamespacesFalseNamespacesNotPresent() { @Override void testTwoNamespacesOutOfThree() { - KubernetesCatalogWatch watch = createWatcherInSpecificNamespacesWithLabels(Set.of("namespaceA", "namespaceB"), + Fabric8KubernetesCatalogWatch watch = createWatcherInSpecificNamespacesWithLabels(Set.of("namespaceA", "namespaceB"), Map.of("color", "blue"), ENDPOINT_SLICES); endpointSlice("namespaceA", Map.of(), "podA"); diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchEndpointsTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchEndpointsTests.java index de18f41356..d40e2804b5 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchEndpointsTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchEndpointsTests.java @@ -42,7 +42,7 @@ class Fabric8KubernetesCatalogWatchEndpointsTests extends Fabric8EndpointsAndEnd @Override void testInSpecificNamespaceWithServiceLabels() { - KubernetesCatalogWatch watch = createWatcherInSpecificNamespaceWithLabels("namespaceA", Map.of("color", "blue"), + Fabric8KubernetesCatalogWatch watch = createWatcherInSpecificNamespaceWithLabels("namespaceA", Map.of("color", "blue"), ENDPOINT_SLICES); endpoints("namespaceA", Map.of(), "podA"); @@ -58,7 +58,7 @@ void testInSpecificNamespaceWithServiceLabels() { @Override void testInSpecificNamespaceWithoutServiceLabels() { - KubernetesCatalogWatch watch = createWatcherInSpecificNamespaceWithLabels("namespaceA", Map.of(), + Fabric8KubernetesCatalogWatch watch = createWatcherInSpecificNamespaceWithLabels("namespaceA", Map.of(), ENDPOINT_SLICES); endpoints("namespaceA", Map.of(), "podA"); @@ -77,7 +77,7 @@ void testInSpecificNamespaceWithoutServiceLabels() { @Override void testInAllNamespacesWithServiceLabels() { - KubernetesCatalogWatch watch = createWatcherInAllNamespacesWithLabels(Map.of("color", "blue"), Set.of(), + Fabric8KubernetesCatalogWatch watch = createWatcherInAllNamespacesWithLabels(Map.of("color", "blue"), Set.of(), ENDPOINT_SLICES); endpoints("namespaceA", Map.of(), "podA"); @@ -94,7 +94,7 @@ void testInAllNamespacesWithServiceLabels() { @Override void testInAllNamespacesWithoutServiceLabels() { - KubernetesCatalogWatch watch = createWatcherInAllNamespacesWithLabels(Map.of(), Set.of(), ENDPOINT_SLICES); + Fabric8KubernetesCatalogWatch watch = createWatcherInAllNamespacesWithLabels(Map.of(), Set.of(), ENDPOINT_SLICES); endpoints("namespaceA", Map.of(), "podA"); endpoints("namespaceA", Map.of("color", "blue"), "podB"); @@ -112,7 +112,7 @@ void testInAllNamespacesWithoutServiceLabels() { @Override void testAllNamespacesTrueOtherBranchesNotCalled() { - KubernetesCatalogWatch watch = createWatcherInAllNamespacesWithLabels(Map.of("color", "blue"), Set.of("B"), + Fabric8KubernetesCatalogWatch watch = createWatcherInAllNamespacesWithLabels(Map.of("color", "blue"), Set.of("B"), ENDPOINT_SLICES); endpoints("namespaceA", Map.of(), "podA"); @@ -129,7 +129,7 @@ void testAllNamespacesTrueOtherBranchesNotCalled() { @Override void testAllNamespacesFalseNamespacesPresent() { - KubernetesCatalogWatch watch = createWatcherInSpecificNamespacesWithLabels(Set.of("namespaceA"), + Fabric8KubernetesCatalogWatch watch = createWatcherInSpecificNamespacesWithLabels(Set.of("namespaceA"), Map.of("color", "blue"), ENDPOINT_SLICES); endpoints("namespaceA", Map.of(), "podA"); @@ -145,7 +145,7 @@ void testAllNamespacesFalseNamespacesPresent() { @Override void testAllNamespacesFalseNamespacesNotPresent() { - KubernetesCatalogWatch watch = createWatcherInSpecificNamespaceWithLabels("namespaceA", Map.of("color", "blue"), + Fabric8KubernetesCatalogWatch watch = createWatcherInSpecificNamespaceWithLabels("namespaceA", Map.of("color", "blue"), ENDPOINT_SLICES); endpoints("namespaceA", Map.of(), "podA"); @@ -161,7 +161,7 @@ void testAllNamespacesFalseNamespacesNotPresent() { @Override void testTwoNamespacesOutOfThree() { - KubernetesCatalogWatch watch = createWatcherInSpecificNamespacesWithLabels(Set.of("namespaceA", "namespaceB"), + Fabric8KubernetesCatalogWatch watch = createWatcherInSpecificNamespacesWithLabels(Set.of("namespaceA", "namespaceB"), Map.of("color", "blue"), ENDPOINT_SLICES); endpoints("namespaceA", Map.of(), "podA"); diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesCatalogServicesWatchConfigurationTest.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesCatalogServicesWatchConfigurationTest.java index 6ad806343a..60fc44d1e0 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesCatalogServicesWatchConfigurationTest.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesCatalogServicesWatchConfigurationTest.java @@ -81,8 +81,8 @@ private void setup(String... env) { List envList = new ArrayList<>(Arrays.asList(env)); envList.add("spring.cloud.config.enabled=false"); context = new SpringApplicationBuilder(PropertyPlaceholderAutoConfiguration.class, - KubernetesClientTestConfiguration.class, KubernetesCatalogWatchAutoConfiguration.class, - KubernetesDiscoveryClientAutoConfiguration.class, KubernetesDiscoveryPropertiesAutoConfiguration.class) + KubernetesClientTestConfiguration.class, Fabric8KubernetesCatalogWatchAutoConfiguration.class, + Fabric8KubernetesDiscoveryClientAutoConfiguration.class, KubernetesDiscoveryPropertiesAutoConfiguration.class) .web(WebApplicationType.NONE).properties(envList.toArray(new String[0])).run(); } diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesCatalogWatchAutoConfigurationApplicationContextTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesCatalogWatchAutoConfigurationApplicationContextTests.java index fb13b9fdca..9a877374fc 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesCatalogWatchAutoConfigurationApplicationContextTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesCatalogWatchAutoConfigurationApplicationContextTests.java @@ -23,7 +23,6 @@ import org.springframework.cloud.kubernetes.commons.KubernetesCommonsAutoConfiguration; import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryPropertiesAutoConfiguration; import org.springframework.cloud.kubernetes.fabric8.Fabric8AutoConfiguration; -import org.springframework.cloud.kubernetes.fabric8.discovery.reactive.KubernetesReactiveDiscoveryClient; import static org.assertj.core.api.Assertions.assertThat; @@ -37,28 +36,28 @@ class KubernetesCatalogWatchAutoConfigurationApplicationContextTests { @Test void discoveryEnabledDefault() { setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false"); - applicationContextRunner.run(context -> assertThat(context).hasSingleBean(KubernetesCatalogWatch.class)); + applicationContextRunner.run(context -> assertThat(context).hasSingleBean(Fabric8KubernetesCatalogWatch.class)); } @Test void discoveryEnabled() { setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", "spring.cloud.discovery.enabled=true"); - applicationContextRunner.run(context -> assertThat(context).hasSingleBean(KubernetesCatalogWatch.class)); + applicationContextRunner.run(context -> assertThat(context).hasSingleBean(Fabric8KubernetesCatalogWatch.class)); } @Test void discoveryDisabled() { setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", "spring.cloud.discovery.enabled=false"); - applicationContextRunner.run(context -> assertThat(context).doesNotHaveBean(KubernetesCatalogWatch.class)); + applicationContextRunner.run(context -> assertThat(context).doesNotHaveBean(Fabric8KubernetesCatalogWatch.class)); } @Test void kubernetesDiscoveryEnabled() { setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", "spring.cloud.kubernetes.discovery.enabled=true"); - applicationContextRunner.run(context -> assertThat(context).hasSingleBean(KubernetesCatalogWatch.class)); + applicationContextRunner.run(context -> assertThat(context).hasSingleBean(Fabric8KubernetesCatalogWatch.class)); } // disabling discovery has no impact on the catalog watch. @@ -66,44 +65,44 @@ void kubernetesDiscoveryEnabled() { void kubernetesDiscoveryDisabled() { setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", "spring.cloud.kubernetes.discovery.enabled=false"); - applicationContextRunner.run(context -> assertThat(context).hasSingleBean(KubernetesCatalogWatch.class)); + applicationContextRunner.run(context -> assertThat(context).hasSingleBean(Fabric8KubernetesCatalogWatch.class)); } - /** - * both blocking and reactive configs are disabled, should not influence catalog - * watcher in any way. - */ - @Test - void disableBlockingAndReactive() { - setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", - "spring.cloud.discovery.blocking.enabled=false", "spring.cloud.discovery.reactive.enabled=false"); - applicationContextRunner.run(context -> { - assertThat(context).hasSingleBean(KubernetesCatalogWatch.class); - assertThat(context).doesNotHaveBean(KubernetesClientServicesFunction.class); - assertThat(context).doesNotHaveBean(KubernetesDiscoveryClient.class); - assertThat(context).doesNotHaveBean(KubernetesReactiveDiscoveryClient.class); - }); - } - - /** - * spring.cloud.kubernetes.discovery.enabled is false, but does not influence catalog - * watcher. - */ - @Test - void disableKubernetesDiscovery() { - setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", - "spring.cloud.kubernetes.discovery.enabled=false"); - applicationContextRunner.run(context -> { - assertThat(context).hasSingleBean(KubernetesCatalogWatch.class); - assertThat(context).doesNotHaveBean(KubernetesClientServicesFunction.class); - assertThat(context).doesNotHaveBean(KubernetesDiscoveryClient.class); - assertThat(context).doesNotHaveBean(KubernetesReactiveDiscoveryClient.class); - }); - } +// /** +// * both blocking and reactive configs are disabled, should not influence catalog +// * watcher in any way. +// */ +// @Test +// void disableBlockingAndReactive() { +// setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", +// "spring.cloud.discovery.blocking.enabled=false", "spring.cloud.discovery.reactive.enabled=false"); +// applicationContextRunner.run(context -> { +// assertThat(context).hasSingleBean(Fabric8KubernetesCatalogWatch.class); +// assertThat(context).doesNotHaveBean(KubernetesClientServicesFunction.class); +// assertThat(context).doesNotHaveBean(Fabric8KubernetesDiscoveryClient.class); +// assertThat(context).doesNotHaveBean(Fabric8KubernetesReactiveDiscoveryClient.class); +// }); +// } +// +// /** +// * spring.cloud.kubernetes.discovery.enabled is false, but does not influence catalog +// * watcher. +// */ +// @Test +// void disableKubernetesDiscovery() { +// setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", +// "spring.cloud.kubernetes.discovery.enabled=false"); +// applicationContextRunner.run(context -> { +// assertThat(context).hasSingleBean(Fabric8KubernetesCatalogWatch.class); +// assertThat(context).doesNotHaveBean(KubernetesClientServicesFunction.class); +// assertThat(context).doesNotHaveBean(Fabric8KubernetesDiscoveryClient.class); +// assertThat(context).doesNotHaveBean(Fabric8KubernetesReactiveDiscoveryClient.class); +// }); +// } private void setup(String... properties) { applicationContextRunner = new ApplicationContextRunner().withConfiguration( - AutoConfigurations.of(KubernetesCatalogWatchAutoConfiguration.class, Fabric8AutoConfiguration.class, + AutoConfigurations.of(Fabric8KubernetesCatalogWatchAutoConfiguration.class, Fabric8AutoConfiguration.class, KubernetesCommonsAutoConfiguration.class, KubernetesDiscoveryPropertiesAutoConfiguration.class)) .withPropertyValues(properties); } diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesCatalogWatchTest.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesCatalogWatchTest.java index 5f3f7b9fca..67a5c0000e 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesCatalogWatchTest.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesCatalogWatchTest.java @@ -60,7 +60,7 @@ class KubernetesCatalogWatchTest { private final KubernetesNamespaceProvider namespaceProvider = Mockito.mock(KubernetesNamespaceProvider.class); - private KubernetesCatalogWatch kubernetesCatalogWatch; + private Fabric8KubernetesCatalogWatch kubernetesCatalogWatch; private static final ApplicationEventPublisher APPLICATION_EVENT_PUBLISHER = Mockito .mock(ApplicationEventPublisher.class); @@ -370,7 +370,7 @@ private void createInAllNamespaceWatcher() { KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, false, "", Set.of(), Map.of(), "", null, 0, false); - kubernetesCatalogWatch = new KubernetesCatalogWatch(CLIENT, properties, namespaceProvider); + kubernetesCatalogWatch = new Fabric8KubernetesCatalogWatch(CLIENT, properties, namespaceProvider); kubernetesCatalogWatch.setApplicationEventPublisher(APPLICATION_EVENT_PUBLISHER); kubernetesCatalogWatch.postConstruct(); @@ -389,7 +389,7 @@ private void createInSpecificNamespaceWatcher() { KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, false, "", Set.of(), Map.of(), "", null, 0, false); - kubernetesCatalogWatch = new KubernetesCatalogWatch(CLIENT, properties, namespaceProvider); + kubernetesCatalogWatch = new Fabric8KubernetesCatalogWatch(CLIENT, properties, namespaceProvider); kubernetesCatalogWatch.setApplicationEventPublisher(APPLICATION_EVENT_PUBLISHER); kubernetesCatalogWatch.postConstruct(); diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientAutoConfigurationApplicationContextTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientAutoConfigurationApplicationContextTests.java index 9f144d84f4..1e37c431d9 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientAutoConfigurationApplicationContextTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientAutoConfigurationApplicationContextTests.java @@ -30,150 +30,150 @@ import static org.assertj.core.api.Assertions.assertThat; /** - * Test various conditionals for {@link KubernetesDiscoveryClientAutoConfiguration} + * Test various conditionals for {@link Fabric8KubernetesDiscoveryClientAutoConfiguration} * * @author wind57 */ class KubernetesDiscoveryClientAutoConfigurationApplicationContextTests { - private ApplicationContextRunner applicationContextRunner; - - @Test - void discoveryEnabledDefault() { - setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false"); - applicationContextRunner.run(context -> { - assertThat(context).hasSingleBean(KubernetesClientServicesFunction.class); - assertThat(context).hasSingleBean(KubernetesDiscoveryClient.class); - assertThat(context).hasSingleBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class); - }); - } - - @Test - void discoveryEnabled() { - setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", - "spring.cloud.discovery.enabled=true"); - applicationContextRunner.run(context -> { - assertThat(context).hasSingleBean(KubernetesClientServicesFunction.class); - assertThat(context).hasSingleBean(KubernetesDiscoveryClient.class); - assertThat(context).hasSingleBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class); - }); - } - - @Test - void discoveryDisabled() { - setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", - "spring.cloud.discovery.enabled=false"); - applicationContextRunner.run(context -> { - assertThat(context).doesNotHaveBean(KubernetesClientServicesFunction.class); - assertThat(context).doesNotHaveBean(KubernetesDiscoveryClient.class); - assertThat(context).doesNotHaveBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class); - }); - } - - @Test - void kubernetesDiscoveryEnabled() { - setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", - "spring.cloud.kubernetes.discovery.enabled=true"); - applicationContextRunner.run(context -> { - assertThat(context).hasSingleBean(KubernetesClientServicesFunction.class); - assertThat(context).hasSingleBean(KubernetesDiscoveryClient.class); - assertThat(context).hasSingleBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class); - }); - } - - @Test - void kubernetesDiscoveryDisabled() { - setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", - "spring.cloud.kubernetes.discovery.enabled=false"); - applicationContextRunner.run(context -> { - assertThat(context).doesNotHaveBean(KubernetesClientServicesFunction.class); - assertThat(context).doesNotHaveBean(KubernetesDiscoveryClient.class); - assertThat(context).doesNotHaveBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class); - }); - } - - @Test - void kubernetesDiscoveryBlockingEnabled() { - setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", - "spring.cloud.discovery.blocking.enabled=true"); - applicationContextRunner.run(context -> { - assertThat(context).hasSingleBean(KubernetesClientServicesFunction.class); - assertThat(context).hasSingleBean(KubernetesDiscoveryClient.class); - assertThat(context).hasSingleBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class); - }); - } - - @Test - void kubernetesDiscoveryBlockingDisabled() { - setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", - "spring.cloud.discovery.blocking.enabled=false"); - applicationContextRunner.run(context -> { - assertThat(context).doesNotHaveBean(KubernetesClientServicesFunction.class); - assertThat(context).doesNotHaveBean(KubernetesDiscoveryClient.class); - assertThat(context).doesNotHaveBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class); - }); - } - - @Test - void kubernetesDiscoveryHealthIndicatorEnabled() { - setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", - "spring.cloud.discovery.client.health-indicator.enabled=true"); - applicationContextRunner.run(context -> { - assertThat(context).hasSingleBean(KubernetesClientServicesFunction.class); - assertThat(context).hasSingleBean(KubernetesDiscoveryClient.class); - assertThat(context).hasSingleBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class); - }); - } - - @Test - void kubernetesDiscoveryHealthIndicatorDisabled() { - setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", - "spring.cloud.discovery.client.health-indicator.enabled=false"); - applicationContextRunner.run(context -> { - assertThat(context).hasSingleBean(KubernetesClientServicesFunction.class); - assertThat(context).hasSingleBean(KubernetesDiscoveryClient.class); - assertThat(context).doesNotHaveBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class); - }); - } - - @Test - void kubernetesDiscoveryHealthIndicatorEnabledHealthIndicatorMissing() { - setupWithFilteredClassLoader(HealthIndicator.class, "spring.main.cloud-platform=KUBERNETES", - "spring.cloud.config.enabled=false", "spring.cloud.discovery.client.health-indicator.enabled=true"); - applicationContextRunner.run(context -> { - assertThat(context).hasSingleBean(KubernetesClientServicesFunction.class); - assertThat(context).hasSingleBean(KubernetesDiscoveryClient.class); - assertThat(context).doesNotHaveBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class); - }); - } - - /** - * reactive is disabled and should not impact blocking in any way - */ - @Test - void reactiveDisabled() { - setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", - "spring.cloud.discovery.reactive.enabled=false"); - applicationContextRunner.run(context -> { - assertThat(context).hasSingleBean(KubernetesClientServicesFunction.class); - assertThat(context).hasSingleBean(KubernetesDiscoveryClient.class); - assertThat(context).hasSingleBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class); - }); - } - - private void setup(String... properties) { - applicationContextRunner = new ApplicationContextRunner().withConfiguration( - AutoConfigurations.of(KubernetesDiscoveryClientAutoConfiguration.class, Fabric8AutoConfiguration.class, - KubernetesCommonsAutoConfiguration.class, KubernetesDiscoveryPropertiesAutoConfiguration.class)) - .withPropertyValues(properties); - } - - private void setupWithFilteredClassLoader(Class cls, String... properties) { - applicationContextRunner = new ApplicationContextRunner() - .withConfiguration(AutoConfigurations.of(KubernetesDiscoveryClientAutoConfiguration.class, - Fabric8AutoConfiguration.class, KubernetesCommonsAutoConfiguration.class, - KubernetesDiscoveryPropertiesAutoConfiguration.class)) - .withClassLoader(new FilteredClassLoader(cls)).withPropertyValues(properties); - } +// private ApplicationContextRunner applicationContextRunner; +// +// @Test +// void discoveryEnabledDefault() { +// setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false"); +// applicationContextRunner.run(context -> { +// assertThat(context).hasSingleBean(KubernetesClientServicesFunction.class); +// assertThat(context).hasSingleBean(Fabric8KubernetesDiscoveryClient.class); +// assertThat(context).hasSingleBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class); +// }); +// } +// +// @Test +// void discoveryEnabled() { +// setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", +// "spring.cloud.discovery.enabled=true"); +// applicationContextRunner.run(context -> { +// assertThat(context).hasSingleBean(KubernetesClientServicesFunction.class); +// assertThat(context).hasSingleBean(Fabric8KubernetesDiscoveryClient.class); +// assertThat(context).hasSingleBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class); +// }); +// } +// +// @Test +// void discoveryDisabled() { +// setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", +// "spring.cloud.discovery.enabled=false"); +// applicationContextRunner.run(context -> { +// assertThat(context).doesNotHaveBean(KubernetesClientServicesFunction.class); +// assertThat(context).doesNotHaveBean(Fabric8KubernetesDiscoveryClient.class); +// assertThat(context).doesNotHaveBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class); +// }); +// } +// +// @Test +// void kubernetesDiscoveryEnabled() { +// setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", +// "spring.cloud.kubernetes.discovery.enabled=true"); +// applicationContextRunner.run(context -> { +// assertThat(context).hasSingleBean(KubernetesClientServicesFunction.class); +// assertThat(context).hasSingleBean(Fabric8KubernetesDiscoveryClient.class); +// assertThat(context).hasSingleBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class); +// }); +// } +// +// @Test +// void kubernetesDiscoveryDisabled() { +// setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", +// "spring.cloud.kubernetes.discovery.enabled=false"); +// applicationContextRunner.run(context -> { +// assertThat(context).doesNotHaveBean(KubernetesClientServicesFunction.class); +// assertThat(context).doesNotHaveBean(Fabric8KubernetesDiscoveryClient.class); +// assertThat(context).doesNotHaveBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class); +// }); +// } +// +// @Test +// void kubernetesDiscoveryBlockingEnabled() { +// setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", +// "spring.cloud.discovery.blocking.enabled=true"); +// applicationContextRunner.run(context -> { +// assertThat(context).hasSingleBean(KubernetesClientServicesFunction.class); +// assertThat(context).hasSingleBean(Fabric8KubernetesDiscoveryClient.class); +// assertThat(context).hasSingleBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class); +// }); +// } +// +// @Test +// void kubernetesDiscoveryBlockingDisabled() { +// setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", +// "spring.cloud.discovery.blocking.enabled=false"); +// applicationContextRunner.run(context -> { +// assertThat(context).doesNotHaveBean(KubernetesClientServicesFunction.class); +// assertThat(context).doesNotHaveBean(Fabric8KubernetesDiscoveryClient.class); +// assertThat(context).doesNotHaveBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class); +// }); +// } +// +// @Test +// void kubernetesDiscoveryHealthIndicatorEnabled() { +// setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", +// "spring.cloud.discovery.client.health-indicator.enabled=true"); +// applicationContextRunner.run(context -> { +// assertThat(context).hasSingleBean(KubernetesClientServicesFunction.class); +// assertThat(context).hasSingleBean(Fabric8KubernetesDiscoveryClient.class); +// assertThat(context).hasSingleBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class); +// }); +// } +// +// @Test +// void kubernetesDiscoveryHealthIndicatorDisabled() { +// setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", +// "spring.cloud.discovery.client.health-indicator.enabled=false"); +// applicationContextRunner.run(context -> { +// assertThat(context).hasSingleBean(KubernetesClientServicesFunction.class); +// assertThat(context).hasSingleBean(Fabric8KubernetesDiscoveryClient.class); +// assertThat(context).doesNotHaveBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class); +// }); +// } +// +// @Test +// void kubernetesDiscoveryHealthIndicatorEnabledHealthIndicatorMissing() { +// setupWithFilteredClassLoader(HealthIndicator.class, "spring.main.cloud-platform=KUBERNETES", +// "spring.cloud.config.enabled=false", "spring.cloud.discovery.client.health-indicator.enabled=true"); +// applicationContextRunner.run(context -> { +// assertThat(context).hasSingleBean(KubernetesClientServicesFunction.class); +// assertThat(context).hasSingleBean(Fabric8KubernetesDiscoveryClient.class); +// assertThat(context).doesNotHaveBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class); +// }); +// } +// +// /** +// * reactive is disabled and should not impact blocking in any way +// */ +// @Test +// void reactiveDisabled() { +// setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", +// "spring.cloud.discovery.reactive.enabled=false"); +// applicationContextRunner.run(context -> { +// assertThat(context).hasSingleBean(KubernetesClientServicesFunction.class); +// assertThat(context).hasSingleBean(Fabric8KubernetesDiscoveryClient.class); +// assertThat(context).hasSingleBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class); +// }); +// } +// +// private void setup(String... properties) { +// applicationContextRunner = new ApplicationContextRunner().withConfiguration( +// AutoConfigurations.of(Fabric8KubernetesDiscoveryClientAutoConfiguration.class, Fabric8AutoConfiguration.class, +// KubernetesCommonsAutoConfiguration.class, KubernetesDiscoveryPropertiesAutoConfiguration.class)) +// .withPropertyValues(properties); +// } +// +// private void setupWithFilteredClassLoader(Class cls, String... properties) { +// applicationContextRunner = new ApplicationContextRunner() +// .withConfiguration(AutoConfigurations.of(Fabric8KubernetesDiscoveryClientAutoConfiguration.class, +// Fabric8AutoConfiguration.class, KubernetesCommonsAutoConfiguration.class, +// KubernetesDiscoveryPropertiesAutoConfiguration.class)) +// .withClassLoader(new FilteredClassLoader(cls)).withPropertyValues(properties); +// } } diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientAutoConfigurationPropertiesTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientAutoConfigurationPropertiesTests.java index 8a252a3080..f77d5bb204 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientAutoConfigurationPropertiesTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientAutoConfigurationPropertiesTests.java @@ -56,32 +56,32 @@ void afterEach() { void kubernetesDiscoveryDisabled() { setup("spring.cloud.kubernetes.discovery.enabled=false", "spring.cloud.kubernetes.discovery.catalog-services-watch.enabled=false"); - assertThat(context.getBeanNamesForType(KubernetesDiscoveryClient.class)).isEmpty(); + assertThat(context.getBeanNamesForType(Fabric8KubernetesDiscoveryClient.class)).isEmpty(); } @Test void kubernetesDiscoveryWhenKubernetesDisabled() { setup(); - assertThat(context.getBeanNamesForType(KubernetesDiscoveryClient.class)).isEmpty(); + assertThat(context.getBeanNamesForType(Fabric8KubernetesDiscoveryClient.class)).isEmpty(); } @Test void kubernetesDiscoveryWhenDiscoveryDisabled() { setup("spring.cloud.discovery.enabled=false"); - assertThat(context.getBeanNamesForType(KubernetesDiscoveryClient.class)).isEmpty(); + assertThat(context.getBeanNamesForType(Fabric8KubernetesDiscoveryClient.class)).isEmpty(); } @Test void kubernetesDiscoveryDefaultEnabled() { setup("spring.main.cloud-platform=KUBERNETES"); - assertThat(context.getBeanNamesForType(KubernetesDiscoveryClient.class)).hasSize(1); + assertThat(context.getBeanNamesForType(Fabric8KubernetesDiscoveryClient.class)).hasSize(1); } private void setup(String... env) { List envList = new ArrayList<>(Arrays.asList(env)); envList.add("spring.cloud.config.enabled=false"); context = new SpringApplicationBuilder(PropertyPlaceholderAutoConfiguration.class, - KubernetesClientTestConfiguration.class, KubernetesDiscoveryClientAutoConfiguration.class, + KubernetesClientTestConfiguration.class, Fabric8KubernetesDiscoveryClientAutoConfiguration.class, KubernetesDiscoveryPropertiesAutoConfiguration.class) .web(org.springframework.boot.WebApplicationType.NONE) .properties(envList.toArray(new String[0])).run(); diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientAutoConfigurationTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientAutoConfigurationTests.java index 09e6ad68d4..583f55a833 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientAutoConfigurationTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientAutoConfigurationTests.java @@ -39,7 +39,7 @@ void kubernetesDiscoveryClientCreated() { assertThat(this.discoveryClient).isInstanceOf(CompositeDiscoveryClient.class); CompositeDiscoveryClient composite = (CompositeDiscoveryClient) this.discoveryClient; - assertThat(composite.getDiscoveryClients().stream().anyMatch(dc -> dc instanceof KubernetesDiscoveryClient)) + assertThat(composite.getDiscoveryClients().stream().anyMatch(dc -> dc instanceof Fabric8KubernetesDiscoveryClient)) .isTrue(); } diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientConfigClientBootstrapConfigurationTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientConfigClientBootstrapConfigurationTests.java index b153dd0386..b561fe5329 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientConfigClientBootstrapConfigurationTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientConfigClientBootstrapConfigurationTests.java @@ -74,13 +74,13 @@ private void setup(String... env) { TestPropertyValues.of(env).applyTo(parent); parent.register(UtilAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class, EnvironmentKnobbler.class, KubernetesCommonsAutoConfiguration.class, - KubernetesDiscoveryClientConfigClientBootstrapConfiguration.class, + Fabric8KubernetesDiscoveryClientConfigClientBootstrapConfiguration.class, DiscoveryClientConfigServiceBootstrapConfiguration.class, ConfigClientProperties.class); parent.refresh(); context = new AnnotationConfigApplicationContext(); context.setParent(parent); context.register(PropertyPlaceholderAutoConfiguration.class, KubernetesCommonsAutoConfiguration.class, - KubernetesDiscoveryClientAutoConfiguration.class); + Fabric8KubernetesDiscoveryClientAutoConfiguration.class); context.refresh(); } @@ -88,8 +88,8 @@ private void setup(String... env) { protected static class EnvironmentKnobbler { @Bean - KubernetesDiscoveryClient kubernetesDiscoveryClient() { - KubernetesDiscoveryClient client = mock(KubernetesDiscoveryClient.class); + Fabric8KubernetesDiscoveryClient kubernetesDiscoveryClient() { + Fabric8KubernetesDiscoveryClient client = mock(Fabric8KubernetesDiscoveryClient.class); ServiceInstance instance = new DefaultServiceInstance("configserver1", "configserver", "fake", 8888, false); given(client.getInstances("configserver")).willReturn(Collections.singletonList(instance)); return client; diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientFilterMetadataTest.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientFilterMetadataTest.java index 0e1390e611..d673f44517 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientFilterMetadataTest.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientFilterMetadataTest.java @@ -59,234 +59,234 @@ @SuppressWarnings("unchecked") class KubernetesDiscoveryClientFilterMetadataTest { - private static final KubernetesClient CLIENT = Mockito.mock(KubernetesClient.class); - - private final MixedOperation> serviceOperation = Mockito - .mock(MixedOperation.class); - - private final MixedOperation> endpointsOperation = Mockito - .mock(MixedOperation.class); - - private final ServiceResource serviceResource = Mockito.mock(ServiceResource.class); - - private final FilterWatchListDeletable> filter = Mockito - .mock(FilterWatchListDeletable.class); - - private final FilterNested>> filterNested = Mockito - .mock(FilterNested.class); - - @Test - void testAllExtraMetadataDisabled() { - String serviceId = "s"; - - Metadata metadata = new Metadata(false, null, false, null, false, null); - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, - false, null, Set.of(), Map.of(), null, metadata, 0, true); - - KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(CLIENT, properties, a -> null); - discoveryClient.setEnvironment(withClientNamespace()); - - setupServiceWithLabelsAndAnnotationsAndPorts(serviceId, "ns", Map.of("l1", "lab"), Map.of("l1", "lab"), - Map.of(80, "http", 5555, "")); - - List instances = discoveryClient.getInstances(serviceId); - assertThat(instances).hasSize(1); - assertThat(instances.get(0).getMetadata()).isEqualTo(Map.of("k8s_namespace", "ns")); - } - - @Test - void testLabelsEnabled() { - String serviceId = "s"; - - Metadata metadata = new Metadata(true, null, false, null, false, null); - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, - false, null, Set.of(), Map.of(), null, metadata, 0, true); - - KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(CLIENT, properties, a -> null); - discoveryClient.setEnvironment(withClientNamespace()); - - setupServiceWithLabelsAndAnnotationsAndPorts(serviceId, "ns", Map.of("l1", "v1", "l2", "v2"), - Map.of("l1", "lab"), Map.of(80, "http", 5555, "")); - - List instances = discoveryClient.getInstances(serviceId); - assertThat(instances).hasSize(1); - assertThat(instances.get(0).getMetadata()).containsOnly(entry("l1", "v1"), entry("l2", "v2"), - entry("k8s_namespace", "ns")); - } - - @Test - void testLabelsEnabledWithPrefix() { - String serviceId = "s"; - - Metadata metadata = new Metadata(true, "l_", false, null, false, null); - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, - false, null, Set.of(), Map.of(), null, metadata, 0, true); - - KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(CLIENT, properties, a -> null); - discoveryClient.setEnvironment(withClientNamespace()); - - setupServiceWithLabelsAndAnnotationsAndPorts(serviceId, "ns", Map.of("l1", "v1", "l2", "v2"), - Map.of("l1", "lab"), Map.of(80, "http", 5555, "")); - - List instances = discoveryClient.getInstances(serviceId); - assertThat(instances).hasSize(1); - assertThat(instances.get(0).getMetadata()).containsOnly(entry("l_l1", "v1"), entry("l_l2", "v2"), - entry("k8s_namespace", "ns")); - } - - @Test - void testAnnotationsEnabled() { - String serviceId = "s"; - - Metadata metadata = new Metadata(false, null, true, null, false, null); - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, - false, null, Set.of(), Map.of(), null, metadata, 0, true); - - KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(CLIENT, properties, a -> null); - discoveryClient.setEnvironment(withClientNamespace()); - - setupServiceWithLabelsAndAnnotationsAndPorts(serviceId, "ns", Map.of("l1", "v1"), - Map.of("a1", "v1", "a2", "v2"), Map.of(80, "http", 5555, "")); - - List instances = discoveryClient.getInstances(serviceId); - assertThat(instances).hasSize(1); - assertThat(instances.get(0).getMetadata()).containsOnly(entry("a1", "v1"), entry("a2", "v2"), - entry("k8s_namespace", "ns")); - } - - @Test - void testAnnotationsEnabledWithPrefix() { - String serviceId = "s"; - - Metadata metadata = new Metadata(false, null, true, "a_", false, null); - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, - false, null, Set.of(), Map.of(), null, metadata, 0, true); - - KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(CLIENT, properties, a -> null); - discoveryClient.setEnvironment(withClientNamespace()); - - setupServiceWithLabelsAndAnnotationsAndPorts(serviceId, "ns", Map.of("l1", "v1"), - Map.of("a1", "v1", "a2", "v2"), Map.of(80, "http", 5555, "")); - - List instances = discoveryClient.getInstances(serviceId); - assertThat(instances).hasSize(1); - assertThat(instances.get(0).getMetadata()).containsOnly(entry("a_a1", "v1"), entry("a_a2", "v2"), - entry("k8s_namespace", "ns")); - } - - @Test - void testPortsEnabled() { - String serviceId = "s"; - - Metadata metadata = new Metadata(false, null, false, null, true, null); - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, - false, null, Set.of(), Map.of(), null, metadata, 0, true); - - KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(CLIENT, properties, a -> null); - discoveryClient.setEnvironment(withClientNamespace()); - - setupServiceWithLabelsAndAnnotationsAndPorts(serviceId, "test", Map.of("l1", "v1"), - Map.of("a1", "v1", "a2", "v2"), Map.of(80, "http", 5555, "")); - - List instances = discoveryClient.getInstances(serviceId); - assertThat(instances).hasSize(1); - assertThat(instances.get(0).getMetadata()).containsOnly(entry("http", "80"), entry("k8s_namespace", "test")); - } - - @Test - void testPortsEnabledWithPrefix() { - String serviceId = "s"; - - Metadata metadata = new Metadata(false, null, false, null, true, "p_"); - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, - false, null, Set.of(), Map.of(), null, metadata, 0, true); - - KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(CLIENT, properties, a -> null); - discoveryClient.setEnvironment(withClientNamespace()); - - setupServiceWithLabelsAndAnnotationsAndPorts(serviceId, "ns", Map.of("l1", "v1"), - Map.of("a1", "v1", "a2", "v2"), Map.of(80, "http", 5555, "")); - - List instances = discoveryClient.getInstances(serviceId); - assertThat(instances).hasSize(1); - assertThat(instances.get(0).getMetadata()).containsOnly(entry("p_http", "80"), entry("k8s_namespace", "ns")); - } - - @Test - void testLabelsAndAnnotationsAndPortsEnabledWithPrefix() { - String serviceId = "s"; - - Metadata metadata = new Metadata(true, "l_", true, "a_", true, "p_"); - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, - false, null, Set.of(), Map.of(), null, metadata, 0, true); - - KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(CLIENT, properties, a -> null); - discoveryClient.setEnvironment(withClientNamespace()); - - setupServiceWithLabelsAndAnnotationsAndPorts(serviceId, "ns", Map.of("l1", "la1"), - Map.of("a1", "an1", "a2", "an2"), Map.of(80, "http", 5555, "")); - - List instances = discoveryClient.getInstances(serviceId); - assertThat(instances).hasSize(1); - assertThat(instances.get(0).getMetadata()).containsOnly(entry("a_a1", "an1"), entry("a_a2", "an2"), - entry("l_l1", "la1"), entry("p_http", "80"), entry("k8s_namespace", "ns")); - } - - private void setupServiceWithLabelsAndAnnotationsAndPorts(String serviceId, String namespace, - Map labels, Map annotations, Map ports) { - Service service = new ServiceBuilder().withNewMetadata().withNamespace(namespace).withLabels(labels) - .withAnnotations(annotations).endMetadata().withNewSpec().withPorts(getServicePorts(ports)).endSpec() - .build(); - when(serviceOperation.withName(serviceId)).thenReturn(serviceResource); - when(serviceResource.get()).thenReturn(service); - when(CLIENT.services()).thenReturn(serviceOperation); - when(CLIENT.services().inNamespace(anyString())).thenReturn(serviceOperation); - - ObjectMeta objectMeta = new ObjectMeta(); - objectMeta.setNamespace(namespace); - - Endpoints endpoints = new EndpointsBuilder().withMetadata(objectMeta).addNewSubset() - .addAllToPorts(getEndpointPorts(ports)).addNewAddress().endAddress().endSubset().build(); - - when(CLIENT.endpoints()).thenReturn(endpointsOperation); - when(endpointsOperation.inNamespace(Mockito.anyString())).thenReturn(endpointsOperation); - when(endpointsOperation.withNewFilter()).thenReturn(filterNested); - - EndpointsList endpointsList = new EndpointsList(null, Collections.singletonList(endpoints), null, null); - when(filter.list()).thenReturn(endpointsList); - when(filterNested.withLabels(anyMap())).thenReturn(filterNested); - - when(filterNested.withField(eq("metadata.name"), eq(serviceId))).thenReturn(filterNested); - when(filterNested.endFilter()).thenReturn(filter); - - } - - private List getServicePorts(Map ports) { - return ports.entrySet().stream().map(e -> { - ServicePortBuilder servicePortBuilder = new ServicePortBuilder(); - servicePortBuilder.withPort(e.getKey()); - if (!Strings.isNullOrEmpty(e.getValue())) { - servicePortBuilder.withName(e.getValue()); - } - return servicePortBuilder.build(); - }).collect(toList()); - } - - private List getEndpointPorts(Map ports) { - return ports.entrySet().stream().map(e -> { - EndpointPortBuilder endpointPortBuilder = new EndpointPortBuilder(); - endpointPortBuilder.withPort(e.getKey()); - if (!Strings.isNullOrEmpty(e.getValue())) { - endpointPortBuilder.withName(e.getValue()); - } - return endpointPortBuilder.build(); - }).collect(toList()); - } - - private static Environment withClientNamespace() { - MockEnvironment mockEnvironment = new MockEnvironment(); - mockEnvironment.setProperty("spring.cloud.kubernetes.client.namespace", "test"); - return mockEnvironment; - } +// private static final KubernetesClient CLIENT = Mockito.mock(KubernetesClient.class); +// +// private final MixedOperation> serviceOperation = Mockito +// .mock(MixedOperation.class); +// +// private final MixedOperation> endpointsOperation = Mockito +// .mock(MixedOperation.class); +// +// private final ServiceResource serviceResource = Mockito.mock(ServiceResource.class); +// +// private final FilterWatchListDeletable> filter = Mockito +// .mock(FilterWatchListDeletable.class); +// +// private final FilterNested>> filterNested = Mockito +// .mock(FilterNested.class); +// +// @Test +// void testAllExtraMetadataDisabled() { +// String serviceId = "s"; +// +// Metadata metadata = new Metadata(false, null, false, null, false, null); +// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, +// false, null, Set.of(), Map.of(), null, metadata, 0, true); +// +// Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(CLIENT, properties, a -> null); +// discoveryClient.setEnvironment(withClientNamespace()); +// +// setupServiceWithLabelsAndAnnotationsAndPorts(serviceId, "ns", Map.of("l1", "lab"), Map.of("l1", "lab"), +// Map.of(80, "http", 5555, "")); +// +// List instances = discoveryClient.getInstances(serviceId); +// assertThat(instances).hasSize(1); +// assertThat(instances.get(0).getMetadata()).isEqualTo(Map.of("k8s_namespace", "ns")); +// } +// +// @Test +// void testLabelsEnabled() { +// String serviceId = "s"; +// +// Metadata metadata = new Metadata(true, null, false, null, false, null); +// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, +// false, null, Set.of(), Map.of(), null, metadata, 0, true); +// +// Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(CLIENT, properties, a -> null); +// discoveryClient.setEnvironment(withClientNamespace()); +// +// setupServiceWithLabelsAndAnnotationsAndPorts(serviceId, "ns", Map.of("l1", "v1", "l2", "v2"), +// Map.of("l1", "lab"), Map.of(80, "http", 5555, "")); +// +// List instances = discoveryClient.getInstances(serviceId); +// assertThat(instances).hasSize(1); +// assertThat(instances.get(0).getMetadata()).containsOnly(entry("l1", "v1"), entry("l2", "v2"), +// entry("k8s_namespace", "ns")); +// } +// +// @Test +// void testLabelsEnabledWithPrefix() { +// String serviceId = "s"; +// +// Metadata metadata = new Metadata(true, "l_", false, null, false, null); +// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, +// false, null, Set.of(), Map.of(), null, metadata, 0, true); +// +// Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(CLIENT, properties, a -> null); +// discoveryClient.setEnvironment(withClientNamespace()); +// +// setupServiceWithLabelsAndAnnotationsAndPorts(serviceId, "ns", Map.of("l1", "v1", "l2", "v2"), +// Map.of("l1", "lab"), Map.of(80, "http", 5555, "")); +// +// List instances = discoveryClient.getInstances(serviceId); +// assertThat(instances).hasSize(1); +// assertThat(instances.get(0).getMetadata()).containsOnly(entry("l_l1", "v1"), entry("l_l2", "v2"), +// entry("k8s_namespace", "ns")); +// } +// +// @Test +// void testAnnotationsEnabled() { +// String serviceId = "s"; +// +// Metadata metadata = new Metadata(false, null, true, null, false, null); +// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, +// false, null, Set.of(), Map.of(), null, metadata, 0, true); +// +// Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(CLIENT, properties, a -> null); +// discoveryClient.setEnvironment(withClientNamespace()); +// +// setupServiceWithLabelsAndAnnotationsAndPorts(serviceId, "ns", Map.of("l1", "v1"), +// Map.of("a1", "v1", "a2", "v2"), Map.of(80, "http", 5555, "")); +// +// List instances = discoveryClient.getInstances(serviceId); +// assertThat(instances).hasSize(1); +// assertThat(instances.get(0).getMetadata()).containsOnly(entry("a1", "v1"), entry("a2", "v2"), +// entry("k8s_namespace", "ns")); +// } +// +// @Test +// void testAnnotationsEnabledWithPrefix() { +// String serviceId = "s"; +// +// Metadata metadata = new Metadata(false, null, true, "a_", false, null); +// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, +// false, null, Set.of(), Map.of(), null, metadata, 0, true); +// +// Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(CLIENT, properties, a -> null); +// discoveryClient.setEnvironment(withClientNamespace()); +// +// setupServiceWithLabelsAndAnnotationsAndPorts(serviceId, "ns", Map.of("l1", "v1"), +// Map.of("a1", "v1", "a2", "v2"), Map.of(80, "http", 5555, "")); +// +// List instances = discoveryClient.getInstances(serviceId); +// assertThat(instances).hasSize(1); +// assertThat(instances.get(0).getMetadata()).containsOnly(entry("a_a1", "v1"), entry("a_a2", "v2"), +// entry("k8s_namespace", "ns")); +// } +// +// @Test +// void testPortsEnabled() { +// String serviceId = "s"; +// +// Metadata metadata = new Metadata(false, null, false, null, true, null); +// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, +// false, null, Set.of(), Map.of(), null, metadata, 0, true); +// +// Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(CLIENT, properties, a -> null); +// discoveryClient.setEnvironment(withClientNamespace()); +// +// setupServiceWithLabelsAndAnnotationsAndPorts(serviceId, "test", Map.of("l1", "v1"), +// Map.of("a1", "v1", "a2", "v2"), Map.of(80, "http", 5555, "")); +// +// List instances = discoveryClient.getInstances(serviceId); +// assertThat(instances).hasSize(1); +// assertThat(instances.get(0).getMetadata()).containsOnly(entry("http", "80"), entry("k8s_namespace", "test")); +// } +// +// @Test +// void testPortsEnabledWithPrefix() { +// String serviceId = "s"; +// +// Metadata metadata = new Metadata(false, null, false, null, true, "p_"); +// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, +// false, null, Set.of(), Map.of(), null, metadata, 0, true); +// +// Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(CLIENT, properties, a -> null); +// discoveryClient.setEnvironment(withClientNamespace()); +// +// setupServiceWithLabelsAndAnnotationsAndPorts(serviceId, "ns", Map.of("l1", "v1"), +// Map.of("a1", "v1", "a2", "v2"), Map.of(80, "http", 5555, "")); +// +// List instances = discoveryClient.getInstances(serviceId); +// assertThat(instances).hasSize(1); +// assertThat(instances.get(0).getMetadata()).containsOnly(entry("p_http", "80"), entry("k8s_namespace", "ns")); +// } +// +// @Test +// void testLabelsAndAnnotationsAndPortsEnabledWithPrefix() { +// String serviceId = "s"; +// +// Metadata metadata = new Metadata(true, "l_", true, "a_", true, "p_"); +// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, +// false, null, Set.of(), Map.of(), null, metadata, 0, true); +// +// Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(CLIENT, properties, a -> null); +// discoveryClient.setEnvironment(withClientNamespace()); +// +// setupServiceWithLabelsAndAnnotationsAndPorts(serviceId, "ns", Map.of("l1", "la1"), +// Map.of("a1", "an1", "a2", "an2"), Map.of(80, "http", 5555, "")); +// +// List instances = discoveryClient.getInstances(serviceId); +// assertThat(instances).hasSize(1); +// assertThat(instances.get(0).getMetadata()).containsOnly(entry("a_a1", "an1"), entry("a_a2", "an2"), +// entry("l_l1", "la1"), entry("p_http", "80"), entry("k8s_namespace", "ns")); +// } +// +// private void setupServiceWithLabelsAndAnnotationsAndPorts(String serviceId, String namespace, +// Map labels, Map annotations, Map ports) { +// Service service = new ServiceBuilder().withNewMetadata().withNamespace(namespace).withLabels(labels) +// .withAnnotations(annotations).endMetadata().withNewSpec().withPorts(getServicePorts(ports)).endSpec() +// .build(); +// when(serviceOperation.withName(serviceId)).thenReturn(serviceResource); +// when(serviceResource.get()).thenReturn(service); +// when(CLIENT.services()).thenReturn(serviceOperation); +// when(CLIENT.services().inNamespace(anyString())).thenReturn(serviceOperation); +// +// ObjectMeta objectMeta = new ObjectMeta(); +// objectMeta.setNamespace(namespace); +// +// Endpoints endpoints = new EndpointsBuilder().withMetadata(objectMeta).addNewSubset() +// .addAllToPorts(getEndpointPorts(ports)).addNewAddress().endAddress().endSubset().build(); +// +// when(CLIENT.endpoints()).thenReturn(endpointsOperation); +// when(endpointsOperation.inNamespace(Mockito.anyString())).thenReturn(endpointsOperation); +// when(endpointsOperation.withNewFilter()).thenReturn(filterNested); +// +// EndpointsList endpointsList = new EndpointsList(null, Collections.singletonList(endpoints), null, null); +// when(filter.list()).thenReturn(endpointsList); +// when(filterNested.withLabels(anyMap())).thenReturn(filterNested); +// +// when(filterNested.withField(eq("metadata.name"), eq(serviceId))).thenReturn(filterNested); +// when(filterNested.endFilter()).thenReturn(filter); +// +// } +// +// private List getServicePorts(Map ports) { +// return ports.entrySet().stream().map(e -> { +// ServicePortBuilder servicePortBuilder = new ServicePortBuilder(); +// servicePortBuilder.withPort(e.getKey()); +// if (!Strings.isNullOrEmpty(e.getValue())) { +// servicePortBuilder.withName(e.getValue()); +// } +// return servicePortBuilder.build(); +// }).collect(toList()); +// } +// +// private List getEndpointPorts(Map ports) { +// return ports.entrySet().stream().map(e -> { +// EndpointPortBuilder endpointPortBuilder = new EndpointPortBuilder(); +// endpointPortBuilder.withPort(e.getKey()); +// if (!Strings.isNullOrEmpty(e.getValue())) { +// endpointPortBuilder.withName(e.getValue()); +// } +// return endpointPortBuilder.build(); +// }).collect(toList()); +// } +// +// private static Environment withClientNamespace() { +// MockEnvironment mockEnvironment = new MockEnvironment(); +// mockEnvironment.setProperty("spring.cloud.kubernetes.client.namespace", "test"); +// return mockEnvironment; +// } } diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientFilterTest.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientFilterTest.java index 6399457f21..9c4d655a8f 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientFilterTest.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientFilterTest.java @@ -38,101 +38,101 @@ class KubernetesDiscoveryClientFilterTest { - private final KubernetesClient kubernetesClient = Mockito.mock(KubernetesClient.class); - - private final KubernetesClientServicesFunction kubernetesClientServicesFunction = KubernetesClient::services; - - private final MixedOperation> serviceOperation = Mockito - .mock(MixedOperation.class); - - @Test - void testFilteredServices() { - List springBootServiceNames = Arrays.asList("serviceA", "serviceB"); - List services = createSpringBootServiceByName(springBootServiceNames); - - // Add non spring boot service - Service service = new Service(); - ObjectMeta objectMeta = new ObjectMeta(); - objectMeta.setName("ServiceNonSpringBoot"); - service.setMetadata(objectMeta); - services.add(service); - - ServiceList serviceList = new ServiceList(); - serviceList.setItems(services); - when(this.serviceOperation.list()).thenReturn(serviceList); - when(this.kubernetesClient.services()).thenReturn(this.serviceOperation); - - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, - false, "metadata.additionalProperties['spring-boot']", Set.of(), Map.of(), null, - KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, true); - KubernetesDiscoveryClient client = new KubernetesDiscoveryClient(this.kubernetesClient, properties, - this.kubernetesClientServicesFunction); - - List filteredServices = client.getServices(); - assertThat(filteredServices).isEqualTo(springBootServiceNames); - - } - - @Test - void testFilteredServicesByPrefix() { - List springBootServiceNames = Arrays.asList("serviceA", "serviceB", "serviceC"); - List services = createSpringBootServiceByName(springBootServiceNames); - - // Add non spring boot service - Service service = new Service(); - ObjectMeta objectMeta = new ObjectMeta(); - objectMeta.setName("anotherService"); - service.setMetadata(objectMeta); - services.add(service); - - ServiceList serviceList = new ServiceList(); - serviceList.setItems(services); - when(this.serviceOperation.list()).thenReturn(serviceList); - when(this.kubernetesClient.services()).thenReturn(this.serviceOperation); - - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, - false, "metadata.name.startsWith('service')", Set.of(), Map.of(), null, - KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, true); - KubernetesDiscoveryClient client = new KubernetesDiscoveryClient(this.kubernetesClient, properties, - this.kubernetesClientServicesFunction); - - List filteredServices = client.getServices(); - assertThat(filteredServices).isEqualTo(springBootServiceNames); - - } - - @Test - void testNoExpression() { - List springBootServiceNames = Arrays.asList("serviceA", "serviceB", "serviceC"); - List services = createSpringBootServiceByName(springBootServiceNames); - - ServiceList serviceList = new ServiceList(); - serviceList.setItems(services); - when(this.serviceOperation.list()).thenReturn(serviceList); - when(this.kubernetesClient.services()).thenReturn(this.serviceOperation); - - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, - false, "", Set.of(), Map.of(), null, KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, true); - KubernetesDiscoveryClient client = new KubernetesDiscoveryClient(this.kubernetesClient, properties, - this.kubernetesClientServicesFunction); - - List filteredServices = client.getServices(); - - assertThat(filteredServices).isEqualTo(springBootServiceNames); - - } - - private List createSpringBootServiceByName(List serviceNames) { - List serviceCollection = new ArrayList<>(serviceNames.size()); - for (String serviceName : serviceNames) { - Service service = new Service(); - ObjectMeta objectMeta = new ObjectMeta(); - objectMeta.setName(serviceName); - objectMeta.setAdditionalProperty("spring-boot", "true"); - service.setMetadata(objectMeta); - serviceCollection.add(service); - } - return serviceCollection; - } +// private final KubernetesClient kubernetesClient = Mockito.mock(KubernetesClient.class); +// +// private final KubernetesClientServicesFunction kubernetesClientServicesFunction = KubernetesClient::services; +// +// private final MixedOperation> serviceOperation = Mockito +// .mock(MixedOperation.class); +// +// @Test +// void testFilteredServices() { +// List springBootServiceNames = Arrays.asList("serviceA", "serviceB"); +// List services = createSpringBootServiceByName(springBootServiceNames); +// +// // Add non spring boot service +// Service service = new Service(); +// ObjectMeta objectMeta = new ObjectMeta(); +// objectMeta.setName("ServiceNonSpringBoot"); +// service.setMetadata(objectMeta); +// services.add(service); +// +// ServiceList serviceList = new ServiceList(); +// serviceList.setItems(services); +// when(this.serviceOperation.list()).thenReturn(serviceList); +// when(this.kubernetesClient.services()).thenReturn(this.serviceOperation); +// +// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, +// false, "metadata.additionalProperties['spring-boot']", Set.of(), Map.of(), null, +// KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, true); +// Fabric8KubernetesDiscoveryClient client = new Fabric8KubernetesDiscoveryClient(this.kubernetesClient, properties, +// this.kubernetesClientServicesFunction); +// +// List filteredServices = client.getServices(); +// assertThat(filteredServices).isEqualTo(springBootServiceNames); +// +// } +// +// @Test +// void testFilteredServicesByPrefix() { +// List springBootServiceNames = Arrays.asList("serviceA", "serviceB", "serviceC"); +// List services = createSpringBootServiceByName(springBootServiceNames); +// +// // Add non spring boot service +// Service service = new Service(); +// ObjectMeta objectMeta = new ObjectMeta(); +// objectMeta.setName("anotherService"); +// service.setMetadata(objectMeta); +// services.add(service); +// +// ServiceList serviceList = new ServiceList(); +// serviceList.setItems(services); +// when(this.serviceOperation.list()).thenReturn(serviceList); +// when(this.kubernetesClient.services()).thenReturn(this.serviceOperation); +// +// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, +// false, "metadata.name.startsWith('service')", Set.of(), Map.of(), null, +// KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, true); +// Fabric8KubernetesDiscoveryClient client = new Fabric8KubernetesDiscoveryClient(this.kubernetesClient, properties, +// this.kubernetesClientServicesFunction); +// +// List filteredServices = client.getServices(); +// assertThat(filteredServices).isEqualTo(springBootServiceNames); +// +// } +// +// @Test +// void testNoExpression() { +// List springBootServiceNames = Arrays.asList("serviceA", "serviceB", "serviceC"); +// List services = createSpringBootServiceByName(springBootServiceNames); +// +// ServiceList serviceList = new ServiceList(); +// serviceList.setItems(services); +// when(this.serviceOperation.list()).thenReturn(serviceList); +// when(this.kubernetesClient.services()).thenReturn(this.serviceOperation); +// +// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, +// false, "", Set.of(), Map.of(), null, KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, true); +// Fabric8KubernetesDiscoveryClient client = new Fabric8KubernetesDiscoveryClient(this.kubernetesClient, properties, +// this.kubernetesClientServicesFunction); +// +// List filteredServices = client.getServices(); +// +// assertThat(filteredServices).isEqualTo(springBootServiceNames); +// +// } +// +// private List createSpringBootServiceByName(List serviceNames) { +// List serviceCollection = new ArrayList<>(serviceNames.size()); +// for (String serviceName : serviceNames) { +// Service service = new Service(); +// ObjectMeta objectMeta = new ObjectMeta(); +// objectMeta.setName(serviceName); +// objectMeta.setAdditionalProperty("spring-boot", "true"); +// service.setMetadata(objectMeta); +// serviceCollection.add(service); +// } +// return serviceCollection; +// } } diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientTest.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientTest.java index 404cdcbc83..db6348c0d1 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientTest.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientTest.java @@ -45,498 +45,498 @@ @EnableKubernetesMockClient(crud = true, https = false) class KubernetesDiscoveryClientTest { - private KubernetesClient mockClient; - - @BeforeEach - void setup() { - // Configure the kubernetes master url to point to the mock server - System.setProperty(Config.KUBERNETES_MASTER_SYSTEM_PROPERTY, mockClient.getConfiguration().getMasterUrl()); - System.setProperty(Config.KUBERNETES_TRUST_CERT_SYSTEM_PROPERTY, "true"); - System.setProperty(Config.KUBERNETES_AUTH_TRYKUBECONFIG_SYSTEM_PROPERTY, "false"); - System.setProperty(Config.KUBERNETES_AUTH_TRYSERVICEACCOUNT_SYSTEM_PROPERTY, "false"); - System.setProperty(Config.KUBERNETES_HTTP2_DISABLE, "true"); - } - - @AfterEach - void afterEach() { - mockClient.close(); - } - - @Test - void getInstancesShouldBeAbleToHandleEndpointsSingleAddress() { - Map labels = Map.of("l", "v"); - - Endpoints endPoint = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace("test") - .withLabels(labels).endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef() - .withUid("10").endTargetRef().endAddress().addNewPort("http", "http_tcp", 80, "TCP").endSubset() - .build(); - - mockClient.endpoints().inNamespace("test").resource(endPoint).create(); - - Service service = new ServiceBuilder().withNewMetadata().withName("endpoint").withNamespace("test") - .withLabels(labels).endMetadata().build(); - - mockClient.services().inNamespace("test").resource(service).create(); - - DiscoveryClient discoveryClient = new KubernetesDiscoveryClient(mockClient, - KubernetesDiscoveryProperties.DEFAULT, KubernetesClient::services, null, - new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT)); - - List instances = discoveryClient.getInstances("endpoint"); - - assertThat(instances).hasSize(1).filteredOn(s -> s.getHost().equals("ip1") && !s.isSecure()).hasSize(1) - .filteredOn(s -> s.getInstanceId().equals("10")).hasSize(1); - } - - @Test - void getInstancesShouldBeAbleToHandleEndpointsSingleAddressAndMultiplePorts() { - Map labels = Map.of("l2", "v2"); - - Endpoints endPoint = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace("test") - .withLabels(labels).endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef() - .withUid("20").endTargetRef().endAddress().addNewPort("mgmt", "mgmt_tcp", 900, "TCP") - .addNewPort("http", "http_tcp", 80, "TCP").endSubset().build(); - - mockClient.endpoints().inNamespace("test").resource(endPoint).create(); - - Service service = new ServiceBuilder().withNewMetadata().withName("endpoint").withNamespace("test") - .withLabels(labels).withAnnotations(labels).endMetadata().build(); - - mockClient.services().inNamespace("test").resource(service).create(); - - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, - false, null, Set.of(), labels, "http_tcp", Metadata.DEFAULT, 0, true); - - DiscoveryClient discoveryClient = new KubernetesDiscoveryClient(mockClient, properties, - KubernetesClient::services, null, new ServicePortSecureResolver(properties)); - - List instances = discoveryClient.getInstances("endpoint"); - - assertThat(instances).hasSize(1).filteredOn(s -> s.getHost().equals("ip1") && !s.isSecure()).hasSize(1) - .filteredOn(s -> s.getInstanceId().equals("20")).hasSize(1).filteredOn(s -> 80 == s.getPort()) - .hasSize(1); - } - - @Test - void getEndPointsListTest() { - Map labels = Map.of("l", "v"); - - Endpoints endPoint = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace("test") - .withLabels(labels).endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef() - .withUid("30").endTargetRef().endAddress().addNewPort("http", "http_tcp", 80, "TCP").endSubset() - .build(); - - mockClient.endpoints().inNamespace("test").resource(endPoint).create(); - - KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(mockClient, - KubernetesDiscoveryProperties.DEFAULT, KubernetesClient::services, null, - new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT)); - - List result_endpoints = discoveryClient.getEndPointsList("endpoint"); - - assertThat(result_endpoints).hasSize(1); - } - - @Test - void getEndPointsListTestAllNamespaces() { - - String namespace1 = "ns1"; - String namespace2 = "ns2"; - - Endpoints endPoint1 = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace(namespace1) - .endMetadata().build(); - - Endpoints endPoint2 = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace(namespace2) - .endMetadata().build(); - - mockClient.endpoints().inNamespace(namespace1).resource(endPoint1).create(); - mockClient.endpoints().inNamespace(namespace2).resource(endPoint2).create(); - - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, - false, null, Set.of(), Map.of(), null, KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, false); - - KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(mockClient, properties, - KubernetesClient::services, null, new ServicePortSecureResolver(properties)); - - List result_endpoints = discoveryClient.getEndPointsList("endpoint"); - - assertThat(result_endpoints).hasSize(2); - } - - @Test - void getEndPointsListShouldHandleNamespaces() { - - String namespace1 = "ns1"; - String namespace2 = "ns2"; - String namespace3 = "ns3"; - - Endpoints endPoint1 = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace(namespace1) - .endMetadata().build(); - Endpoints endPoint2 = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace(namespace2) - .endMetadata().build(); - Endpoints endPoint3 = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace(namespace3) - .endMetadata().build(); - - mockClient.endpoints().inNamespace(namespace1).resource(endPoint1).create(); - mockClient.endpoints().inNamespace(namespace2).resource(endPoint2).create(); - mockClient.endpoints().inNamespace(namespace3).resource(endPoint3).create(); - - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, - Set.of(namespace1, namespace3), true, 60, false, null, Set.of(), Map.of(), null, - KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, false); - - KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(mockClient, properties, - KubernetesClient::services, null, new ServicePortSecureResolver(properties)); - - List result_endpoints = discoveryClient.getEndPointsList("endpoint"); - - assertThat(result_endpoints).hasSize(2); - assertThat(result_endpoints.stream().map(Endpoints::getMetadata).map(ObjectMeta::getNamespace) - .collect(Collectors.toList())).containsOnly(namespace1, namespace3); - } - - @Test - void getInstancesShouldBeAbleToHandleEndpointsMultipleAddresses() { - Map labels = Map.of("l1", "v1"); - - Endpoints endPoint = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace("test") - .withLabels(labels).endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef() - .withUid("40").endTargetRef().endAddress().addNewAddress().withIp("ip2").withNewTargetRef() - .withUid("50").endTargetRef().endAddress().addNewPort("https", "https_tcp", 443, "TCP").endSubset() - .build(); - - mockClient.endpoints().inNamespace("test").resource(endPoint).create(); - - Service service = new ServiceBuilder().withNewMetadata().withName("endpoint").withNamespace("test") - .withLabels(labels).endMetadata().build(); - - mockClient.services().inNamespace("test").resource(service).create(); - - Metadata metadata = new Metadata(false, null, false, null, true, "port."); - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, - false, null, Set.of(443, 8443), labels, null, metadata, 0, true); - - DiscoveryClient discoveryClient = new KubernetesDiscoveryClient(mockClient, properties, - KubernetesClient::services, null, new ServicePortSecureResolver(properties)); - - List instances = discoveryClient.getInstances("endpoint"); - - assertThat(instances).hasSize(2).filteredOn(ServiceInstance::isSecure).extracting(ServiceInstance::getHost) - .containsOnly("ip1", "ip2"); - } - - @Test - void getServicesShouldReturnAllServicesWhenNoLabelsAreAppliedToTheClient() { - - Map service1Labels = Collections.singletonMap("label", "value"); - Service service1 = new ServiceBuilder().withNewMetadata().withName("s1").withNamespace("test") - .withLabels(service1Labels).endMetadata().build(); - - Map service2Labels = Map.of("label", "value", "label2", "value2"); - Service service2 = new ServiceBuilder().withNewMetadata().withName("s2").withNamespace("test") - .withLabels(service2Labels).endMetadata().build(); - - Service service3 = new ServiceBuilder().withNewMetadata().withName("s3").withNamespace("test").endMetadata() - .build(); - mockClient.services().inNamespace("test").resource(service1).create(); - mockClient.services().inNamespace("test").resource(service2).create(); - mockClient.services().inNamespace("test").resource(service3).create(); - - DiscoveryClient discoveryClient = new KubernetesDiscoveryClient(mockClient, - KubernetesDiscoveryProperties.DEFAULT, KubernetesClient::services, null, - new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT)); - - List services = discoveryClient.getServices(); - - assertThat(services).containsOnly("s1", "s2", "s3"); - } - - @Test - void getServicesShouldReturnOnlyMatchingServicesWhenLabelsAreAppliedToTheClient() { - - Map service1Labels = Collections.singletonMap("label", "value"); - Service service1 = new ServiceBuilder().withNewMetadata().withName("s1").withNamespace("test") - .withLabels(service1Labels).endMetadata().build(); - - Map service2Labels = Map.of("label", "value", "label2", "value2"); - Service service2 = new ServiceBuilder().withNewMetadata().withName("s2").withNamespace("test") - .withLabels(service2Labels).endMetadata().build(); - - mockClient.services().inNamespace("test").resource(service1).create(); - mockClient.services().inNamespace("test").resource(service2).create(); - - DiscoveryClient discoveryClient = new KubernetesDiscoveryClient(mockClient, - KubernetesDiscoveryProperties.DEFAULT, - client -> client.services().withLabels(Collections.singletonMap("label", "value")), null, - new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT)); - - List services = discoveryClient.getServices(); - - assertThat(services).containsOnly("s1", "s2"); - } - - @Test - void getServicesShouldReturnServicesInNamespaces() { - - String nameSpace1 = "ns1"; - String nameSpace2 = "ns2"; - String nameSpace3 = "ns3"; - - Service service1 = new ServiceBuilder().withNewMetadata().withName("s1").withNamespace(nameSpace1).endMetadata() - .build(); - - Service service2 = new ServiceBuilder().withNewMetadata().withName("s2").withNamespace(nameSpace2).endMetadata() - .build(); - - Service service3 = new ServiceBuilder().withNewMetadata().withName("s3").withNamespace(nameSpace3).endMetadata() - .build(); - - mockClient.services().inNamespace(nameSpace1).resource(service1).create(); - mockClient.services().inNamespace(nameSpace2).resource(service2).create(); - mockClient.services().inNamespace(nameSpace3).resource(service3).create(); - - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, - Set.of(nameSpace1, nameSpace2), true, 60, false, null, Set.of(), Map.of(), null, - KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, false); - - DiscoveryClient discoveryClient = new KubernetesDiscoveryClient(mockClient, properties, - KubernetesClient::services, null, new ServicePortSecureResolver(properties)); - - List services = discoveryClient.getServices(); - - assertThat(services).containsOnly("s1", "s2"); - } - - @Test - void getInstancesShouldBeAbleToHandleEndpointsFromMultipleNamespaces() { - Endpoints endPoints1 = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace("test") - .endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef().withUid("60") - .endTargetRef().endAddress().addNewPort("http", "http_tcp", 80, "TCP").endSubset().build(); - - Endpoints endPoints2 = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace("test2") - .endMetadata().addNewSubset().addNewAddress().withIp("ip2").withNewTargetRef().withUid("70") - .endTargetRef().endAddress().addNewPort("http", "http_tcp", 80, "TCP").endSubset().build(); - - mockClient.endpoints().inNamespace("test").resource(endPoints1).create(); - mockClient.endpoints().inNamespace("test2").resource(endPoints2).create(); - - Service service1 = new ServiceBuilder().withNewMetadata().withName("endpoint").withNamespace("test") - .withLabels(Collections.singletonMap("l", "v")).endMetadata().build(); - - Service service2 = new ServiceBuilder().withNewMetadata().withName("endpoint").withNamespace("test2") - .withLabels(Collections.singletonMap("l", "v")).endMetadata().build(); - - mockClient.services().inNamespace("test").resource(service1).create(); - mockClient.services().inNamespace("test2").resource(service2).create(); - - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, - false, null, Set.of(), Map.of(), null, Metadata.DEFAULT, 0, true); - - DiscoveryClient discoveryClient = new KubernetesDiscoveryClient(mockClient, properties, - KubernetesClient::services, null, new ServicePortSecureResolver(properties)); - - List instances = discoveryClient.getInstances("endpoint"); - - assertThat(instances).hasSize(2); - assertThat(instances).filteredOn(s -> s.getHost().equals("ip1") && !s.isSecure()).hasSize(1); - assertThat(instances).filteredOn(s -> s.getHost().equals("ip2") && !s.isSecure()).hasSize(1); - assertThat(instances).filteredOn(s -> s.getServiceId().contains("endpoint") - && ((KubernetesServiceInstance) s).getNamespace().equals("test")).hasSize(1); - assertThat(instances).filteredOn(s -> s.getServiceId().contains("endpoint") - && ((KubernetesServiceInstance) s).getNamespace().equals("test2")).hasSize(1); - assertThat(instances).filteredOn(s -> s.getInstanceId().equals("60")).hasSize(1); - assertThat(instances).filteredOn(s -> s.getInstanceId().equals("70")).hasSize(1); - } - - @Test - void instanceWithoutPortsShouldBeSkipped() { - Endpoints endPoint = new EndpointsBuilder().withNewMetadata().withName("endpoint1").withNamespace("test") - .withLabels(Collections.emptyMap()).endMetadata().build(); - - mockClient.endpoints().inNamespace("test").resource(endPoint).create(); - - KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(mockClient, - KubernetesDiscoveryProperties.DEFAULT, KubernetesClient::services, null, - new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT)); - - List instances = discoveryClient.getInstances("endpoint1"); - - assertThat(instances).isEmpty(); - } - - @Test - void getInstancesShouldBeAbleToHandleEndpointsSingleAddressAndMultiplePortsUsingPrimaryPortNameLabel() { - Map labels = Map.of("primary-port-name", "https"); - - Endpoints endPoint1 = new EndpointsBuilder().withNewMetadata().withName("endpoint2").withNamespace("test") - .withLabels(labels).endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef() - .withUid("80").endTargetRef().endAddress().addNewPort("http", "https", 443, "TCP") - .addNewPort("http", "http", 80, "TCP").endSubset().build(); - - mockClient.endpoints().inNamespace("test").resource(endPoint1).create(); - - Service service = new ServiceBuilder().withNewMetadata().withName("endpoint2").withNamespace("test") - .withLabels(labels).withAnnotations(labels).endMetadata().build(); - - mockClient.services().inNamespace("test").resource(service).create(); - - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, - false, null, Set.of(443, 8443), Map.of(), null, Metadata.DEFAULT, 0, true); - - DiscoveryClient discoveryClient = new KubernetesDiscoveryClient(mockClient, properties, - KubernetesClient::services, null, new ServicePortSecureResolver(properties)); - - List instances = discoveryClient.getInstances("endpoint2"); - - assertThat(instances).hasSize(1).filteredOn(s -> s.getHost().equals("ip1") && s.isSecure()).hasSize(1) - .filteredOn(s -> s.getInstanceId().equals("80")).hasSize(1).filteredOn(s -> 443 == s.getPort()) - .hasSize(1); - } - - @Test - void instanceWithMultiplePortsAndMisconfiguredPrimaryPortNameInLabelWithoutFallbackShouldLogWarning() { - Map labels = Map.of("primary-port-name", "oops"); - - Endpoints endPoint1 = new EndpointsBuilder().withNewMetadata().withName("endpoint3").withNamespace("test") - .withLabels(labels).endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef() - .withUid("90").endTargetRef().endAddress().addNewPort("http", "https1", 443, "TCP") - .addNewPort("http", "https2", 8443, "TCP").addNewPort("http", "http1", 80, "TCP") - .addNewPort("http", "http2", 8080, "TCP").endSubset().build(); - - mockClient.endpoints().inNamespace("test").resource(endPoint1).create(); - - Service service = new ServiceBuilder().withNewMetadata().withName("endpoint3").withNamespace("test") - .withLabels(labels).withAnnotations(labels).endMetadata().build(); - - mockClient.services().inNamespace("test").resource(service).create(); - - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, - false, null, Set.of(443, 8443), Map.of(), null, Metadata.DEFAULT, 0, true); - - DiscoveryClient discoveryClient = new KubernetesDiscoveryClient(mockClient, properties, - KubernetesClient::services, null, new ServicePortSecureResolver(properties)); - - List instances = discoveryClient.getInstances("endpoint3"); - - assertThat(instances).hasSize(1).filteredOn(s -> s.getHost().equals("ip1") && s.isSecure()).hasSize(1) - .filteredOn(s -> s.getInstanceId().equals("90")).hasSize(1).filteredOn(s -> 443 == s.getPort()) - .hasSize(1); - } - - @Test - void instanceWithMultiplePortsAndMisconfiguredGenericPrimaryPortNameWithoutFallbackShouldLogWarning() { - Map labels = Map.of(); - - Endpoints endPoint1 = new EndpointsBuilder().withNewMetadata().withName("endpoint4").withNamespace("test") - .withLabels(labels).endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef() - .withUid("100").endTargetRef().endAddress().addNewPort("http", "https1", 443, "TCP") - .addNewPort("http", "https2", 8443, "TCP").addNewPort("http", "http1", 80, "TCP") - .addNewPort("http", "http2", 8080, "TCP").endSubset().build(); - - mockClient.endpoints().inNamespace("test").resource(endPoint1).create(); - - Service service = new ServiceBuilder().withNewMetadata().withName("endpoint4").withNamespace("test") - .withLabels(labels).withAnnotations(labels).endMetadata().build(); - - mockClient.services().inNamespace("test").resource(service).create(); - - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, - false, null, Set.of(443, 8443), Map.of(), "oops", Metadata.DEFAULT, 0, true); - - DiscoveryClient discoveryClient = new KubernetesDiscoveryClient(mockClient, properties, - KubernetesClient::services, null, new ServicePortSecureResolver(properties)); - - List instances = discoveryClient.getInstances("endpoint4"); - - assertThat(instances).hasSize(1).filteredOn(s -> s.getHost().equals("ip1") && s.isSecure()).hasSize(1) - .filteredOn(s -> s.getInstanceId().equals("100")).hasSize(1).filteredOn(s -> 443 == s.getPort()) - .hasSize(1); - } - - @Test - void instanceWithMultiplePortsAndWithoutPrimaryPortNameSpecifiedShouldFallBackToHttps() { - Map labels = Map.of(); - - Endpoints endPoint1 = new EndpointsBuilder().withNewMetadata().withName("endpoint5").withNamespace("test") - .withLabels(labels).endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef() - .withUid("110").endTargetRef().endAddress().addNewPort("http", "https", 443, "TCP") - .addNewPort("http", "http", 80, "TCP").endSubset().build(); - - mockClient.endpoints().inNamespace("test").resource(endPoint1).create(); - - Service service = new ServiceBuilder().withNewMetadata().withName("endpoint5").withNamespace("test") - .withLabels(labels).withAnnotations(labels).endMetadata().build(); - - mockClient.services().inNamespace("test").resource(service).create(); - - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, - false, null, Set.of(443, 8443), Map.of(), null, Metadata.DEFAULT, 0, true); - - DiscoveryClient discoveryClient = new KubernetesDiscoveryClient(mockClient, properties, - KubernetesClient::services, null, new ServicePortSecureResolver(properties)); - - List instances = discoveryClient.getInstances("endpoint5"); - - assertThat(instances).hasSize(1).filteredOn(s -> s.getHost().equals("ip1") && s.isSecure()).hasSize(1) - .filteredOn(s -> s.getInstanceId().equals("110")).hasSize(1).filteredOn(s -> 443 == s.getPort()) - .hasSize(1); - } - - @Test - void instanceWithMultiplePortsAndWithoutPrimaryPortNameSpecifiedOrHttpsPortShouldFallBackToHttp() { - Map labels = Map.of(); - - Endpoints endPoint1 = new EndpointsBuilder().withNewMetadata().withName("endpoint5").withNamespace("test") - .withLabels(labels).endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef() - .withUid("120").endTargetRef().endAddress().addNewPort("http", "https1", 443, "TCP") - .addNewPort("http", "https2", 8443, "TCP").addNewPort("http", "http", 80, "TCP").endSubset().build(); - - mockClient.endpoints().inNamespace("test").resource(endPoint1).create(); - - Service service = new ServiceBuilder().withNewMetadata().withName("endpoint5").withNamespace("test") - .withLabels(labels).withAnnotations(labels).endMetadata().build(); - - mockClient.services().inNamespace("test").resource(service).create(); - - DiscoveryClient discoveryClient = new KubernetesDiscoveryClient(mockClient, - KubernetesDiscoveryProperties.DEFAULT, KubernetesClient::services, null, - new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT)); - - List instances = discoveryClient.getInstances("endpoint5"); - - assertThat(instances).hasSize(1).filteredOn(s -> s.getHost().equals("ip1") && !s.isSecure()).hasSize(1) - .filteredOn(s -> s.getInstanceId().equals("120")).hasSize(1).filteredOn(s -> 80 == s.getPort()) - .hasSize(1); - } - - @Test - void instanceWithMultiplePortsAndWithoutPrimaryPortNameSpecifiedShouldLogWarning() { - Map labels = Map.of(); - - Endpoints endPoint1 = new EndpointsBuilder().withNewMetadata().withName("endpoint5").withNamespace("test") - .withLabels(labels).endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef() - .withUid("130").endTargetRef().endAddress().addNewPort("http", "https", 443, "TCP") - .addNewPort("http", "http", 80, "TCP").endSubset().build(); - - mockClient.endpoints().inNamespace("test").resource(endPoint1).create(); - - Service service = new ServiceBuilder().withNewMetadata().withName("endpoint5").withNamespace("test") - .withLabels(labels).withAnnotations(labels).endMetadata().build(); - - mockClient.services().inNamespace("test").resource(service).create(); - - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, - true, null, Set.of(443, 8443), Map.of(), null, Metadata.DEFAULT, 0, true); - - DiscoveryClient discoveryClient = new KubernetesDiscoveryClient(mockClient, properties, - KubernetesClient::services, null, new ServicePortSecureResolver(properties)); - - List instances = discoveryClient.getInstances("endpoint5"); - - // We're returning the first discovered port to not change previous behaviour - assertThat(instances).hasSize(1).filteredOn(s -> s.getHost().equals("ip1") && s.isSecure()).hasSize(1) - .filteredOn(s -> s.getInstanceId().equals("130")).hasSize(1).filteredOn(s -> 443 == s.getPort()) - .hasSize(1); - } +// private KubernetesClient mockClient; +// +// @BeforeEach +// void setup() { +// // Configure the kubernetes master url to point to the mock server +// System.setProperty(Config.KUBERNETES_MASTER_SYSTEM_PROPERTY, mockClient.getConfiguration().getMasterUrl()); +// System.setProperty(Config.KUBERNETES_TRUST_CERT_SYSTEM_PROPERTY, "true"); +// System.setProperty(Config.KUBERNETES_AUTH_TRYKUBECONFIG_SYSTEM_PROPERTY, "false"); +// System.setProperty(Config.KUBERNETES_AUTH_TRYSERVICEACCOUNT_SYSTEM_PROPERTY, "false"); +// System.setProperty(Config.KUBERNETES_HTTP2_DISABLE, "true"); +// } +// +// @AfterEach +// void afterEach() { +// mockClient.close(); +// } +// +// @Test +// void getInstancesShouldBeAbleToHandleEndpointsSingleAddress() { +// Map labels = Map.of("l", "v"); +// +// Endpoints endPoint = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace("test") +// .withLabels(labels).endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef() +// .withUid("10").endTargetRef().endAddress().addNewPort("http", "http_tcp", 80, "TCP").endSubset() +// .build(); +// +// mockClient.endpoints().inNamespace("test").resource(endPoint).create(); +// +// Service service = new ServiceBuilder().withNewMetadata().withName("endpoint").withNamespace("test") +// .withLabels(labels).endMetadata().build(); +// +// mockClient.services().inNamespace("test").resource(service).create(); +// +// DiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, +// KubernetesDiscoveryProperties.DEFAULT, KubernetesClient::services, null, +// new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT)); +// +// List instances = discoveryClient.getInstances("endpoint"); +// +// assertThat(instances).hasSize(1).filteredOn(s -> s.getHost().equals("ip1") && !s.isSecure()).hasSize(1) +// .filteredOn(s -> s.getInstanceId().equals("10")).hasSize(1); +// } +// +// @Test +// void getInstancesShouldBeAbleToHandleEndpointsSingleAddressAndMultiplePorts() { +// Map labels = Map.of("l2", "v2"); +// +// Endpoints endPoint = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace("test") +// .withLabels(labels).endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef() +// .withUid("20").endTargetRef().endAddress().addNewPort("mgmt", "mgmt_tcp", 900, "TCP") +// .addNewPort("http", "http_tcp", 80, "TCP").endSubset().build(); +// +// mockClient.endpoints().inNamespace("test").resource(endPoint).create(); +// +// Service service = new ServiceBuilder().withNewMetadata().withName("endpoint").withNamespace("test") +// .withLabels(labels).withAnnotations(labels).endMetadata().build(); +// +// mockClient.services().inNamespace("test").resource(service).create(); +// +// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, +// false, null, Set.of(), labels, "http_tcp", Metadata.DEFAULT, 0, true); +// +// DiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, properties, +// KubernetesClient::services, null, new ServicePortSecureResolver(properties)); +// +// List instances = discoveryClient.getInstances("endpoint"); +// +// assertThat(instances).hasSize(1).filteredOn(s -> s.getHost().equals("ip1") && !s.isSecure()).hasSize(1) +// .filteredOn(s -> s.getInstanceId().equals("20")).hasSize(1).filteredOn(s -> 80 == s.getPort()) +// .hasSize(1); +// } +// +// @Test +// void getEndPointsListTest() { +// Map labels = Map.of("l", "v"); +// +// Endpoints endPoint = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace("test") +// .withLabels(labels).endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef() +// .withUid("30").endTargetRef().endAddress().addNewPort("http", "http_tcp", 80, "TCP").endSubset() +// .build(); +// +// mockClient.endpoints().inNamespace("test").resource(endPoint).create(); +// +// Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, +// KubernetesDiscoveryProperties.DEFAULT, KubernetesClient::services, null, +// new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT)); +// +// List result_endpoints = discoveryClient.getEndPointsList("endpoint"); +// +// assertThat(result_endpoints).hasSize(1); +// } +// +// @Test +// void getEndPointsListTestAllNamespaces() { +// +// String namespace1 = "ns1"; +// String namespace2 = "ns2"; +// +// Endpoints endPoint1 = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace(namespace1) +// .endMetadata().build(); +// +// Endpoints endPoint2 = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace(namespace2) +// .endMetadata().build(); +// +// mockClient.endpoints().inNamespace(namespace1).resource(endPoint1).create(); +// mockClient.endpoints().inNamespace(namespace2).resource(endPoint2).create(); +// +// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, +// false, null, Set.of(), Map.of(), null, KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, false); +// +// Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, properties, +// KubernetesClient::services, null, new ServicePortSecureResolver(properties)); +// +// List result_endpoints = discoveryClient.getEndPointsList("endpoint"); +// +// assertThat(result_endpoints).hasSize(2); +// } +// +// @Test +// void getEndPointsListShouldHandleNamespaces() { +// +// String namespace1 = "ns1"; +// String namespace2 = "ns2"; +// String namespace3 = "ns3"; +// +// Endpoints endPoint1 = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace(namespace1) +// .endMetadata().build(); +// Endpoints endPoint2 = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace(namespace2) +// .endMetadata().build(); +// Endpoints endPoint3 = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace(namespace3) +// .endMetadata().build(); +// +// mockClient.endpoints().inNamespace(namespace1).resource(endPoint1).create(); +// mockClient.endpoints().inNamespace(namespace2).resource(endPoint2).create(); +// mockClient.endpoints().inNamespace(namespace3).resource(endPoint3).create(); +// +// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, +// Set.of(namespace1, namespace3), true, 60, false, null, Set.of(), Map.of(), null, +// KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, false); +// +// Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, properties, +// KubernetesClient::services, null, new ServicePortSecureResolver(properties)); +// +// List result_endpoints = discoveryClient.getEndPointsList("endpoint"); +// +// assertThat(result_endpoints).hasSize(2); +// assertThat(result_endpoints.stream().map(Endpoints::getMetadata).map(ObjectMeta::getNamespace) +// .collect(Collectors.toList())).containsOnly(namespace1, namespace3); +// } +// +// @Test +// void getInstancesShouldBeAbleToHandleEndpointsMultipleAddresses() { +// Map labels = Map.of("l1", "v1"); +// +// Endpoints endPoint = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace("test") +// .withLabels(labels).endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef() +// .withUid("40").endTargetRef().endAddress().addNewAddress().withIp("ip2").withNewTargetRef() +// .withUid("50").endTargetRef().endAddress().addNewPort("https", "https_tcp", 443, "TCP").endSubset() +// .build(); +// +// mockClient.endpoints().inNamespace("test").resource(endPoint).create(); +// +// Service service = new ServiceBuilder().withNewMetadata().withName("endpoint").withNamespace("test") +// .withLabels(labels).endMetadata().build(); +// +// mockClient.services().inNamespace("test").resource(service).create(); +// +// Metadata metadata = new Metadata(false, null, false, null, true, "port."); +// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, +// false, null, Set.of(443, 8443), labels, null, metadata, 0, true); +// +// DiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, properties, +// KubernetesClient::services, null, new ServicePortSecureResolver(properties)); +// +// List instances = discoveryClient.getInstances("endpoint"); +// +// assertThat(instances).hasSize(2).filteredOn(ServiceInstance::isSecure).extracting(ServiceInstance::getHost) +// .containsOnly("ip1", "ip2"); +// } +// +// @Test +// void getServicesShouldReturnAllServicesWhenNoLabelsAreAppliedToTheClient() { +// +// Map service1Labels = Collections.singletonMap("label", "value"); +// Service service1 = new ServiceBuilder().withNewMetadata().withName("s1").withNamespace("test") +// .withLabels(service1Labels).endMetadata().build(); +// +// Map service2Labels = Map.of("label", "value", "label2", "value2"); +// Service service2 = new ServiceBuilder().withNewMetadata().withName("s2").withNamespace("test") +// .withLabels(service2Labels).endMetadata().build(); +// +// Service service3 = new ServiceBuilder().withNewMetadata().withName("s3").withNamespace("test").endMetadata() +// .build(); +// mockClient.services().inNamespace("test").resource(service1).create(); +// mockClient.services().inNamespace("test").resource(service2).create(); +// mockClient.services().inNamespace("test").resource(service3).create(); +// +// DiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, +// KubernetesDiscoveryProperties.DEFAULT, KubernetesClient::services, null, +// new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT)); +// +// List services = discoveryClient.getServices(); +// +// assertThat(services).containsOnly("s1", "s2", "s3"); +// } +// +// @Test +// void getServicesShouldReturnOnlyMatchingServicesWhenLabelsAreAppliedToTheClient() { +// +// Map service1Labels = Collections.singletonMap("label", "value"); +// Service service1 = new ServiceBuilder().withNewMetadata().withName("s1").withNamespace("test") +// .withLabels(service1Labels).endMetadata().build(); +// +// Map service2Labels = Map.of("label", "value", "label2", "value2"); +// Service service2 = new ServiceBuilder().withNewMetadata().withName("s2").withNamespace("test") +// .withLabels(service2Labels).endMetadata().build(); +// +// mockClient.services().inNamespace("test").resource(service1).create(); +// mockClient.services().inNamespace("test").resource(service2).create(); +// +// DiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, +// KubernetesDiscoveryProperties.DEFAULT, +// client -> client.services().withLabels(Collections.singletonMap("label", "value")), null, +// new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT)); +// +// List services = discoveryClient.getServices(); +// +// assertThat(services).containsOnly("s1", "s2"); +// } +// +// @Test +// void getServicesShouldReturnServicesInNamespaces() { +// +// String nameSpace1 = "ns1"; +// String nameSpace2 = "ns2"; +// String nameSpace3 = "ns3"; +// +// Service service1 = new ServiceBuilder().withNewMetadata().withName("s1").withNamespace(nameSpace1).endMetadata() +// .build(); +// +// Service service2 = new ServiceBuilder().withNewMetadata().withName("s2").withNamespace(nameSpace2).endMetadata() +// .build(); +// +// Service service3 = new ServiceBuilder().withNewMetadata().withName("s3").withNamespace(nameSpace3).endMetadata() +// .build(); +// +// mockClient.services().inNamespace(nameSpace1).resource(service1).create(); +// mockClient.services().inNamespace(nameSpace2).resource(service2).create(); +// mockClient.services().inNamespace(nameSpace3).resource(service3).create(); +// +// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, +// Set.of(nameSpace1, nameSpace2), true, 60, false, null, Set.of(), Map.of(), null, +// KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, false); +// +// DiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, properties, +// KubernetesClient::services, null, new ServicePortSecureResolver(properties)); +// +// List services = discoveryClient.getServices(); +// +// assertThat(services).containsOnly("s1", "s2"); +// } +// +// @Test +// void getInstancesShouldBeAbleToHandleEndpointsFromMultipleNamespaces() { +// Endpoints endPoints1 = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace("test") +// .endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef().withUid("60") +// .endTargetRef().endAddress().addNewPort("http", "http_tcp", 80, "TCP").endSubset().build(); +// +// Endpoints endPoints2 = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace("test2") +// .endMetadata().addNewSubset().addNewAddress().withIp("ip2").withNewTargetRef().withUid("70") +// .endTargetRef().endAddress().addNewPort("http", "http_tcp", 80, "TCP").endSubset().build(); +// +// mockClient.endpoints().inNamespace("test").resource(endPoints1).create(); +// mockClient.endpoints().inNamespace("test2").resource(endPoints2).create(); +// +// Service service1 = new ServiceBuilder().withNewMetadata().withName("endpoint").withNamespace("test") +// .withLabels(Collections.singletonMap("l", "v")).endMetadata().build(); +// +// Service service2 = new ServiceBuilder().withNewMetadata().withName("endpoint").withNamespace("test2") +// .withLabels(Collections.singletonMap("l", "v")).endMetadata().build(); +// +// mockClient.services().inNamespace("test").resource(service1).create(); +// mockClient.services().inNamespace("test2").resource(service2).create(); +// +// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, +// false, null, Set.of(), Map.of(), null, Metadata.DEFAULT, 0, true); +// +// DiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, properties, +// KubernetesClient::services, null, new ServicePortSecureResolver(properties)); +// +// List instances = discoveryClient.getInstances("endpoint"); +// +// assertThat(instances).hasSize(2); +// assertThat(instances).filteredOn(s -> s.getHost().equals("ip1") && !s.isSecure()).hasSize(1); +// assertThat(instances).filteredOn(s -> s.getHost().equals("ip2") && !s.isSecure()).hasSize(1); +// assertThat(instances).filteredOn(s -> s.getServiceId().contains("endpoint") +// && ((KubernetesServiceInstance) s).getNamespace().equals("test")).hasSize(1); +// assertThat(instances).filteredOn(s -> s.getServiceId().contains("endpoint") +// && ((KubernetesServiceInstance) s).getNamespace().equals("test2")).hasSize(1); +// assertThat(instances).filteredOn(s -> s.getInstanceId().equals("60")).hasSize(1); +// assertThat(instances).filteredOn(s -> s.getInstanceId().equals("70")).hasSize(1); +// } +// +// @Test +// void instanceWithoutPortsShouldBeSkipped() { +// Endpoints endPoint = new EndpointsBuilder().withNewMetadata().withName("endpoint1").withNamespace("test") +// .withLabels(Collections.emptyMap()).endMetadata().build(); +// +// mockClient.endpoints().inNamespace("test").resource(endPoint).create(); +// +// Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, +// KubernetesDiscoveryProperties.DEFAULT, KubernetesClient::services, null, +// new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT)); +// +// List instances = discoveryClient.getInstances("endpoint1"); +// +// assertThat(instances).isEmpty(); +// } +// +// @Test +// void getInstancesShouldBeAbleToHandleEndpointsSingleAddressAndMultiplePortsUsingPrimaryPortNameLabel() { +// Map labels = Map.of("primary-port-name", "https"); +// +// Endpoints endPoint1 = new EndpointsBuilder().withNewMetadata().withName("endpoint2").withNamespace("test") +// .withLabels(labels).endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef() +// .withUid("80").endTargetRef().endAddress().addNewPort("http", "https", 443, "TCP") +// .addNewPort("http", "http", 80, "TCP").endSubset().build(); +// +// mockClient.endpoints().inNamespace("test").resource(endPoint1).create(); +// +// Service service = new ServiceBuilder().withNewMetadata().withName("endpoint2").withNamespace("test") +// .withLabels(labels).withAnnotations(labels).endMetadata().build(); +// +// mockClient.services().inNamespace("test").resource(service).create(); +// +// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, +// false, null, Set.of(443, 8443), Map.of(), null, Metadata.DEFAULT, 0, true); +// +// DiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, properties, +// KubernetesClient::services, null, new ServicePortSecureResolver(properties)); +// +// List instances = discoveryClient.getInstances("endpoint2"); +// +// assertThat(instances).hasSize(1).filteredOn(s -> s.getHost().equals("ip1") && s.isSecure()).hasSize(1) +// .filteredOn(s -> s.getInstanceId().equals("80")).hasSize(1).filteredOn(s -> 443 == s.getPort()) +// .hasSize(1); +// } +// +// @Test +// void instanceWithMultiplePortsAndMisconfiguredPrimaryPortNameInLabelWithoutFallbackShouldLogWarning() { +// Map labels = Map.of("primary-port-name", "oops"); +// +// Endpoints endPoint1 = new EndpointsBuilder().withNewMetadata().withName("endpoint3").withNamespace("test") +// .withLabels(labels).endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef() +// .withUid("90").endTargetRef().endAddress().addNewPort("http", "https1", 443, "TCP") +// .addNewPort("http", "https2", 8443, "TCP").addNewPort("http", "http1", 80, "TCP") +// .addNewPort("http", "http2", 8080, "TCP").endSubset().build(); +// +// mockClient.endpoints().inNamespace("test").resource(endPoint1).create(); +// +// Service service = new ServiceBuilder().withNewMetadata().withName("endpoint3").withNamespace("test") +// .withLabels(labels).withAnnotations(labels).endMetadata().build(); +// +// mockClient.services().inNamespace("test").resource(service).create(); +// +// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, +// false, null, Set.of(443, 8443), Map.of(), null, Metadata.DEFAULT, 0, true); +// +// DiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, properties, +// KubernetesClient::services, null, new ServicePortSecureResolver(properties)); +// +// List instances = discoveryClient.getInstances("endpoint3"); +// +// assertThat(instances).hasSize(1).filteredOn(s -> s.getHost().equals("ip1") && s.isSecure()).hasSize(1) +// .filteredOn(s -> s.getInstanceId().equals("90")).hasSize(1).filteredOn(s -> 443 == s.getPort()) +// .hasSize(1); +// } +// +// @Test +// void instanceWithMultiplePortsAndMisconfiguredGenericPrimaryPortNameWithoutFallbackShouldLogWarning() { +// Map labels = Map.of(); +// +// Endpoints endPoint1 = new EndpointsBuilder().withNewMetadata().withName("endpoint4").withNamespace("test") +// .withLabels(labels).endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef() +// .withUid("100").endTargetRef().endAddress().addNewPort("http", "https1", 443, "TCP") +// .addNewPort("http", "https2", 8443, "TCP").addNewPort("http", "http1", 80, "TCP") +// .addNewPort("http", "http2", 8080, "TCP").endSubset().build(); +// +// mockClient.endpoints().inNamespace("test").resource(endPoint1).create(); +// +// Service service = new ServiceBuilder().withNewMetadata().withName("endpoint4").withNamespace("test") +// .withLabels(labels).withAnnotations(labels).endMetadata().build(); +// +// mockClient.services().inNamespace("test").resource(service).create(); +// +// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, +// false, null, Set.of(443, 8443), Map.of(), "oops", Metadata.DEFAULT, 0, true); +// +// DiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, properties, +// KubernetesClient::services, null, new ServicePortSecureResolver(properties)); +// +// List instances = discoveryClient.getInstances("endpoint4"); +// +// assertThat(instances).hasSize(1).filteredOn(s -> s.getHost().equals("ip1") && s.isSecure()).hasSize(1) +// .filteredOn(s -> s.getInstanceId().equals("100")).hasSize(1).filteredOn(s -> 443 == s.getPort()) +// .hasSize(1); +// } +// +// @Test +// void instanceWithMultiplePortsAndWithoutPrimaryPortNameSpecifiedShouldFallBackToHttps() { +// Map labels = Map.of(); +// +// Endpoints endPoint1 = new EndpointsBuilder().withNewMetadata().withName("endpoint5").withNamespace("test") +// .withLabels(labels).endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef() +// .withUid("110").endTargetRef().endAddress().addNewPort("http", "https", 443, "TCP") +// .addNewPort("http", "http", 80, "TCP").endSubset().build(); +// +// mockClient.endpoints().inNamespace("test").resource(endPoint1).create(); +// +// Service service = new ServiceBuilder().withNewMetadata().withName("endpoint5").withNamespace("test") +// .withLabels(labels).withAnnotations(labels).endMetadata().build(); +// +// mockClient.services().inNamespace("test").resource(service).create(); +// +// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, +// false, null, Set.of(443, 8443), Map.of(), null, Metadata.DEFAULT, 0, true); +// +// DiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, properties, +// KubernetesClient::services, null, new ServicePortSecureResolver(properties)); +// +// List instances = discoveryClient.getInstances("endpoint5"); +// +// assertThat(instances).hasSize(1).filteredOn(s -> s.getHost().equals("ip1") && s.isSecure()).hasSize(1) +// .filteredOn(s -> s.getInstanceId().equals("110")).hasSize(1).filteredOn(s -> 443 == s.getPort()) +// .hasSize(1); +// } +// +// @Test +// void instanceWithMultiplePortsAndWithoutPrimaryPortNameSpecifiedOrHttpsPortShouldFallBackToHttp() { +// Map labels = Map.of(); +// +// Endpoints endPoint1 = new EndpointsBuilder().withNewMetadata().withName("endpoint5").withNamespace("test") +// .withLabels(labels).endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef() +// .withUid("120").endTargetRef().endAddress().addNewPort("http", "https1", 443, "TCP") +// .addNewPort("http", "https2", 8443, "TCP").addNewPort("http", "http", 80, "TCP").endSubset().build(); +// +// mockClient.endpoints().inNamespace("test").resource(endPoint1).create(); +// +// Service service = new ServiceBuilder().withNewMetadata().withName("endpoint5").withNamespace("test") +// .withLabels(labels).withAnnotations(labels).endMetadata().build(); +// +// mockClient.services().inNamespace("test").resource(service).create(); +// +// DiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, +// KubernetesDiscoveryProperties.DEFAULT, KubernetesClient::services, null, +// new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT)); +// +// List instances = discoveryClient.getInstances("endpoint5"); +// +// assertThat(instances).hasSize(1).filteredOn(s -> s.getHost().equals("ip1") && !s.isSecure()).hasSize(1) +// .filteredOn(s -> s.getInstanceId().equals("120")).hasSize(1).filteredOn(s -> 80 == s.getPort()) +// .hasSize(1); +// } +// +// @Test +// void instanceWithMultiplePortsAndWithoutPrimaryPortNameSpecifiedShouldLogWarning() { +// Map labels = Map.of(); +// +// Endpoints endPoint1 = new EndpointsBuilder().withNewMetadata().withName("endpoint5").withNamespace("test") +// .withLabels(labels).endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef() +// .withUid("130").endTargetRef().endAddress().addNewPort("http", "https", 443, "TCP") +// .addNewPort("http", "http", 80, "TCP").endSubset().build(); +// +// mockClient.endpoints().inNamespace("test").resource(endPoint1).create(); +// +// Service service = new ServiceBuilder().withNewMetadata().withName("endpoint5").withNamespace("test") +// .withLabels(labels).withAnnotations(labels).endMetadata().build(); +// +// mockClient.services().inNamespace("test").resource(service).create(); +// +// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, +// true, null, Set.of(443, 8443), Map.of(), null, Metadata.DEFAULT, 0, true); +// +// DiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, properties, +// KubernetesClient::services, null, new ServicePortSecureResolver(properties)); +// +// List instances = discoveryClient.getInstances("endpoint5"); +// +// // We're returning the first discovered port to not change previous behaviour +// assertThat(instances).hasSize(1).filteredOn(s -> s.getHost().equals("ip1") && s.isSecure()).hasSize(1) +// .filteredOn(s -> s.getInstanceId().equals("130")).hasSize(1).filteredOn(s -> 443 == s.getPort()) +// .hasSize(1); +// } } diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientTests.java index 1252746f98..c58d9984cd 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientTests.java @@ -77,7 +77,7 @@ void testAllNamespacesEmpty(CapturedOutput output) { KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); - KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null); + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties, null, null, null); List result = discoveryClient.getEndPointsList("serviceId"); Assertions.assertEquals(result.size(), 0); Assertions.assertTrue(output.getOut().contains("discovering endpoints in all namespaces")); @@ -102,7 +102,7 @@ void testAllNamespacesSingleEndpointsMatchExactLabels(CapturedOutput output) { KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); - KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null); + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties, null, null, null); List result = discoveryClient.getEndPointsList("blue-service"); Assertions.assertEquals(result.size(), 1); Assertions.assertTrue(output.getOut().contains("discovering endpoints in all namespaces")); @@ -127,7 +127,7 @@ void testAllNamespacesSingleEndpointsMatchPartialLabels(CapturedOutput output) { KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); - KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null); + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties, null, null, null); List result = discoveryClient.getEndPointsList("blue-service"); Assertions.assertEquals(result.size(), 1); Assertions.assertTrue(output.getOut().contains("discovering endpoints in all namespaces")); @@ -152,7 +152,7 @@ void testAllNamespacesSingleEndpointsNameMatchesLabelsDont(CapturedOutput output KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); - KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null); + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties, null, null, null); List result = discoveryClient.getEndPointsList("blue-service"); Assertions.assertEquals(result.size(), 0); Assertions.assertTrue(output.getOut().contains("discovering endpoints in all namespaces")); @@ -178,7 +178,7 @@ void testAllNamespacesTwoEndpointsOneMatches(CapturedOutput output) { KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); - KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null); + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties, null, null, null); List result = discoveryClient.getEndPointsList("service-one"); Assertions.assertEquals(result.size(), 1); Assertions.assertTrue(output.getOut().contains("discovering endpoints in all namespaces")); @@ -204,7 +204,7 @@ void testAllNamespacesTwoEndpointsInDifferentNamespaces(CapturedOutput output) { KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); - KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null); + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties, null, null, null); List result = discoveryClient.getEndPointsList("service-one"); Assertions.assertEquals(result.size(), 2); Assertions.assertEquals( @@ -228,7 +228,7 @@ void testClientNamespaceEmpty(CapturedOutput output) { KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); - KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null); + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties, null, null, null); List result = discoveryClient.getEndPointsList("serviceId"); Assertions.assertEquals(result.size(), 0); Assertions.assertTrue(output.getOut().contains("discovering endpoints in namespace : test")); @@ -253,7 +253,7 @@ void testClientNamespaceSingleEndpointsMatchExactLabels(CapturedOutput output) { KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); - KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null); + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties, null, null, null); List result = discoveryClient.getEndPointsList("blue-service"); Assertions.assertEquals(result.size(), 1); Assertions.assertTrue(output.getOut().contains("discovering endpoints in namespace : test")); @@ -278,7 +278,7 @@ void testClientNamespaceSingleEndpointsMatchPartialLabels(CapturedOutput output) KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); - KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null); + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties, null, null, null); List result = discoveryClient.getEndPointsList("blue-service"); Assertions.assertEquals(result.size(), 1); Assertions.assertTrue(output.getOut().contains("discovering endpoints in namespace : test")); @@ -303,7 +303,7 @@ void testClientNamespaceSingleEndpointsNameMatchesLabelsDont(CapturedOutput outp KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); - KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null); + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties, null, null, null); List result = discoveryClient.getEndPointsList("blue-service"); Assertions.assertEquals(result.size(), 0); Assertions.assertTrue(output.getOut().contains("discovering endpoints in namespace : test")); @@ -329,7 +329,7 @@ void testClientNamespaceTwoEndpointsOneMatches(CapturedOutput output) { KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); - KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null); + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties, null, null, null); List result = discoveryClient.getEndPointsList("service-one"); Assertions.assertEquals(result.size(), 1); Assertions.assertTrue(output.getOut().contains("discovering endpoints in namespace : test")); @@ -355,7 +355,7 @@ void testClientNamespaceTwoEndpointsInDifferentNamespaces(CapturedOutput output) KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); - KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null); + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties, null, null, null); List result = discoveryClient.getEndPointsList("service-one"); Assertions.assertEquals(result.size(), 1); Assertions.assertEquals( @@ -379,7 +379,7 @@ void testSelectiveNamespacesEmpty(CapturedOutput output) { KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); - KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null); + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties, null, null, null); List result = discoveryClient.getEndPointsList("serviceId"); Assertions.assertEquals(result.size(), 0); Assertions.assertTrue(output.getOut().contains("discovering endpoints in namespaces : [test]")); @@ -404,7 +404,7 @@ void testSelectiveNamespacesSingleEndpointsMatchExactLabels(CapturedOutput outpu KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); - KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null); + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties, null, null, null); List result = discoveryClient.getEndPointsList("blue-service"); Assertions.assertEquals(result.size(), 1); Assertions.assertTrue(output.getOut().contains("discovering endpoints in namespaces : [test]")); @@ -431,7 +431,7 @@ void testSelectiveNamespacesMultipleNamespacesSingleMatch(CapturedOutput output) KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); - KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null); + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties, null, null, null); List result = discoveryClient.getEndPointsList("blue-service"); Assertions.assertEquals(result.size(), 1); Assertions.assertEquals(result.get(0).getMetadata().getLabels(), Map.of("color", "blue", "shape", "round")); @@ -461,7 +461,7 @@ void testSelectiveNamespacesMultipleNamespacesAllMatch(CapturedOutput output) { KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); - KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null); + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties, null, null, null); List result = discoveryClient.getEndPointsList("blue-service"); Assertions.assertEquals(result.size(), 2); Assertions.assertTrue(output.getOut().contains("discovering endpoints in namespaces : " + namespacesAsString)); diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java index 9d41b95f8c..d1c35f3fbc 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java @@ -54,7 +54,7 @@ class KubernetesDiscoveryClientUtilsTests { void testSubsetsFromEndpointsEmptySubsets() { Endpoints endpoints = new EndpointsBuilder() .withMetadata(new ObjectMetaBuilder().withNamespace("non-default").build()).build(); - EndpointSubsetNS result = KubernetesDiscoveryClientUtils.subsetsFromEndpoints(endpoints); + EndpointSubsetNS result = Fabric8KubernetesDiscoveryClientUtils.subsetsFromEndpoints(endpoints); Assertions.assertNotNull(result); Assertions.assertEquals(result.endpointSubset(), List.of()); Assertions.assertEquals(result.namespace(), "non-default"); @@ -67,7 +67,7 @@ void testSubsetsFromEndpointsNonEmptySubsets() { .withSubsets( new EndpointSubsetBuilder().withPorts(new EndpointPortBuilder().withPort(8080).build()).build()) .build(); - EndpointSubsetNS result = KubernetesDiscoveryClientUtils.subsetsFromEndpoints(endpoints); + EndpointSubsetNS result = Fabric8KubernetesDiscoveryClientUtils.subsetsFromEndpoints(endpoints); Assertions.assertNotNull(result); Assertions.assertEquals(result.endpointSubset().size(), 1); Assertions.assertEquals(result.endpointSubset().get(0).getPorts().get(0).getPort(), 8080); @@ -87,7 +87,7 @@ void testPrimaryPortNameNotFound(CapturedOutput output) { KubernetesDiscoveryProperties properties = KubernetesDiscoveryProperties.DEFAULT; Service service = new ServiceBuilder().withMetadata(new ObjectMeta()).build(); - String result = KubernetesDiscoveryClientUtils.primaryPortName(properties, service, "abc"); + String result = Fabric8KubernetesDiscoveryClientUtils.primaryPortName(properties, service, "abc"); Assertions.assertNull(result); Assertions.assertTrue(output.getOut().contains( "did not find a primary-port-name in neither properties nor service labels for service with ID : abc")); @@ -108,7 +108,7 @@ void testPrimaryPortNameFoundInProperties(CapturedOutput output) { true, "", Set.of(), Map.of(), primaryPortName, null, 0, false); Service service = new ServiceBuilder().withMetadata(new ObjectMeta()).build(); - String result = KubernetesDiscoveryClientUtils.primaryPortName(properties, service, "abc"); + String result = Fabric8KubernetesDiscoveryClientUtils.primaryPortName(properties, service, "abc"); Assertions.assertNotNull(result); Assertions.assertEquals(result, primaryPortName); Assertions.assertTrue(output.getOut().contains("will use primaryPortName : https for service with ID = abc")); @@ -128,7 +128,7 @@ void testPrimaryPortNameFoundInLabels(CapturedOutput output) { KubernetesDiscoveryProperties properties = KubernetesDiscoveryProperties.DEFAULT; Service service = new ServiceBuilder().withMetadata(new ObjectMetaBuilder().withLabels(labels).build()).build(); - String result = KubernetesDiscoveryClientUtils.primaryPortName(properties, service, "abc"); + String result = Fabric8KubernetesDiscoveryClientUtils.primaryPortName(properties, service, "abc"); Assertions.assertNotNull(result); Assertions.assertEquals(result, "https"); Assertions.assertTrue(output.getOut().contains("will use primaryPortName : https for service with ID = abc")); @@ -150,7 +150,7 @@ void testPrimaryPortNameFoundInBothPropertiesAndLabels(CapturedOutput output) { true, "", Set.of(), Map.of(), primaryPortName, null, 0, false); Service service = new ServiceBuilder().withMetadata(new ObjectMetaBuilder().withLabels(labels).build()).build(); - String result = KubernetesDiscoveryClientUtils.primaryPortName(properties, service, "abc"); + String result = Fabric8KubernetesDiscoveryClientUtils.primaryPortName(properties, service, "abc"); Assertions.assertNotNull(result); Assertions.assertEquals(result, "http"); Assertions.assertTrue(output.getOut().contains("will use primaryPortName : http for service with ID = abc")); @@ -169,7 +169,7 @@ void testEndpointsPortSinglePort(CapturedOutput output) { KubernetesDiscoveryProperties properties = KubernetesDiscoveryProperties.DEFAULT; Service service = new ServiceBuilder().build(); - Integer port = KubernetesDiscoveryClientUtils.endpointsPort(endpointSubset, serviceId, properties, service); + Integer port = Fabric8KubernetesDiscoveryClientUtils.endpointsPort(endpointSubset, serviceId, properties, service); Assertions.assertEquals(port, 8080); Assertions.assertTrue(output.getOut().contains("endpoint ports has a single entry, using port : 8080")); } @@ -189,7 +189,7 @@ void testEndpointsPortNullPrimaryPortName(CapturedOutput output) { KubernetesDiscoveryProperties properties = KubernetesDiscoveryProperties.DEFAULT; Service service = new ServiceBuilder().withMetadata(new ObjectMeta()).build(); - Integer port = KubernetesDiscoveryClientUtils.endpointsPort(endpointSubset, serviceId, properties, service); + Integer port = Fabric8KubernetesDiscoveryClientUtils.endpointsPort(endpointSubset, serviceId, properties, service); Assertions.assertEquals(port, 8080); Assertions.assertTrue(output.getOut().contains( "did not find a primary-port-name in neither properties nor service labels for service with ID : spring-k8s")); @@ -223,7 +223,7 @@ void testEndpointsPortPrimaryPortNameIsPresentButNotFound(CapturedOutput output) Service service = new ServiceBuilder().withMetadata(new ObjectMeta()).build(); - Integer port = KubernetesDiscoveryClientUtils.endpointsPort(endpointSubset, serviceId, properties, service); + Integer port = Fabric8KubernetesDiscoveryClientUtils.endpointsPort(endpointSubset, serviceId, properties, service); Assertions.assertEquals(port, 8080); Assertions.assertTrue( output.getOut().contains("will use primaryPortName : three for service with ID = spring-k8s")); @@ -257,7 +257,7 @@ void testEndpointsPortPrimaryPortNameFound(CapturedOutput output) { Service service = new ServiceBuilder().withMetadata(new ObjectMeta()).build(); - Integer port = KubernetesDiscoveryClientUtils.endpointsPort(endpointSubset, serviceId, properties, service); + Integer port = Fabric8KubernetesDiscoveryClientUtils.endpointsPort(endpointSubset, serviceId, properties, service); Assertions.assertEquals(port, 8081); Assertions.assertTrue( output.getOut().contains("will use primaryPortName : two for service with ID = spring-k8s")); @@ -286,7 +286,7 @@ void testEndpointsPortPrimaryPortHttps(CapturedOutput output) { Service service = new ServiceBuilder().withMetadata(new ObjectMeta()).build(); - Integer port = KubernetesDiscoveryClientUtils.endpointsPort(endpointSubset, serviceId, properties, service); + Integer port = Fabric8KubernetesDiscoveryClientUtils.endpointsPort(endpointSubset, serviceId, properties, service); Assertions.assertEquals(port, 8082); Assertions.assertTrue( output.getOut().contains("will use primaryPortName : three for service with ID = spring-k8s")); @@ -316,7 +316,7 @@ void testEndpointsPortPrimaryPortHttp(CapturedOutput output) { Service service = new ServiceBuilder().withMetadata(new ObjectMeta()).build(); - Integer port = KubernetesDiscoveryClientUtils.endpointsPort(endpointSubset, serviceId, properties, service); + Integer port = Fabric8KubernetesDiscoveryClientUtils.endpointsPort(endpointSubset, serviceId, properties, service); Assertions.assertEquals(port, 8082); Assertions.assertTrue( output.getOut().contains("will use primaryPortName : three for service with ID = spring-k8s")); @@ -348,7 +348,7 @@ void testServiceMetadataEmpty() { true, "", Set.of(), Map.of(), "", metadata, 0, false); Service service = new ServiceBuilder().build(); - Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, + Map result = Fabric8KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, List.of(), namespace); Assertions.assertEquals(result.size(), 1); Assertions.assertEquals(result, Map.of("k8s_namespace", "default")); @@ -378,7 +378,7 @@ void testServiceMetadataAddLabelsNoPrefix(CapturedOutput output) { Service service = new ServiceBuilder() .withMetadata(new ObjectMetaBuilder().withLabels(Map.of("a", "b")).build()).build(); - Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, + Map result = Fabric8KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, List.of(), namespace); Assertions.assertEquals(result.size(), 2); Assertions.assertEquals(result, Map.of("a", "b", "k8s_namespace", "default")); @@ -411,7 +411,7 @@ void testServiceMetadataAddLabelsWithPrefix(CapturedOutput output) { Service service = new ServiceBuilder() .withMetadata(new ObjectMetaBuilder().withLabels(Map.of("a", "b", "c", "d")).build()).build(); - Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, + Map result = Fabric8KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, List.of(), namespace); Assertions.assertEquals(result.size(), 3); Assertions.assertEquals(result, Map.of("prefix-a", "b", "prefix-c", "d", "k8s_namespace", "default")); @@ -446,7 +446,7 @@ void testServiceMetadataAddAnnotationsNoPrefix(CapturedOutput output) { new ObjectMetaBuilder().withAnnotations(Map.of("aa", "bb")).withLabels(Map.of("a", "b")).build()) .build(); - Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, + Map result = Fabric8KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, List.of(), namespace); Assertions.assertEquals(result.size(), 2); Assertions.assertEquals(result, Map.of("aa", "bb", "k8s_namespace", "default")); @@ -478,7 +478,7 @@ void testServiceMetadataAddAnnotationsWithPrefix(CapturedOutput output) { Service service = new ServiceBuilder().withMetadata(new ObjectMetaBuilder() .withAnnotations(Map.of("aa", "bb", "cc", "dd")).withLabels(Map.of("a", "b")).build()).build(); - Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, + Map result = Fabric8KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, List.of(), namespace); Assertions.assertEquals(result.size(), 3); Assertions.assertEquals(result, Map.of("prefix-aa", "bb", "prefix-cc", "dd", "k8s_namespace", "default")); @@ -513,7 +513,7 @@ void testServiceMetadataAddLabelsAndAnnotationsWithPrefix(CapturedOutput output) .withAnnotations(Map.of("aa", "bb", "cc", "dd")).withLabels(Map.of("a", "b", "c", "d")).build()) .build(); - Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, + Map result = Fabric8KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, List.of(), namespace); Assertions.assertEquals(result.size(), 5); Assertions.assertEquals(result, Map.of("annotation-aa", "bb", "annotation-cc", "dd", "label-a", "b", "label-c", @@ -558,7 +558,7 @@ void testServiceMetadataAddPortsWithoutPrefix(CapturedOutput output) { new EndpointSubsetBuilder() .withPorts(new EndpointPortBuilder().withPort(8080).withName("https").build()).build()); - Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, + Map result = Fabric8KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, endpointSubsets, namespace); Assertions.assertEquals(result.size(), 2); Assertions.assertEquals(result, Map.of("https", "8080", "k8s_namespace", "default")); @@ -595,7 +595,7 @@ void testServiceMetadataAddPortsWithPrefix(CapturedOutput output) { new EndpointSubsetBuilder() .withPorts(new EndpointPortBuilder().withPort(8080).withName("https").build()).build()); - Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, + Map result = Fabric8KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, endpointSubsets, namespace); Assertions.assertEquals(result.size(), 3); Assertions.assertEquals(result, @@ -616,7 +616,7 @@ void testEmptyAddresses() { KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, includeNotReadyAddresses, "", Set.of(), Map.of(), "", null, 0, false); EndpointSubset endpointSubset = new EndpointSubsetBuilder().build(); - List addresses = KubernetesDiscoveryClientUtils.addresses(endpointSubset, properties); + List addresses = Fabric8KubernetesDiscoveryClientUtils.addresses(endpointSubset, properties); Assertions.assertEquals(addresses.size(), 0); } @@ -635,7 +635,7 @@ void testReadyAddressesOnly() { .withAddresses(new EndpointAddressBuilder().withHostname("one").build(), new EndpointAddressBuilder().withHostname("two").build()) .build(); - List addresses = KubernetesDiscoveryClientUtils.addresses(endpointSubset, properties); + List addresses = Fabric8KubernetesDiscoveryClientUtils.addresses(endpointSubset, properties); Assertions.assertEquals(addresses.size(), 2); } @@ -654,7 +654,7 @@ void testReadyAddressesTakenNotReadyAddressesNotTaken() { .withAddresses(new EndpointAddressBuilder().withHostname("one").build(), new EndpointAddressBuilder().withHostname("two").build()) .withNotReadyAddresses(new EndpointAddressBuilder().withHostname("three").build()).build(); - List addresses = KubernetesDiscoveryClientUtils.addresses(endpointSubset, properties); + List addresses = Fabric8KubernetesDiscoveryClientUtils.addresses(endpointSubset, properties); Assertions.assertEquals(addresses.size(), 2); List hostNames = addresses.stream().map(EndpointAddress::getHostname).sorted().toList(); Assertions.assertEquals(hostNames, List.of("one", "two")); @@ -675,7 +675,7 @@ void testBothAddressesTaken() { .withAddresses(new EndpointAddressBuilder().withHostname("one").build(), new EndpointAddressBuilder().withHostname("two").build()) .withNotReadyAddresses(new EndpointAddressBuilder().withHostname("three").build()).build(); - List addresses = KubernetesDiscoveryClientUtils.addresses(endpointSubset, properties); + List addresses = Fabric8KubernetesDiscoveryClientUtils.addresses(endpointSubset, properties); Assertions.assertEquals(addresses.size(), 3); List hostNames = addresses.stream().map(EndpointAddress::getHostname).sorted().toList(); Assertions.assertEquals(hostNames, List.of("one", "three", "two")); @@ -690,7 +690,7 @@ void testServiceInstance() { EndpointAddress address = new EndpointAddressBuilder().withNewTargetRef().withUid("123").endTargetRef() .withIp("127.0.0.1").build(); - ServiceInstance serviceInstance = KubernetesDiscoveryClientUtils.serviceInstance(resolver, service, address, + ServiceInstance serviceInstance = Fabric8KubernetesDiscoveryClientUtils.serviceInstance(resolver, service, address, 8080, "my-service", Map.of("a", "b"), "k8s"); Assertions.assertTrue(serviceInstance instanceof DefaultKubernetesServiceInstance); DefaultKubernetesServiceInstance defaultInstance = (DefaultKubernetesServiceInstance) serviceInstance; diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesReactiveDiscoveryClientAutoConfigurationApplicationContextTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesReactiveDiscoveryClientAutoConfigurationApplicationContextTests.java new file mode 100644 index 0000000000..2460080be1 --- /dev/null +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesReactiveDiscoveryClientAutoConfigurationApplicationContextTests.java @@ -0,0 +1,177 @@ +/* + * Copyright 2013-2023 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.discovery; + +import org.junit.jupiter.api.Test; + +import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.test.context.FilteredClassLoader; +import org.springframework.boot.test.context.runner.ApplicationContextRunner; +import org.springframework.cloud.client.ReactiveCommonsClientAutoConfiguration; +import org.springframework.cloud.client.discovery.health.reactive.ReactiveDiscoveryClientHealthIndicator; +import org.springframework.cloud.commons.util.UtilAutoConfiguration; +import org.springframework.cloud.kubernetes.commons.KubernetesCommonsAutoConfiguration; +import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryPropertiesAutoConfiguration; +import org.springframework.cloud.kubernetes.fabric8.Fabric8AutoConfiguration; +import org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesClientServicesFunction; +import org.springframework.cloud.kubernetes.fabric8.discovery.Fabric8KubernetesReactiveDiscoveryClient; +import org.springframework.cloud.kubernetes.fabric8.discovery.Fabric8KubernetesReactiveDiscoveryClientAutoConfiguration; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Test various conditionals for + * {@link Fabric8KubernetesReactiveDiscoveryClientAutoConfiguration} + * + * @author wind57 + */ +class KubernetesReactiveDiscoveryClientAutoConfigurationApplicationContextTests { + + private ApplicationContextRunner applicationContextRunner; + +// @Test +// void discoveryEnabledDefault() { +// setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false"); +// applicationContextRunner.run(context -> { +// assertThat(context).hasSingleBean(Fabric8KubernetesReactiveDiscoveryClient.class); +// assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class); +// assertThat(context).hasSingleBean(KubernetesClientServicesFunction.class); +// }); +// } +// +// @Test +// void discoveryEnabled() { +// setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", +// "spring.cloud.discovery.enabled=true"); +// applicationContextRunner.run(context -> { +// assertThat(context).hasSingleBean(Fabric8KubernetesReactiveDiscoveryClient.class); +// assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class); +// assertThat(context).hasSingleBean(KubernetesClientServicesFunction.class); +// }); +// } +// +// @Test +// void discoveryDisabled() { +// setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", +// "spring.cloud.discovery.enabled=false"); +// applicationContextRunner.run(context -> { +// assertThat(context).doesNotHaveBean(Fabric8KubernetesReactiveDiscoveryClient.class); +// assertThat(context).doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class); +// assertThat(context).doesNotHaveBean(KubernetesClientServicesFunction.class); +// }); +// } +// +// @Test +// void kubernetesDiscoveryEnabled() { +// setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", +// "spring.cloud.kubernetes.discovery.enabled=true"); +// applicationContextRunner.run(context -> { +// assertThat(context).hasSingleBean(Fabric8KubernetesReactiveDiscoveryClient.class); +// assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class); +// assertThat(context).hasSingleBean(KubernetesClientServicesFunction.class); +// }); +// } +// +// @Test +// void kubernetesDiscoveryDisabled() { +// setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", +// "spring.cloud.kubernetes.discovery.enabled=false"); +// applicationContextRunner.run(context -> { +// assertThat(context).doesNotHaveBean(Fabric8KubernetesReactiveDiscoveryClient.class); +// assertThat(context).doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class); +// assertThat(context).doesNotHaveBean(KubernetesClientServicesFunction.class); +// }); +// } +// +// @Test +// void kubernetesReactiveDiscoveryEnabled() { +// setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", +// "spring.cloud.discovery.reactive.enabled=true"); +// applicationContextRunner.run(context -> { +// assertThat(context).hasSingleBean(Fabric8KubernetesReactiveDiscoveryClient.class); +// assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class); +// assertThat(context).hasSingleBean(KubernetesClientServicesFunction.class); +// }); +// } +// +// @Test +// void kubernetesReactiveDiscoveryDisabled() { +// setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", +// "spring.cloud.discovery.reactive.enabled=false"); +// applicationContextRunner.run(context -> { +// assertThat(context).doesNotHaveBean(Fabric8KubernetesReactiveDiscoveryClient.class); +// assertThat(context).doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class); +// assertThat(context).doesNotHaveBean(KubernetesClientServicesFunction.class); +// }); +// } +// +// /** +// * blocking is disabled, and it should not impact reactive in any way. +// */ +// @Test +// void blockingDisabled() { +// setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", +// "spring.cloud.discovery.blocking.enabled=false"); +// applicationContextRunner.run(context -> { +// assertThat(context).hasSingleBean(Fabric8KubernetesReactiveDiscoveryClient.class); +// assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class); +// assertThat(context).hasSingleBean(KubernetesClientServicesFunction.class); +// }); +// } +// +// @Test +// void healthDisabled() { +// setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", +// "spring.cloud.discovery.client.health-indicator.enabled=false"); +// applicationContextRunner.run(context -> { +// assertThat(context).hasSingleBean(Fabric8KubernetesReactiveDiscoveryClient.class); +// assertThat(context).doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class); +// assertThat(context).hasSingleBean(KubernetesClientServicesFunction.class); +// }); +// } +// +// @Test +// void healthEnabledClassNotPresent() { +// setupWithFilteredClassLoader("org.springframework.boot.actuate.health.ReactiveHealthIndicator", +// "spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", +// "spring.cloud.discovery.client.health-indicator.enabled=false"); +// applicationContextRunner.run(context -> { +// assertThat(context).hasSingleBean(Fabric8KubernetesReactiveDiscoveryClient.class); +// assertThat(context).doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class); +// assertThat(context).hasSingleBean(KubernetesClientServicesFunction.class); +// }); +// } +// +// private void setup(String... properties) { +// applicationContextRunner = new ApplicationContextRunner() +// .withConfiguration(AutoConfigurations.of(UtilAutoConfiguration.class, +// ReactiveCommonsClientAutoConfiguration.class, KubernetesCommonsAutoConfiguration.class, +// Fabric8AutoConfiguration.class, Fabric8KubernetesReactiveDiscoveryClientAutoConfiguration.class, +// KubernetesDiscoveryPropertiesAutoConfiguration.class)) +// .withPropertyValues(properties); +// } +// +// private void setupWithFilteredClassLoader(String name, String... properties) { +// applicationContextRunner = new ApplicationContextRunner() +// .withConfiguration(AutoConfigurations.of(UtilAutoConfiguration.class, +// ReactiveCommonsClientAutoConfiguration.class, KubernetesCommonsAutoConfiguration.class, +// Fabric8AutoConfiguration.class, Fabric8KubernetesReactiveDiscoveryClientAutoConfiguration.class, +// KubernetesDiscoveryPropertiesAutoConfiguration.class)) +// .withClassLoader(new FilteredClassLoader(name)).withPropertyValues(properties); +// } + +} diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/reactive/KubernetesReactiveDiscoveryClientAutoConfigurationTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesReactiveDiscoveryClientAutoConfigurationTests.java similarity index 90% rename from spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/reactive/KubernetesReactiveDiscoveryClientAutoConfigurationTests.java rename to spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesReactiveDiscoveryClientAutoConfigurationTests.java index bc27268398..58e967d706 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/reactive/KubernetesReactiveDiscoveryClientAutoConfigurationTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesReactiveDiscoveryClientAutoConfigurationTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.cloud.kubernetes.fabric8.discovery.reactive; +package org.springframework.cloud.kubernetes.fabric8.discovery; import org.junit.jupiter.api.Test; @@ -28,7 +28,8 @@ import org.springframework.cloud.kubernetes.commons.KubernetesCommonsAutoConfiguration; import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryPropertiesAutoConfiguration; import org.springframework.cloud.kubernetes.fabric8.Fabric8AutoConfiguration; -import org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientAutoConfiguration; +import org.springframework.cloud.kubernetes.fabric8.discovery.Fabric8KubernetesDiscoveryClientAutoConfiguration; +import org.springframework.cloud.kubernetes.fabric8.discovery.Fabric8KubernetesReactiveDiscoveryClientAutoConfiguration; import static org.assertj.core.api.Assertions.assertThat; @@ -40,8 +41,8 @@ class KubernetesReactiveDiscoveryClientAutoConfigurationTests { private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() .withConfiguration(AutoConfigurations.of(UtilAutoConfiguration.class, ReactiveCommonsClientAutoConfiguration.class, KubernetesCommonsAutoConfiguration.class, - Fabric8AutoConfiguration.class, KubernetesDiscoveryClientAutoConfiguration.class, - KubernetesReactiveDiscoveryClientAutoConfiguration.class, + Fabric8AutoConfiguration.class, Fabric8KubernetesDiscoveryClientAutoConfiguration.class, + Fabric8KubernetesReactiveDiscoveryClientAutoConfiguration.class, KubernetesDiscoveryPropertiesAutoConfiguration.class)); @Test diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesReactiveDiscoveryClientTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesReactiveDiscoveryClientTests.java new file mode 100644 index 0000000000..66974a9824 --- /dev/null +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesReactiveDiscoveryClientTests.java @@ -0,0 +1,264 @@ +/* + * Copyright 2019-2019 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.discovery; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import io.fabric8.kubernetes.api.model.Endpoints; +import io.fabric8.kubernetes.api.model.EndpointsBuilder; +import io.fabric8.kubernetes.api.model.EndpointsList; +import io.fabric8.kubernetes.api.model.ServiceBuilder; +import io.fabric8.kubernetes.api.model.ServiceList; +import io.fabric8.kubernetes.api.model.ServiceListBuilder; +import io.fabric8.kubernetes.client.Config; +import io.fabric8.kubernetes.client.KubernetesClient; +import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient; +import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.cloud.kubernetes.fabric8.discovery.Fabric8KubernetesReactiveDiscoveryClient; +import reactor.core.publisher.Flux; +import reactor.test.StepVerifier; + +import org.springframework.cloud.client.ServiceInstance; +import org.springframework.cloud.client.discovery.ReactiveDiscoveryClient; +import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; + +import static java.util.Collections.singletonList; +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties.Metadata; + +/** + * @author Tim Ysewyn + */ +@EnableKubernetesMockClient(crud = true, https = false) +class KubernetesReactiveDiscoveryClientTests { + +// private static KubernetesMockServer kubernetesServer; +// +// private static KubernetesClient kubernetesClient; +// +// @BeforeEach +// void beforeEach() { +// // Configure the kubernetes master url to point to the mock server +// System.setProperty(Config.KUBERNETES_MASTER_SYSTEM_PROPERTY, +// kubernetesClient.getConfiguration().getMasterUrl()); +// System.setProperty(Config.KUBERNETES_TRUST_CERT_SYSTEM_PROPERTY, "true"); +// System.setProperty(Config.KUBERNETES_AUTH_TRYKUBECONFIG_SYSTEM_PROPERTY, "false"); +// System.setProperty(Config.KUBERNETES_AUTH_TRYSERVICEACCOUNT_SYSTEM_PROPERTY, "false"); +// System.setProperty(Config.KUBERNETES_HTTP2_DISABLE, "true"); +// } +// +// @AfterEach +// void afterEach() { +// kubernetesServer.clearExpectations(); +// } +// +// @Test +// void verifyDefaults() { +// ReactiveDiscoveryClient client = new Fabric8KubernetesReactiveDiscoveryClient(kubernetesClient, +// KubernetesDiscoveryProperties.DEFAULT, KubernetesClient::services); +// assertThat(client.description()).isEqualTo("Kubernetes Reactive Discovery Client"); +// assertThat(client.getOrder()).isEqualTo(ReactiveDiscoveryClient.DEFAULT_ORDER); +// } +// +// @Test +// void shouldReturnFluxOfServices() { +// kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services") +// .andReturn(200, new ServiceListBuilder().addNewItem().withNewMetadata().withName("s1") +// .withLabels(Map.of("label", "value")).endMetadata().endItem().addNewItem().withNewMetadata() +// .withName("s2").withLabels(Map.of("label", "value", "label2", "value2")).endMetadata().endItem() +// .addNewItem().withNewMetadata().withName("s3").endMetadata().endItem().build()) +// .once(); +// ReactiveDiscoveryClient client = new Fabric8KubernetesReactiveDiscoveryClient(kubernetesClient, +// KubernetesDiscoveryProperties.DEFAULT, KubernetesClient::services); +// Flux services = client.getServices(); +// StepVerifier.create(services).expectNext("s1", "s2", "s3").expectComplete().verify(); +// } +// +// @Test +// void shouldReturnEmptyFluxOfServicesWhenNoInstancesFound() { +// kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services") +// .andReturn(200, new ServiceListBuilder().build()).once(); +// +// ReactiveDiscoveryClient client = new Fabric8KubernetesReactiveDiscoveryClient(kubernetesClient, +// KubernetesDiscoveryProperties.DEFAULT, KubernetesClient::services); +// Flux services = client.getServices(); +// StepVerifier.create(services).expectNextCount(0).expectComplete().verify(); +// } +// +// @Test +// void shouldReturnEmptyFluxForNonExistingService() { +// kubernetesServer.expect().get() +// .withPath("/api/v1/namespaces/test/endpoints?fieldSelector=metadata.name%3Dnonexistent-service") +// .andReturn(200, new EndpointsBuilder().build()).once(); +// +// ReactiveDiscoveryClient client = new Fabric8KubernetesReactiveDiscoveryClient(kubernetesClient, +// KubernetesDiscoveryProperties.DEFAULT, KubernetesClient::services); +// Flux instances = client.getInstances("nonexistent-service"); +// StepVerifier.create(instances).expectNextCount(0).expectComplete().verify(); +// } +// +// @Test +// void shouldReturnEmptyFluxWhenServiceHasNoSubsets() { +// kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services") +// .andReturn(200, new ServiceListBuilder().addNewItem().withNewMetadata().withName("existing-service") +// .withLabels(Map.of("label", "value")).endMetadata().endItem().build()) +// .once(); +// +// kubernetesServer.expect().get() +// .withPath("/api/v1/namespaces/test/endpoints?fieldSelector=metadata.name%3Dexisting-service") +// .andReturn(200, new EndpointsBuilder().build()).once(); +// +// ReactiveDiscoveryClient client = new Fabric8KubernetesReactiveDiscoveryClient(kubernetesClient, +// KubernetesDiscoveryProperties.DEFAULT, KubernetesClient::services); +// Flux instances = client.getInstances("existing-service"); +// StepVerifier.create(instances).expectNextCount(0).expectComplete().verify(); +// } +// +// @Test +// void shouldReturnFlux() { +// ServiceList services = new ServiceListBuilder().addNewItem().withNewMetadata().withName("existing-service") +// .withNamespace("test").withLabels(Map.of("label", "value")).endMetadata().endItem().build(); +// +// Endpoints endPoint = new EndpointsBuilder().withNewMetadata().withName("existing-service").withNamespace("test") +// .withLabels(Map.of("label", "value")).endMetadata().addNewSubset().addNewAddress().withIp("ip1") +// .withNewTargetRef().withUid("uid1").endTargetRef().endAddress() +// .addNewPort("http", "http_tcp", 80, "TCP").endSubset().build(); +// +// List endpointsList = new ArrayList<>(); +// endpointsList.add(endPoint); +// +// EndpointsList endpoints = new EndpointsList(); +// endpoints.setItems(endpointsList); +// +// kubernetesServer.expect().get() +// .withPath("/api/v1/namespaces/test/endpoints?fieldSelector=metadata.name%3Dexisting-service") +// .andReturn(200, endpoints).once(); +// +// kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services/existing-service") +// .andReturn(200, services.getItems().get(0)).once(); +// +// Metadata metadata = new Metadata(false, null, false, null, true, "port."); +// ReactiveDiscoveryClient client = new Fabric8KubernetesReactiveDiscoveryClient(kubernetesClient, +// KubernetesDiscoveryProperties.DEFAULT, KubernetesClient::services); +// Flux instances = client.getInstances("existing-service"); +// StepVerifier.create(instances).expectNextCount(1).expectComplete().verify(); +// } +// +// @Test +// void shouldReturnFluxWithPrefixedMetadata() { +// kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services") +// .andReturn(200, new ServiceListBuilder().addNewItem().withNewMetadata().withName("existing-service") +// .withLabels(Map.of("label", "value")).endMetadata().endItem().build()) +// .once(); +// +// Endpoints endPoint = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace("test") +// .endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef().withUid("uid1") +// .endTargetRef().endAddress().addNewPort("http", "http_tcp", 80, "TCP").endSubset().build(); +// +// List endpointsList = new ArrayList<>(); +// endpointsList.add(endPoint); +// +// EndpointsList endpoints = new EndpointsList(); +// endpoints.setItems(endpointsList); +// +// kubernetesServer.expect().get() +// .withPath("/api/v1/namespaces/test/endpoints?fieldSelector=metadata.name%3Dexisting-service") +// .andReturn(200, endpoints).once(); +// +// kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services/existing-service") +// .andReturn(200, new ServiceBuilder().withNewMetadata().withName("existing-service") +// .withLabels(Map.of("label", "value")).endMetadata().build()) +// .once(); +// +// Metadata metadata = new Metadata(true, "label.", true, "annotation.", true, "port."); +// ReactiveDiscoveryClient client = new Fabric8KubernetesReactiveDiscoveryClient(kubernetesClient, +// KubernetesDiscoveryProperties.DEFAULT, KubernetesClient::services); +// Flux instances = client.getInstances("existing-service"); +// StepVerifier.create(instances).expectNextCount(1).expectComplete().verify(); +// } +// +// @Test +// void shouldReturnFluxWhenServiceHasMultiplePortsAndPrimaryPortNameIsSet() { +// kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services") +// .andReturn(200, new ServiceListBuilder().addNewItem().withNewMetadata().withName("existing-service") +// .withLabels(Map.of("label", "value")).endMetadata().endItem().build()) +// .once(); +// +// Endpoints endPoint = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace("test") +// .endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef().withUid("uid1") +// .endTargetRef().endAddress().addNewPort("http", "http_tcp", 80, "TCP") +// .addNewPort("https", "https_tcp", 443, "TCP").endSubset().build(); +// +// List endpointsList = new ArrayList<>(); +// endpointsList.add(endPoint); +// +// EndpointsList endpoints = new EndpointsList(); +// endpoints.setItems(endpointsList); +// +// kubernetesServer.expect().get() +// .withPath("/api/v1/namespaces/test/endpoints?fieldSelector=metadata.name%3Dexisting-service") +// .andReturn(200, endpoints).once(); +// +// kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services/existing-service") +// .andReturn(200, new ServiceBuilder().withNewMetadata().withName("existing-service") +// .withLabels(Map.of("label", "value")).endMetadata().build()) +// .once(); +// +// ReactiveDiscoveryClient client = new Fabric8KubernetesReactiveDiscoveryClient(kubernetesClient, +// KubernetesDiscoveryProperties.DEFAULT, KubernetesClient::services); +// Flux instances = client.getInstances("existing-service"); +// StepVerifier.create(instances).expectNextCount(1).expectComplete().verify(); +// } +// +// @Test +// void shouldReturnFluxOfServicesAcrossAllNamespaces() { +// kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services") +// .andReturn(200, new ServiceListBuilder().addNewItem().withNewMetadata().withName("existing-service") +// .withLabels(Map.of("label", "value")).endMetadata().endItem().build()) +// .once(); +// +// Endpoints endpoints = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace("test") +// .endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef().withUid("uid1") +// .endTargetRef().endAddress().addNewPort("http", "http_tcp", 80, "TCP") +// .addNewPort("https", "https_tcp", 443, "TCP").endSubset().build(); +// +// EndpointsList endpointsList = new EndpointsList(); +// endpointsList.setItems(singletonList(endpoints)); +// +// kubernetesServer.expect().get().withPath("/api/v1/endpoints?fieldSelector=metadata.name%3Dexisting-service") +// .andReturn(200, endpointsList).once(); +// +// kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services/existing-service") +// .andReturn(200, new ServiceBuilder().withNewMetadata().withName("existing-service") +// .withLabels(Map.of("label", "value")).endMetadata().build()) +// .once(); +// +// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, +// false, null, Set.of(), Map.of(), "https_tcp", Metadata.DEFAULT, 0, true); +// ReactiveDiscoveryClient client = new Fabric8KubernetesReactiveDiscoveryClient(kubernetesClient, properties, +// KubernetesClient::services); +// Flux instances = client.getInstances("existing-service"); +// StepVerifier.create(instances).expectNextCount(1).expectComplete().verify(); +// } + +} diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/reactive/KubernetesReactiveDiscoveryClientAutoConfigurationApplicationContextTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/reactive/KubernetesReactiveDiscoveryClientAutoConfigurationApplicationContextTests.java deleted file mode 100644 index a0e156b957..0000000000 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/reactive/KubernetesReactiveDiscoveryClientAutoConfigurationApplicationContextTests.java +++ /dev/null @@ -1,175 +0,0 @@ -/* - * Copyright 2013-2023 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.discovery.reactive; - -import org.junit.jupiter.api.Test; - -import org.springframework.boot.autoconfigure.AutoConfigurations; -import org.springframework.boot.test.context.FilteredClassLoader; -import org.springframework.boot.test.context.runner.ApplicationContextRunner; -import org.springframework.cloud.client.ReactiveCommonsClientAutoConfiguration; -import org.springframework.cloud.client.discovery.health.reactive.ReactiveDiscoveryClientHealthIndicator; -import org.springframework.cloud.commons.util.UtilAutoConfiguration; -import org.springframework.cloud.kubernetes.commons.KubernetesCommonsAutoConfiguration; -import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryPropertiesAutoConfiguration; -import org.springframework.cloud.kubernetes.fabric8.Fabric8AutoConfiguration; -import org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesClientServicesFunction; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Test various conditionals for - * {@link KubernetesReactiveDiscoveryClientAutoConfiguration} - * - * @author wind57 - */ -class KubernetesReactiveDiscoveryClientAutoConfigurationApplicationContextTests { - - private ApplicationContextRunner applicationContextRunner; - - @Test - void discoveryEnabledDefault() { - setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false"); - applicationContextRunner.run(context -> { - assertThat(context).hasSingleBean(KubernetesReactiveDiscoveryClient.class); - assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class); - assertThat(context).hasSingleBean(KubernetesClientServicesFunction.class); - }); - } - - @Test - void discoveryEnabled() { - setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", - "spring.cloud.discovery.enabled=true"); - applicationContextRunner.run(context -> { - assertThat(context).hasSingleBean(KubernetesReactiveDiscoveryClient.class); - assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class); - assertThat(context).hasSingleBean(KubernetesClientServicesFunction.class); - }); - } - - @Test - void discoveryDisabled() { - setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", - "spring.cloud.discovery.enabled=false"); - applicationContextRunner.run(context -> { - assertThat(context).doesNotHaveBean(KubernetesReactiveDiscoveryClient.class); - assertThat(context).doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class); - assertThat(context).doesNotHaveBean(KubernetesClientServicesFunction.class); - }); - } - - @Test - void kubernetesDiscoveryEnabled() { - setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", - "spring.cloud.kubernetes.discovery.enabled=true"); - applicationContextRunner.run(context -> { - assertThat(context).hasSingleBean(KubernetesReactiveDiscoveryClient.class); - assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class); - assertThat(context).hasSingleBean(KubernetesClientServicesFunction.class); - }); - } - - @Test - void kubernetesDiscoveryDisabled() { - setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", - "spring.cloud.kubernetes.discovery.enabled=false"); - applicationContextRunner.run(context -> { - assertThat(context).doesNotHaveBean(KubernetesReactiveDiscoveryClient.class); - assertThat(context).doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class); - assertThat(context).doesNotHaveBean(KubernetesClientServicesFunction.class); - }); - } - - @Test - void kubernetesReactiveDiscoveryEnabled() { - setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", - "spring.cloud.discovery.reactive.enabled=true"); - applicationContextRunner.run(context -> { - assertThat(context).hasSingleBean(KubernetesReactiveDiscoveryClient.class); - assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class); - assertThat(context).hasSingleBean(KubernetesClientServicesFunction.class); - }); - } - - @Test - void kubernetesReactiveDiscoveryDisabled() { - setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", - "spring.cloud.discovery.reactive.enabled=false"); - applicationContextRunner.run(context -> { - assertThat(context).doesNotHaveBean(KubernetesReactiveDiscoveryClient.class); - assertThat(context).doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class); - assertThat(context).doesNotHaveBean(KubernetesClientServicesFunction.class); - }); - } - - /** - * blocking is disabled, and it should not impact reactive in any way. - */ - @Test - void blockingDisabled() { - setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", - "spring.cloud.discovery.blocking.enabled=false"); - applicationContextRunner.run(context -> { - assertThat(context).hasSingleBean(KubernetesReactiveDiscoveryClient.class); - assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class); - assertThat(context).hasSingleBean(KubernetesClientServicesFunction.class); - }); - } - - @Test - void healthDisabled() { - setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", - "spring.cloud.discovery.client.health-indicator.enabled=false"); - applicationContextRunner.run(context -> { - assertThat(context).hasSingleBean(KubernetesReactiveDiscoveryClient.class); - assertThat(context).doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class); - assertThat(context).hasSingleBean(KubernetesClientServicesFunction.class); - }); - } - - @Test - void healthEnabledClassNotPresent() { - setupWithFilteredClassLoader("org.springframework.boot.actuate.health.ReactiveHealthIndicator", - "spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", - "spring.cloud.discovery.client.health-indicator.enabled=false"); - applicationContextRunner.run(context -> { - assertThat(context).hasSingleBean(KubernetesReactiveDiscoveryClient.class); - assertThat(context).doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class); - assertThat(context).hasSingleBean(KubernetesClientServicesFunction.class); - }); - } - - private void setup(String... properties) { - applicationContextRunner = new ApplicationContextRunner() - .withConfiguration(AutoConfigurations.of(UtilAutoConfiguration.class, - ReactiveCommonsClientAutoConfiguration.class, KubernetesCommonsAutoConfiguration.class, - Fabric8AutoConfiguration.class, KubernetesReactiveDiscoveryClientAutoConfiguration.class, - KubernetesDiscoveryPropertiesAutoConfiguration.class)) - .withPropertyValues(properties); - } - - private void setupWithFilteredClassLoader(String name, String... properties) { - applicationContextRunner = new ApplicationContextRunner() - .withConfiguration(AutoConfigurations.of(UtilAutoConfiguration.class, - ReactiveCommonsClientAutoConfiguration.class, KubernetesCommonsAutoConfiguration.class, - Fabric8AutoConfiguration.class, KubernetesReactiveDiscoveryClientAutoConfiguration.class, - KubernetesDiscoveryPropertiesAutoConfiguration.class)) - .withClassLoader(new FilteredClassLoader(name)).withPropertyValues(properties); - } - -} diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/reactive/KubernetesReactiveDiscoveryClientTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/reactive/KubernetesReactiveDiscoveryClientTests.java deleted file mode 100644 index aa7cbd8bda..0000000000 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/reactive/KubernetesReactiveDiscoveryClientTests.java +++ /dev/null @@ -1,263 +0,0 @@ -/* - * Copyright 2019-2019 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.discovery.reactive; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import io.fabric8.kubernetes.api.model.Endpoints; -import io.fabric8.kubernetes.api.model.EndpointsBuilder; -import io.fabric8.kubernetes.api.model.EndpointsList; -import io.fabric8.kubernetes.api.model.ServiceBuilder; -import io.fabric8.kubernetes.api.model.ServiceList; -import io.fabric8.kubernetes.api.model.ServiceListBuilder; -import io.fabric8.kubernetes.client.Config; -import io.fabric8.kubernetes.client.KubernetesClient; -import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient; -import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import reactor.core.publisher.Flux; -import reactor.test.StepVerifier; - -import org.springframework.cloud.client.ServiceInstance; -import org.springframework.cloud.client.discovery.ReactiveDiscoveryClient; -import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; - -import static java.util.Collections.singletonList; -import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties.Metadata; - -/** - * @author Tim Ysewyn - */ -@EnableKubernetesMockClient(crud = true, https = false) -class KubernetesReactiveDiscoveryClientTests { - - private static KubernetesMockServer kubernetesServer; - - private static KubernetesClient kubernetesClient; - - @BeforeEach - void beforeEach() { - // Configure the kubernetes master url to point to the mock server - System.setProperty(Config.KUBERNETES_MASTER_SYSTEM_PROPERTY, - kubernetesClient.getConfiguration().getMasterUrl()); - System.setProperty(Config.KUBERNETES_TRUST_CERT_SYSTEM_PROPERTY, "true"); - System.setProperty(Config.KUBERNETES_AUTH_TRYKUBECONFIG_SYSTEM_PROPERTY, "false"); - System.setProperty(Config.KUBERNETES_AUTH_TRYSERVICEACCOUNT_SYSTEM_PROPERTY, "false"); - System.setProperty(Config.KUBERNETES_HTTP2_DISABLE, "true"); - } - - @AfterEach - void afterEach() { - kubernetesServer.clearExpectations(); - } - - @Test - void verifyDefaults() { - ReactiveDiscoveryClient client = new KubernetesReactiveDiscoveryClient(kubernetesClient, - KubernetesDiscoveryProperties.DEFAULT, KubernetesClient::services); - assertThat(client.description()).isEqualTo("Kubernetes Reactive Discovery Client"); - assertThat(client.getOrder()).isEqualTo(ReactiveDiscoveryClient.DEFAULT_ORDER); - } - - @Test - void shouldReturnFluxOfServices() { - kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services") - .andReturn(200, new ServiceListBuilder().addNewItem().withNewMetadata().withName("s1") - .withLabels(Map.of("label", "value")).endMetadata().endItem().addNewItem().withNewMetadata() - .withName("s2").withLabels(Map.of("label", "value", "label2", "value2")).endMetadata().endItem() - .addNewItem().withNewMetadata().withName("s3").endMetadata().endItem().build()) - .once(); - ReactiveDiscoveryClient client = new KubernetesReactiveDiscoveryClient(kubernetesClient, - KubernetesDiscoveryProperties.DEFAULT, KubernetesClient::services); - Flux services = client.getServices(); - StepVerifier.create(services).expectNext("s1", "s2", "s3").expectComplete().verify(); - } - - @Test - void shouldReturnEmptyFluxOfServicesWhenNoInstancesFound() { - kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services") - .andReturn(200, new ServiceListBuilder().build()).once(); - - ReactiveDiscoveryClient client = new KubernetesReactiveDiscoveryClient(kubernetesClient, - KubernetesDiscoveryProperties.DEFAULT, KubernetesClient::services); - Flux services = client.getServices(); - StepVerifier.create(services).expectNextCount(0).expectComplete().verify(); - } - - @Test - void shouldReturnEmptyFluxForNonExistingService() { - kubernetesServer.expect().get() - .withPath("/api/v1/namespaces/test/endpoints?fieldSelector=metadata.name%3Dnonexistent-service") - .andReturn(200, new EndpointsBuilder().build()).once(); - - ReactiveDiscoveryClient client = new KubernetesReactiveDiscoveryClient(kubernetesClient, - KubernetesDiscoveryProperties.DEFAULT, KubernetesClient::services); - Flux instances = client.getInstances("nonexistent-service"); - StepVerifier.create(instances).expectNextCount(0).expectComplete().verify(); - } - - @Test - void shouldReturnEmptyFluxWhenServiceHasNoSubsets() { - kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services") - .andReturn(200, new ServiceListBuilder().addNewItem().withNewMetadata().withName("existing-service") - .withLabels(Map.of("label", "value")).endMetadata().endItem().build()) - .once(); - - kubernetesServer.expect().get() - .withPath("/api/v1/namespaces/test/endpoints?fieldSelector=metadata.name%3Dexisting-service") - .andReturn(200, new EndpointsBuilder().build()).once(); - - ReactiveDiscoveryClient client = new KubernetesReactiveDiscoveryClient(kubernetesClient, - KubernetesDiscoveryProperties.DEFAULT, KubernetesClient::services); - Flux instances = client.getInstances("existing-service"); - StepVerifier.create(instances).expectNextCount(0).expectComplete().verify(); - } - - @Test - void shouldReturnFlux() { - ServiceList services = new ServiceListBuilder().addNewItem().withNewMetadata().withName("existing-service") - .withNamespace("test").withLabels(Map.of("label", "value")).endMetadata().endItem().build(); - - Endpoints endPoint = new EndpointsBuilder().withNewMetadata().withName("existing-service").withNamespace("test") - .withLabels(Map.of("label", "value")).endMetadata().addNewSubset().addNewAddress().withIp("ip1") - .withNewTargetRef().withUid("uid1").endTargetRef().endAddress() - .addNewPort("http", "http_tcp", 80, "TCP").endSubset().build(); - - List endpointsList = new ArrayList<>(); - endpointsList.add(endPoint); - - EndpointsList endpoints = new EndpointsList(); - endpoints.setItems(endpointsList); - - kubernetesServer.expect().get() - .withPath("/api/v1/namespaces/test/endpoints?fieldSelector=metadata.name%3Dexisting-service") - .andReturn(200, endpoints).once(); - - kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services/existing-service") - .andReturn(200, services.getItems().get(0)).once(); - - Metadata metadata = new Metadata(false, null, false, null, true, "port."); - ReactiveDiscoveryClient client = new KubernetesReactiveDiscoveryClient(kubernetesClient, - KubernetesDiscoveryProperties.DEFAULT, KubernetesClient::services); - Flux instances = client.getInstances("existing-service"); - StepVerifier.create(instances).expectNextCount(1).expectComplete().verify(); - } - - @Test - void shouldReturnFluxWithPrefixedMetadata() { - kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services") - .andReturn(200, new ServiceListBuilder().addNewItem().withNewMetadata().withName("existing-service") - .withLabels(Map.of("label", "value")).endMetadata().endItem().build()) - .once(); - - Endpoints endPoint = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace("test") - .endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef().withUid("uid1") - .endTargetRef().endAddress().addNewPort("http", "http_tcp", 80, "TCP").endSubset().build(); - - List endpointsList = new ArrayList<>(); - endpointsList.add(endPoint); - - EndpointsList endpoints = new EndpointsList(); - endpoints.setItems(endpointsList); - - kubernetesServer.expect().get() - .withPath("/api/v1/namespaces/test/endpoints?fieldSelector=metadata.name%3Dexisting-service") - .andReturn(200, endpoints).once(); - - kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services/existing-service") - .andReturn(200, new ServiceBuilder().withNewMetadata().withName("existing-service") - .withLabels(Map.of("label", "value")).endMetadata().build()) - .once(); - - Metadata metadata = new Metadata(true, "label.", true, "annotation.", true, "port."); - ReactiveDiscoveryClient client = new KubernetesReactiveDiscoveryClient(kubernetesClient, - KubernetesDiscoveryProperties.DEFAULT, KubernetesClient::services); - Flux instances = client.getInstances("existing-service"); - StepVerifier.create(instances).expectNextCount(1).expectComplete().verify(); - } - - @Test - void shouldReturnFluxWhenServiceHasMultiplePortsAndPrimaryPortNameIsSet() { - kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services") - .andReturn(200, new ServiceListBuilder().addNewItem().withNewMetadata().withName("existing-service") - .withLabels(Map.of("label", "value")).endMetadata().endItem().build()) - .once(); - - Endpoints endPoint = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace("test") - .endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef().withUid("uid1") - .endTargetRef().endAddress().addNewPort("http", "http_tcp", 80, "TCP") - .addNewPort("https", "https_tcp", 443, "TCP").endSubset().build(); - - List endpointsList = new ArrayList<>(); - endpointsList.add(endPoint); - - EndpointsList endpoints = new EndpointsList(); - endpoints.setItems(endpointsList); - - kubernetesServer.expect().get() - .withPath("/api/v1/namespaces/test/endpoints?fieldSelector=metadata.name%3Dexisting-service") - .andReturn(200, endpoints).once(); - - kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services/existing-service") - .andReturn(200, new ServiceBuilder().withNewMetadata().withName("existing-service") - .withLabels(Map.of("label", "value")).endMetadata().build()) - .once(); - - ReactiveDiscoveryClient client = new KubernetesReactiveDiscoveryClient(kubernetesClient, - KubernetesDiscoveryProperties.DEFAULT, KubernetesClient::services); - Flux instances = client.getInstances("existing-service"); - StepVerifier.create(instances).expectNextCount(1).expectComplete().verify(); - } - - @Test - void shouldReturnFluxOfServicesAcrossAllNamespaces() { - kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services") - .andReturn(200, new ServiceListBuilder().addNewItem().withNewMetadata().withName("existing-service") - .withLabels(Map.of("label", "value")).endMetadata().endItem().build()) - .once(); - - Endpoints endpoints = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace("test") - .endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef().withUid("uid1") - .endTargetRef().endAddress().addNewPort("http", "http_tcp", 80, "TCP") - .addNewPort("https", "https_tcp", 443, "TCP").endSubset().build(); - - EndpointsList endpointsList = new EndpointsList(); - endpointsList.setItems(singletonList(endpoints)); - - kubernetesServer.expect().get().withPath("/api/v1/endpoints?fieldSelector=metadata.name%3Dexisting-service") - .andReturn(200, endpointsList).once(); - - kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services/existing-service") - .andReturn(200, new ServiceBuilder().withNewMetadata().withName("existing-service") - .withLabels(Map.of("label", "value")).endMetadata().build()) - .once(); - - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, - false, null, Set.of(), Map.of(), "https_tcp", Metadata.DEFAULT, 0, true); - ReactiveDiscoveryClient client = new KubernetesReactiveDiscoveryClient(kubernetesClient, properties, - KubernetesClient::services); - Flux instances = client.getInstances("existing-service"); - StepVerifier.create(instances).expectNextCount(1).expectComplete().verify(); - } - -} diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/configmap/Fabric8DiscoveryController.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/configmap/Fabric8DiscoveryController.java index 7cf7d06ee4..233ac62416 100644 --- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/configmap/Fabric8DiscoveryController.java +++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/configmap/Fabric8DiscoveryController.java @@ -20,7 +20,7 @@ import io.fabric8.kubernetes.api.model.Endpoints; -import org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClient; +import org.springframework.cloud.kubernetes.fabric8.discovery.Fabric8KubernetesDiscoveryClient; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RestController; @@ -31,9 +31,9 @@ @RestController public class Fabric8DiscoveryController { - private final KubernetesDiscoveryClient discoveryClient; + private final Fabric8KubernetesDiscoveryClient discoveryClient; - public Fabric8DiscoveryController(KubernetesDiscoveryClient discoveryClient) { + public Fabric8DiscoveryController(Fabric8KubernetesDiscoveryClient discoveryClient) { this.discoveryClient = discoveryClient; } From cd1ad32263235e381d9126f71ec4c63293f5aa36 Mon Sep 17 00:00:00 2001 From: wind57 Date: Sat, 25 Feb 2023 18:54:03 +0200 Subject: [PATCH 024/151] dirty - working on tests --- ...onditionalOnBlockingOrReactiveEnabled.java | 2 +- .../discovery/Fabric8CatalogWatchContext.java | 2 +- ...overyClientPredicateAutoConfiguration.java | 3 +- .../Fabric8EndpointSliceV1CatalogWatch.java | 2 +- .../Fabric8EndpointsCatalogWatch.java | 2 +- .../Fabric8KubernetesCatalogWatch.java | 2 +- ...bernetesCatalogWatchAutoConfiguration.java | 2 +- .../Fabric8KubernetesDiscoveryClient.java | 2 +- ...netesDiscoveryClientAutoConfiguration.java | 4 +- ...entConfigClientBootstrapConfiguration.java | 2 +- ...ric8KubernetesReactiveDiscoveryClient.java | 2 +- ...ctiveDiscoveryClientAutoConfiguration.java | 5 +- .../discovery/ServicePortSecureResolver.java | 2 +- ...oConfigurationApplicationContextTests.java | 259 +++++----- ...DiscoveryClientAutoConfigurationTests.java | 4 +- ...ubernetesReactiveDiscoveryClientTests.java | 476 ++++++++++-------- .../ServicePortSecureResolverTest.java | 20 +- 17 files changed, 425 insertions(+), 366 deletions(-) diff --git a/spring-cloud-kubernetes-client-discovery/src/main/java/org/springframework/cloud/kubernetes/client/discovery/ConditionalOnBlockingOrReactiveEnabled.java b/spring-cloud-kubernetes-client-discovery/src/main/java/org/springframework/cloud/kubernetes/client/discovery/ConditionalOnBlockingOrReactiveEnabled.java index 6bb44aa493..b89a564b01 100644 --- a/spring-cloud-kubernetes-client-discovery/src/main/java/org/springframework/cloud/kubernetes/client/discovery/ConditionalOnBlockingOrReactiveEnabled.java +++ b/spring-cloud-kubernetes-client-discovery/src/main/java/org/springframework/cloud/kubernetes/client/discovery/ConditionalOnBlockingOrReactiveEnabled.java @@ -30,7 +30,7 @@ /** * Conditional that is resolved to active when either - * {@link ConditionalOnBlockingOrReactiveEnabled} or + * {@link ConditionalOnBlockingDiscoveryEnabled} or * {@link ConditionalOnReactiveDiscoveryEnabled} matches. * * @author wind57 diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8CatalogWatchContext.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8CatalogWatchContext.java index 9d3fc70f8b..2e9bde1a4e 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8CatalogWatchContext.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8CatalogWatchContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-2023 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. diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryClientPredicateAutoConfiguration.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryClientPredicateAutoConfiguration.java index 97b92a6a99..deb2c4dc9b 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryClientPredicateAutoConfiguration.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryClientPredicateAutoConfiguration.java @@ -40,8 +40,7 @@ */ @Configuration(proxyBeanMethods = false) @ConditionalOnDiscoveryEnabled -@ConditionalOnKubernetesDiscoveryEnabled -@ConditionalOnBlockingDiscoveryEnabled +@ConditionalOnBlockingOrReactiveEnabled @ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES) @AutoConfigureAfter(KubernetesDiscoveryPropertiesAutoConfiguration.class) class Fabric8DiscoveryClientPredicateAutoConfiguration { diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8EndpointSliceV1CatalogWatch.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8EndpointSliceV1CatalogWatch.java index e1a3f8a01a..b2dc19d854 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8EndpointSliceV1CatalogWatch.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8EndpointSliceV1CatalogWatch.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-2023 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. diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8EndpointsCatalogWatch.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8EndpointsCatalogWatch.java index 55a60b1d01..22bbe7c661 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8EndpointsCatalogWatch.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8EndpointsCatalogWatch.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-2023 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. diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatch.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatch.java index b3a098b8fe..f9f69355f3 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatch.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatch.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2022 the original author or authors. + * Copyright 2013-2023 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. diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchAutoConfiguration.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchAutoConfiguration.java index 4967cf0c9a..f2a7b85ebd 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchAutoConfiguration.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2023 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. diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClient.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClient.java index f9fe76bae6..163f236bf9 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClient.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClient.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2023 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. diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAutoConfiguration.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAutoConfiguration.java index abc8ea7e96..808af213fc 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAutoConfiguration.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2023 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. @@ -58,7 +58,7 @@ @ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES) @AutoConfigureBefore({ SimpleDiscoveryClientAutoConfiguration.class, CommonsClientAutoConfiguration.class }) @AutoConfigureAfter({ Fabric8AutoConfiguration.class, KubernetesDiscoveryPropertiesAutoConfiguration.class, - Fabric8DiscoveryClientPredicateAutoConfiguration.class}) + Fabric8DiscoveryClientPredicateAutoConfiguration.class }) class Fabric8KubernetesDiscoveryClientAutoConfiguration { @Bean diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientConfigClientBootstrapConfiguration.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientConfigClientBootstrapConfiguration.java index ab3b05673e..f2cd0d0587 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientConfigClientBootstrapConfiguration.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientConfigClientBootstrapConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2023 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. diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClient.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClient.java index 02b79e8cd1..21bc314dea 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClient.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClient.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2019 the original author or authors. + * Copyright 2019-2023 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. diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientAutoConfiguration.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientAutoConfiguration.java index 27baec9613..33ab754d70 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientAutoConfiguration.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2023 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. @@ -56,7 +56,8 @@ @AutoConfigureBefore({ SimpleReactiveDiscoveryClientAutoConfiguration.class, ReactiveCommonsClientAutoConfiguration.class }) @AutoConfigureAfter({ ReactiveCompositeDiscoveryClientAutoConfiguration.class, - Fabric8KubernetesDiscoveryClientAutoConfiguration.class, KubernetesDiscoveryPropertiesAutoConfiguration.class }) + Fabric8KubernetesDiscoveryClientAutoConfiguration.class, KubernetesDiscoveryPropertiesAutoConfiguration.class, + Fabric8DiscoveryClientPredicateAutoConfiguration.class }) class Fabric8KubernetesReactiveDiscoveryClientAutoConfiguration { @Bean diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/ServicePortSecureResolver.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/ServicePortSecureResolver.java index f4feb58811..082e4e912e 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/ServicePortSecureResolver.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/ServicePortSecureResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2022 the original author or authors. + * Copyright 2013-2023 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. diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesReactiveDiscoveryClientAutoConfigurationApplicationContextTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesReactiveDiscoveryClientAutoConfigurationApplicationContextTests.java index 2460080be1..28d2d42844 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesReactiveDiscoveryClientAutoConfigurationApplicationContextTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesReactiveDiscoveryClientAutoConfigurationApplicationContextTests.java @@ -27,9 +27,6 @@ import org.springframework.cloud.kubernetes.commons.KubernetesCommonsAutoConfiguration; import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryPropertiesAutoConfiguration; import org.springframework.cloud.kubernetes.fabric8.Fabric8AutoConfiguration; -import org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesClientServicesFunction; -import org.springframework.cloud.kubernetes.fabric8.discovery.Fabric8KubernetesReactiveDiscoveryClient; -import org.springframework.cloud.kubernetes.fabric8.discovery.Fabric8KubernetesReactiveDiscoveryClientAutoConfiguration; import static org.assertj.core.api.Assertions.assertThat; @@ -43,135 +40,131 @@ class KubernetesReactiveDiscoveryClientAutoConfigurationApplicationContextTests private ApplicationContextRunner applicationContextRunner; -// @Test -// void discoveryEnabledDefault() { -// setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false"); -// applicationContextRunner.run(context -> { -// assertThat(context).hasSingleBean(Fabric8KubernetesReactiveDiscoveryClient.class); -// assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class); -// assertThat(context).hasSingleBean(KubernetesClientServicesFunction.class); -// }); -// } -// -// @Test -// void discoveryEnabled() { -// setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", -// "spring.cloud.discovery.enabled=true"); -// applicationContextRunner.run(context -> { -// assertThat(context).hasSingleBean(Fabric8KubernetesReactiveDiscoveryClient.class); -// assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class); -// assertThat(context).hasSingleBean(KubernetesClientServicesFunction.class); -// }); -// } -// -// @Test -// void discoveryDisabled() { -// setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", -// "spring.cloud.discovery.enabled=false"); -// applicationContextRunner.run(context -> { -// assertThat(context).doesNotHaveBean(Fabric8KubernetesReactiveDiscoveryClient.class); -// assertThat(context).doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class); -// assertThat(context).doesNotHaveBean(KubernetesClientServicesFunction.class); -// }); -// } -// -// @Test -// void kubernetesDiscoveryEnabled() { -// setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", -// "spring.cloud.kubernetes.discovery.enabled=true"); -// applicationContextRunner.run(context -> { -// assertThat(context).hasSingleBean(Fabric8KubernetesReactiveDiscoveryClient.class); -// assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class); -// assertThat(context).hasSingleBean(KubernetesClientServicesFunction.class); -// }); -// } -// -// @Test -// void kubernetesDiscoveryDisabled() { -// setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", -// "spring.cloud.kubernetes.discovery.enabled=false"); -// applicationContextRunner.run(context -> { -// assertThat(context).doesNotHaveBean(Fabric8KubernetesReactiveDiscoveryClient.class); -// assertThat(context).doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class); -// assertThat(context).doesNotHaveBean(KubernetesClientServicesFunction.class); -// }); -// } -// -// @Test -// void kubernetesReactiveDiscoveryEnabled() { -// setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", -// "spring.cloud.discovery.reactive.enabled=true"); -// applicationContextRunner.run(context -> { -// assertThat(context).hasSingleBean(Fabric8KubernetesReactiveDiscoveryClient.class); -// assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class); -// assertThat(context).hasSingleBean(KubernetesClientServicesFunction.class); -// }); -// } -// -// @Test -// void kubernetesReactiveDiscoveryDisabled() { -// setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", -// "spring.cloud.discovery.reactive.enabled=false"); -// applicationContextRunner.run(context -> { -// assertThat(context).doesNotHaveBean(Fabric8KubernetesReactiveDiscoveryClient.class); -// assertThat(context).doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class); -// assertThat(context).doesNotHaveBean(KubernetesClientServicesFunction.class); -// }); -// } -// -// /** -// * blocking is disabled, and it should not impact reactive in any way. -// */ -// @Test -// void blockingDisabled() { -// setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", -// "spring.cloud.discovery.blocking.enabled=false"); -// applicationContextRunner.run(context -> { -// assertThat(context).hasSingleBean(Fabric8KubernetesReactiveDiscoveryClient.class); -// assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class); -// assertThat(context).hasSingleBean(KubernetesClientServicesFunction.class); -// }); -// } -// -// @Test -// void healthDisabled() { -// setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", -// "spring.cloud.discovery.client.health-indicator.enabled=false"); -// applicationContextRunner.run(context -> { -// assertThat(context).hasSingleBean(Fabric8KubernetesReactiveDiscoveryClient.class); -// assertThat(context).doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class); -// assertThat(context).hasSingleBean(KubernetesClientServicesFunction.class); -// }); -// } -// -// @Test -// void healthEnabledClassNotPresent() { -// setupWithFilteredClassLoader("org.springframework.boot.actuate.health.ReactiveHealthIndicator", -// "spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", -// "spring.cloud.discovery.client.health-indicator.enabled=false"); -// applicationContextRunner.run(context -> { -// assertThat(context).hasSingleBean(Fabric8KubernetesReactiveDiscoveryClient.class); -// assertThat(context).doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class); -// assertThat(context).hasSingleBean(KubernetesClientServicesFunction.class); -// }); -// } -// -// private void setup(String... properties) { -// applicationContextRunner = new ApplicationContextRunner() -// .withConfiguration(AutoConfigurations.of(UtilAutoConfiguration.class, -// ReactiveCommonsClientAutoConfiguration.class, KubernetesCommonsAutoConfiguration.class, -// Fabric8AutoConfiguration.class, Fabric8KubernetesReactiveDiscoveryClientAutoConfiguration.class, -// KubernetesDiscoveryPropertiesAutoConfiguration.class)) -// .withPropertyValues(properties); -// } -// -// private void setupWithFilteredClassLoader(String name, String... properties) { -// applicationContextRunner = new ApplicationContextRunner() -// .withConfiguration(AutoConfigurations.of(UtilAutoConfiguration.class, -// ReactiveCommonsClientAutoConfiguration.class, KubernetesCommonsAutoConfiguration.class, -// Fabric8AutoConfiguration.class, Fabric8KubernetesReactiveDiscoveryClientAutoConfiguration.class, -// KubernetesDiscoveryPropertiesAutoConfiguration.class)) -// .withClassLoader(new FilteredClassLoader(name)).withPropertyValues(properties); -// } + @Test + void discoveryEnabledDefault() { + setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false"); + applicationContextRunner.withConfiguration(AutoConfigurations.of(Fabric8DiscoveryClientPredicateAutoConfiguration.class)) + .run(context -> { + assertThat(context).hasSingleBean(Fabric8KubernetesReactiveDiscoveryClient.class); + assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class); + }); + } + + @Test + void discoveryEnabled() { + setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", + "spring.cloud.discovery.enabled=true"); + applicationContextRunner.withConfiguration(AutoConfigurations.of(Fabric8DiscoveryClientPredicateAutoConfiguration.class)) + .run(context -> { + assertThat(context).hasSingleBean(Fabric8KubernetesReactiveDiscoveryClient.class); + assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class); + }); + } + + @Test + void discoveryDisabled() { + setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", + "spring.cloud.discovery.enabled=false"); + applicationContextRunner.run(context -> { + assertThat(context).doesNotHaveBean(Fabric8KubernetesReactiveDiscoveryClient.class); + assertThat(context).doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class); + }); + } + + @Test + void kubernetesDiscoveryEnabled() { + setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", + "spring.cloud.kubernetes.discovery.enabled=true"); + applicationContextRunner.withConfiguration(AutoConfigurations.of(Fabric8DiscoveryClientPredicateAutoConfiguration.class)) + .run(context -> { + assertThat(context).hasSingleBean(Fabric8KubernetesReactiveDiscoveryClient.class); + assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class); + }); + } + + @Test + void kubernetesDiscoveryDisabled() { + setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", + "spring.cloud.kubernetes.discovery.enabled=false"); + applicationContextRunner.run(context -> { + assertThat(context).doesNotHaveBean(Fabric8KubernetesReactiveDiscoveryClient.class); + assertThat(context).doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class); + }); + } + + @Test + void kubernetesReactiveDiscoveryEnabled() { + setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", + "spring.cloud.discovery.reactive.enabled=true"); + applicationContextRunner.withConfiguration(AutoConfigurations.of(Fabric8DiscoveryClientPredicateAutoConfiguration.class)).run(context -> { + assertThat(context).hasSingleBean(Fabric8KubernetesReactiveDiscoveryClient.class); + assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class); + }); + } + + @Test + void kubernetesReactiveDiscoveryDisabled() { + setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", + "spring.cloud.discovery.reactive.enabled=false"); + applicationContextRunner.run(context -> { + assertThat(context).doesNotHaveBean(Fabric8KubernetesReactiveDiscoveryClient.class); + assertThat(context).doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class); + }); + } + + /** + * blocking is disabled, and it should not impact reactive in any way. + */ + @Test + void blockingDisabled() { + setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", + "spring.cloud.discovery.blocking.enabled=false"); + applicationContextRunner.withConfiguration(AutoConfigurations.of(Fabric8DiscoveryClientPredicateAutoConfiguration.class)) + .run(context -> { + assertThat(context).hasSingleBean(Fabric8KubernetesReactiveDiscoveryClient.class); + assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class); + }); + } + + @Test + void healthDisabled() { + setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", + "spring.cloud.discovery.client.health-indicator.enabled=false"); + applicationContextRunner.withConfiguration(AutoConfigurations.of(Fabric8DiscoveryClientPredicateAutoConfiguration.class)) + .run(context -> { + assertThat(context).hasSingleBean(Fabric8KubernetesReactiveDiscoveryClient.class); + assertThat(context).doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class); + }); + } + + @Test + void healthEnabledClassNotPresent() { + setupWithFilteredClassLoader("org.springframework.boot.actuate.health.ReactiveHealthIndicator", + "spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", + "spring.cloud.discovery.client.health-indicator.enabled=false"); + applicationContextRunner.withConfiguration(AutoConfigurations.of(Fabric8DiscoveryClientPredicateAutoConfiguration.class)) + .run(context -> { + assertThat(context).hasSingleBean(Fabric8KubernetesReactiveDiscoveryClient.class); + assertThat(context).doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class); + }); + } + + private void setup(String... properties) { + applicationContextRunner = new ApplicationContextRunner() + .withConfiguration(AutoConfigurations.of(UtilAutoConfiguration.class, + ReactiveCommonsClientAutoConfiguration.class, KubernetesCommonsAutoConfiguration.class, + Fabric8AutoConfiguration.class, Fabric8KubernetesReactiveDiscoveryClientAutoConfiguration.class, + KubernetesDiscoveryPropertiesAutoConfiguration.class)) + .withPropertyValues(properties); + } + + private void setupWithFilteredClassLoader(String name, String... properties) { + applicationContextRunner = new ApplicationContextRunner() + .withConfiguration(AutoConfigurations.of(UtilAutoConfiguration.class, + ReactiveCommonsClientAutoConfiguration.class, KubernetesCommonsAutoConfiguration.class, + Fabric8AutoConfiguration.class, Fabric8KubernetesReactiveDiscoveryClientAutoConfiguration.class, + KubernetesDiscoveryPropertiesAutoConfiguration.class)) + .withClassLoader(new FilteredClassLoader(name)).withPropertyValues(properties); + } } diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesReactiveDiscoveryClientAutoConfigurationTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesReactiveDiscoveryClientAutoConfigurationTests.java index 58e967d706..cffd95a9a4 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesReactiveDiscoveryClientAutoConfigurationTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesReactiveDiscoveryClientAutoConfigurationTests.java @@ -47,7 +47,8 @@ class KubernetesReactiveDiscoveryClientAutoConfigurationTests { @Test void shouldWorkWithDefaults() { - contextRunner.withPropertyValues("spring.main.cloud-platform=KUBERNETES").run(context -> { + contextRunner.withPropertyValues("spring.main.cloud-platform=KUBERNETES") + .withConfiguration(AutoConfigurations.of(Fabric8DiscoveryClientPredicateAutoConfiguration.class)).run(context -> { assertThat(context).hasSingleBean(ReactiveDiscoveryClient.class); assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class); }); @@ -100,6 +101,7 @@ void worksWithoutWebflux() { @Test void worksWithoutActuator() { contextRunner.withPropertyValues("spring.main.cloud-platform=KUBERNETES") + .withConfiguration(AutoConfigurations.of(Fabric8DiscoveryClientPredicateAutoConfiguration.class)) .withClassLoader(new FilteredClassLoader("org.springframework.boot.actuate")).run(context -> { assertThat(context).hasSingleBean(ReactiveDiscoveryClient.class); assertThat(context).doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class); diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesReactiveDiscoveryClientTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesReactiveDiscoveryClientTests.java index 66974a9824..839fccdd54 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesReactiveDiscoveryClientTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesReactiveDiscoveryClientTests.java @@ -34,7 +34,9 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.springframework.cloud.kubernetes.fabric8.discovery.Fabric8KubernetesReactiveDiscoveryClient; +import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider; +import org.springframework.core.env.Environment; +import org.springframework.mock.env.MockEnvironment; import reactor.core.publisher.Flux; import reactor.test.StepVerifier; @@ -52,213 +54,269 @@ @EnableKubernetesMockClient(crud = true, https = false) class KubernetesReactiveDiscoveryClientTests { -// private static KubernetesMockServer kubernetesServer; -// -// private static KubernetesClient kubernetesClient; -// -// @BeforeEach -// void beforeEach() { -// // Configure the kubernetes master url to point to the mock server -// System.setProperty(Config.KUBERNETES_MASTER_SYSTEM_PROPERTY, -// kubernetesClient.getConfiguration().getMasterUrl()); -// System.setProperty(Config.KUBERNETES_TRUST_CERT_SYSTEM_PROPERTY, "true"); -// System.setProperty(Config.KUBERNETES_AUTH_TRYKUBECONFIG_SYSTEM_PROPERTY, "false"); -// System.setProperty(Config.KUBERNETES_AUTH_TRYSERVICEACCOUNT_SYSTEM_PROPERTY, "false"); -// System.setProperty(Config.KUBERNETES_HTTP2_DISABLE, "true"); -// } -// -// @AfterEach -// void afterEach() { -// kubernetesServer.clearExpectations(); -// } -// -// @Test -// void verifyDefaults() { -// ReactiveDiscoveryClient client = new Fabric8KubernetesReactiveDiscoveryClient(kubernetesClient, -// KubernetesDiscoveryProperties.DEFAULT, KubernetesClient::services); -// assertThat(client.description()).isEqualTo("Kubernetes Reactive Discovery Client"); -// assertThat(client.getOrder()).isEqualTo(ReactiveDiscoveryClient.DEFAULT_ORDER); -// } -// -// @Test -// void shouldReturnFluxOfServices() { -// kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services") -// .andReturn(200, new ServiceListBuilder().addNewItem().withNewMetadata().withName("s1") -// .withLabels(Map.of("label", "value")).endMetadata().endItem().addNewItem().withNewMetadata() -// .withName("s2").withLabels(Map.of("label", "value", "label2", "value2")).endMetadata().endItem() -// .addNewItem().withNewMetadata().withName("s3").endMetadata().endItem().build()) -// .once(); -// ReactiveDiscoveryClient client = new Fabric8KubernetesReactiveDiscoveryClient(kubernetesClient, -// KubernetesDiscoveryProperties.DEFAULT, KubernetesClient::services); -// Flux services = client.getServices(); -// StepVerifier.create(services).expectNext("s1", "s2", "s3").expectComplete().verify(); -// } -// -// @Test -// void shouldReturnEmptyFluxOfServicesWhenNoInstancesFound() { -// kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services") -// .andReturn(200, new ServiceListBuilder().build()).once(); -// -// ReactiveDiscoveryClient client = new Fabric8KubernetesReactiveDiscoveryClient(kubernetesClient, -// KubernetesDiscoveryProperties.DEFAULT, KubernetesClient::services); -// Flux services = client.getServices(); -// StepVerifier.create(services).expectNextCount(0).expectComplete().verify(); -// } -// -// @Test -// void shouldReturnEmptyFluxForNonExistingService() { -// kubernetesServer.expect().get() -// .withPath("/api/v1/namespaces/test/endpoints?fieldSelector=metadata.name%3Dnonexistent-service") -// .andReturn(200, new EndpointsBuilder().build()).once(); -// -// ReactiveDiscoveryClient client = new Fabric8KubernetesReactiveDiscoveryClient(kubernetesClient, -// KubernetesDiscoveryProperties.DEFAULT, KubernetesClient::services); -// Flux instances = client.getInstances("nonexistent-service"); -// StepVerifier.create(instances).expectNextCount(0).expectComplete().verify(); -// } -// -// @Test -// void shouldReturnEmptyFluxWhenServiceHasNoSubsets() { -// kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services") -// .andReturn(200, new ServiceListBuilder().addNewItem().withNewMetadata().withName("existing-service") -// .withLabels(Map.of("label", "value")).endMetadata().endItem().build()) -// .once(); -// -// kubernetesServer.expect().get() -// .withPath("/api/v1/namespaces/test/endpoints?fieldSelector=metadata.name%3Dexisting-service") -// .andReturn(200, new EndpointsBuilder().build()).once(); -// -// ReactiveDiscoveryClient client = new Fabric8KubernetesReactiveDiscoveryClient(kubernetesClient, -// KubernetesDiscoveryProperties.DEFAULT, KubernetesClient::services); -// Flux instances = client.getInstances("existing-service"); -// StepVerifier.create(instances).expectNextCount(0).expectComplete().verify(); -// } -// -// @Test -// void shouldReturnFlux() { -// ServiceList services = new ServiceListBuilder().addNewItem().withNewMetadata().withName("existing-service") -// .withNamespace("test").withLabels(Map.of("label", "value")).endMetadata().endItem().build(); -// -// Endpoints endPoint = new EndpointsBuilder().withNewMetadata().withName("existing-service").withNamespace("test") -// .withLabels(Map.of("label", "value")).endMetadata().addNewSubset().addNewAddress().withIp("ip1") -// .withNewTargetRef().withUid("uid1").endTargetRef().endAddress() -// .addNewPort("http", "http_tcp", 80, "TCP").endSubset().build(); -// -// List endpointsList = new ArrayList<>(); -// endpointsList.add(endPoint); -// -// EndpointsList endpoints = new EndpointsList(); -// endpoints.setItems(endpointsList); -// -// kubernetesServer.expect().get() -// .withPath("/api/v1/namespaces/test/endpoints?fieldSelector=metadata.name%3Dexisting-service") -// .andReturn(200, endpoints).once(); -// -// kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services/existing-service") -// .andReturn(200, services.getItems().get(0)).once(); -// -// Metadata metadata = new Metadata(false, null, false, null, true, "port."); -// ReactiveDiscoveryClient client = new Fabric8KubernetesReactiveDiscoveryClient(kubernetesClient, -// KubernetesDiscoveryProperties.DEFAULT, KubernetesClient::services); -// Flux instances = client.getInstances("existing-service"); -// StepVerifier.create(instances).expectNextCount(1).expectComplete().verify(); -// } -// -// @Test -// void shouldReturnFluxWithPrefixedMetadata() { -// kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services") -// .andReturn(200, new ServiceListBuilder().addNewItem().withNewMetadata().withName("existing-service") -// .withLabels(Map.of("label", "value")).endMetadata().endItem().build()) -// .once(); -// -// Endpoints endPoint = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace("test") -// .endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef().withUid("uid1") -// .endTargetRef().endAddress().addNewPort("http", "http_tcp", 80, "TCP").endSubset().build(); -// -// List endpointsList = new ArrayList<>(); -// endpointsList.add(endPoint); -// -// EndpointsList endpoints = new EndpointsList(); -// endpoints.setItems(endpointsList); -// -// kubernetesServer.expect().get() -// .withPath("/api/v1/namespaces/test/endpoints?fieldSelector=metadata.name%3Dexisting-service") -// .andReturn(200, endpoints).once(); -// -// kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services/existing-service") -// .andReturn(200, new ServiceBuilder().withNewMetadata().withName("existing-service") -// .withLabels(Map.of("label", "value")).endMetadata().build()) -// .once(); -// -// Metadata metadata = new Metadata(true, "label.", true, "annotation.", true, "port."); -// ReactiveDiscoveryClient client = new Fabric8KubernetesReactiveDiscoveryClient(kubernetesClient, -// KubernetesDiscoveryProperties.DEFAULT, KubernetesClient::services); -// Flux instances = client.getInstances("existing-service"); -// StepVerifier.create(instances).expectNextCount(1).expectComplete().verify(); -// } -// -// @Test -// void shouldReturnFluxWhenServiceHasMultiplePortsAndPrimaryPortNameIsSet() { -// kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services") -// .andReturn(200, new ServiceListBuilder().addNewItem().withNewMetadata().withName("existing-service") -// .withLabels(Map.of("label", "value")).endMetadata().endItem().build()) -// .once(); -// -// Endpoints endPoint = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace("test") -// .endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef().withUid("uid1") -// .endTargetRef().endAddress().addNewPort("http", "http_tcp", 80, "TCP") -// .addNewPort("https", "https_tcp", 443, "TCP").endSubset().build(); -// -// List endpointsList = new ArrayList<>(); -// endpointsList.add(endPoint); -// -// EndpointsList endpoints = new EndpointsList(); -// endpoints.setItems(endpointsList); -// -// kubernetesServer.expect().get() -// .withPath("/api/v1/namespaces/test/endpoints?fieldSelector=metadata.name%3Dexisting-service") -// .andReturn(200, endpoints).once(); -// -// kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services/existing-service") -// .andReturn(200, new ServiceBuilder().withNewMetadata().withName("existing-service") -// .withLabels(Map.of("label", "value")).endMetadata().build()) -// .once(); -// -// ReactiveDiscoveryClient client = new Fabric8KubernetesReactiveDiscoveryClient(kubernetesClient, -// KubernetesDiscoveryProperties.DEFAULT, KubernetesClient::services); -// Flux instances = client.getInstances("existing-service"); -// StepVerifier.create(instances).expectNextCount(1).expectComplete().verify(); -// } -// -// @Test -// void shouldReturnFluxOfServicesAcrossAllNamespaces() { -// kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services") -// .andReturn(200, new ServiceListBuilder().addNewItem().withNewMetadata().withName("existing-service") -// .withLabels(Map.of("label", "value")).endMetadata().endItem().build()) -// .once(); -// -// Endpoints endpoints = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace("test") -// .endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef().withUid("uid1") -// .endTargetRef().endAddress().addNewPort("http", "http_tcp", 80, "TCP") -// .addNewPort("https", "https_tcp", 443, "TCP").endSubset().build(); -// -// EndpointsList endpointsList = new EndpointsList(); -// endpointsList.setItems(singletonList(endpoints)); -// -// kubernetesServer.expect().get().withPath("/api/v1/endpoints?fieldSelector=metadata.name%3Dexisting-service") -// .andReturn(200, endpointsList).once(); -// -// kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services/existing-service") -// .andReturn(200, new ServiceBuilder().withNewMetadata().withName("existing-service") -// .withLabels(Map.of("label", "value")).endMetadata().build()) -// .once(); -// -// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, -// false, null, Set.of(), Map.of(), "https_tcp", Metadata.DEFAULT, 0, true); -// ReactiveDiscoveryClient client = new Fabric8KubernetesReactiveDiscoveryClient(kubernetesClient, properties, -// KubernetesClient::services); -// Flux instances = client.getInstances("existing-service"); -// StepVerifier.create(instances).expectNextCount(1).expectComplete().verify(); -// } + private static KubernetesMockServer kubernetesServer; + + private static KubernetesClient kubernetesClient; + + @BeforeEach + void beforeEach() { + // Configure the kubernetes master url to point to the mock server + System.setProperty(Config.KUBERNETES_MASTER_SYSTEM_PROPERTY, + kubernetesClient.getConfiguration().getMasterUrl()); + System.setProperty(Config.KUBERNETES_TRUST_CERT_SYSTEM_PROPERTY, "true"); + System.setProperty(Config.KUBERNETES_AUTH_TRYKUBECONFIG_SYSTEM_PROPERTY, "false"); + System.setProperty(Config.KUBERNETES_AUTH_TRYSERVICEACCOUNT_SYSTEM_PROPERTY, "false"); + System.setProperty(Config.KUBERNETES_HTTP2_DISABLE, "true"); + } + + @AfterEach + void afterEach() { + kubernetesServer.clearExpectations(); + } + + @Test + void verifyDefaults() { + ServicePortSecureResolver servicePortSecureResolver = new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT); + KubernetesNamespaceProvider namespaceProvider = new KubernetesNamespaceProvider(mockEnvironment()); + Fabric8KubernetesDiscoveryClient fabric8KubernetesDiscoveryClient = new Fabric8KubernetesDiscoveryClient( + kubernetesClient, KubernetesDiscoveryProperties.DEFAULT, servicePortSecureResolver, namespaceProvider, + x -> true + ); + ReactiveDiscoveryClient client = new Fabric8KubernetesReactiveDiscoveryClient(fabric8KubernetesDiscoveryClient); + assertThat(client.description()).isEqualTo("Kubernetes Reactive Discovery Client"); + assertThat(client.getOrder()).isEqualTo(ReactiveDiscoveryClient.DEFAULT_ORDER); + } + + @Test + void shouldReturnFluxOfServices() { + kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services") + .andReturn(200, new ServiceListBuilder().addNewItem().withNewMetadata().withName("s1") + .withLabels(Map.of("label", "value")).endMetadata().endItem().addNewItem().withNewMetadata() + .withName("s2").withLabels(Map.of("label", "value", "label2", "value2")).endMetadata().endItem() + .addNewItem().withNewMetadata().withName("s3").endMetadata().endItem().build()) + .once(); + ServicePortSecureResolver servicePortSecureResolver = new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT); + KubernetesNamespaceProvider namespaceProvider = new KubernetesNamespaceProvider(mockEnvironment()); + Fabric8KubernetesDiscoveryClient fabric8KubernetesDiscoveryClient = new Fabric8KubernetesDiscoveryClient( + kubernetesClient, KubernetesDiscoveryProperties.DEFAULT, servicePortSecureResolver, namespaceProvider, + x -> true + ); + ReactiveDiscoveryClient client = new Fabric8KubernetesReactiveDiscoveryClient(fabric8KubernetesDiscoveryClient); + Flux services = client.getServices(); + StepVerifier.create(services).expectNext("s1", "s2", "s3").expectComplete().verify(); + } + + @Test + void shouldReturnEmptyFluxOfServicesWhenNoInstancesFound() { + kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services") + .andReturn(200, new ServiceListBuilder().build()).once(); + + ServicePortSecureResolver servicePortSecureResolver = new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT); + KubernetesNamespaceProvider namespaceProvider = new KubernetesNamespaceProvider(mockEnvironment()); + Fabric8KubernetesDiscoveryClient fabric8KubernetesDiscoveryClient = new Fabric8KubernetesDiscoveryClient( + kubernetesClient, KubernetesDiscoveryProperties.DEFAULT, servicePortSecureResolver, namespaceProvider, + x -> true + ); + ReactiveDiscoveryClient client = new Fabric8KubernetesReactiveDiscoveryClient(fabric8KubernetesDiscoveryClient); + Flux services = client.getServices(); + StepVerifier.create(services).expectNextCount(0).expectComplete().verify(); + } + + @Test + void shouldReturnEmptyFluxForNonExistingService() { + kubernetesServer.expect().get() + .withPath("/api/v1/namespaces/test/endpoints?fieldSelector=metadata.name%3Dnonexistent-service") + .andReturn(200, new EndpointsBuilder().build()).once(); + + ServicePortSecureResolver servicePortSecureResolver = new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT); + KubernetesNamespaceProvider namespaceProvider = new KubernetesNamespaceProvider(mockEnvironment()); + Fabric8KubernetesDiscoveryClient fabric8KubernetesDiscoveryClient = new Fabric8KubernetesDiscoveryClient( + kubernetesClient, KubernetesDiscoveryProperties.DEFAULT, servicePortSecureResolver, namespaceProvider, + x -> true + ); + + ReactiveDiscoveryClient client = new Fabric8KubernetesReactiveDiscoveryClient(fabric8KubernetesDiscoveryClient); + Flux instances = client.getInstances("nonexistent-service"); + StepVerifier.create(instances).expectNextCount(0).expectComplete().verify(); + } + + @Test + void shouldReturnEmptyFluxWhenServiceHasNoSubsets() { + kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services") + .andReturn(200, new ServiceListBuilder().addNewItem().withNewMetadata().withName("existing-service") + .withLabels(Map.of("label", "value")).endMetadata().endItem().build()) + .once(); + + kubernetesServer.expect().get() + .withPath("/api/v1/namespaces/test/endpoints?fieldSelector=metadata.name%3Dexisting-service") + .andReturn(200, new EndpointsBuilder().build()).once(); + + ServicePortSecureResolver servicePortSecureResolver = new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT); + KubernetesNamespaceProvider namespaceProvider = new KubernetesNamespaceProvider(mockEnvironment()); + Fabric8KubernetesDiscoveryClient fabric8KubernetesDiscoveryClient = new Fabric8KubernetesDiscoveryClient( + kubernetesClient, KubernetesDiscoveryProperties.DEFAULT, servicePortSecureResolver, namespaceProvider, + x -> true + ); + + ReactiveDiscoveryClient client = new Fabric8KubernetesReactiveDiscoveryClient(fabric8KubernetesDiscoveryClient); + Flux instances = client.getInstances("existing-service"); + StepVerifier.create(instances).expectNextCount(0).expectComplete().verify(); + } + + @Test + void shouldReturnFlux() { + ServiceList services = new ServiceListBuilder().addNewItem().withNewMetadata().withName("existing-service") + .withNamespace("test").withLabels(Map.of("label", "value")).endMetadata().endItem().build(); + + Endpoints endPoint = new EndpointsBuilder().withNewMetadata().withName("existing-service").withNamespace("test") + .withLabels(Map.of("label", "value")).endMetadata().addNewSubset().addNewAddress().withIp("ip1") + .withNewTargetRef().withUid("uid1").endTargetRef().endAddress() + .addNewPort("http", "http_tcp", 80, "TCP").endSubset().build(); + + List endpointsList = new ArrayList<>(); + endpointsList.add(endPoint); + + EndpointsList endpoints = new EndpointsList(); + endpoints.setItems(endpointsList); + + kubernetesServer.expect().get() + .withPath("/api/v1/namespaces/test/endpoints?fieldSelector=metadata.name%3Dexisting-service") + .andReturn(200, endpoints).once(); + + kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services/existing-service") + .andReturn(200, services.getItems().get(0)).once(); + + ServicePortSecureResolver servicePortSecureResolver = new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT); + KubernetesNamespaceProvider namespaceProvider = new KubernetesNamespaceProvider(mockEnvironment()); + Fabric8KubernetesDiscoveryClient fabric8KubernetesDiscoveryClient = new Fabric8KubernetesDiscoveryClient( + kubernetesClient, KubernetesDiscoveryProperties.DEFAULT, servicePortSecureResolver, namespaceProvider, + x -> true + ); + + //Metadata metadata = new Metadata(false, null, false, null, true, "port."); + ReactiveDiscoveryClient client = new Fabric8KubernetesReactiveDiscoveryClient(fabric8KubernetesDiscoveryClient); + Flux instances = client.getInstances("existing-service"); + StepVerifier.create(instances).expectNextCount(1).expectComplete().verify(); + } + + @Test + void shouldReturnFluxWithPrefixedMetadata() { + kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services") + .andReturn(200, new ServiceListBuilder().addNewItem().withNewMetadata().withName("existing-service") + .withLabels(Map.of("label", "value")).endMetadata().endItem().build()) + .once(); + + Endpoints endPoint = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace("test") + .endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef().withUid("uid1") + .endTargetRef().endAddress().addNewPort("http", "http_tcp", 80, "TCP").endSubset().build(); + + List endpointsList = new ArrayList<>(); + endpointsList.add(endPoint); + + EndpointsList endpoints = new EndpointsList(); + endpoints.setItems(endpointsList); + + kubernetesServer.expect().get() + .withPath("/api/v1/namespaces/test/endpoints?fieldSelector=metadata.name%3Dexisting-service") + .andReturn(200, endpoints).once(); + + kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services/existing-service") + .andReturn(200, new ServiceBuilder().withNewMetadata().withName("existing-service") + .withLabels(Map.of("label", "value")).endMetadata().build()) + .once(); + + ServicePortSecureResolver servicePortSecureResolver = new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT); + KubernetesNamespaceProvider namespaceProvider = new KubernetesNamespaceProvider(mockEnvironment()); + Fabric8KubernetesDiscoveryClient fabric8KubernetesDiscoveryClient = new Fabric8KubernetesDiscoveryClient( + kubernetesClient, KubernetesDiscoveryProperties.DEFAULT, servicePortSecureResolver, namespaceProvider, + x -> true + ); + + ReactiveDiscoveryClient client = new Fabric8KubernetesReactiveDiscoveryClient(fabric8KubernetesDiscoveryClient); + Flux instances = client.getInstances("existing-service"); + StepVerifier.create(instances).expectNextCount(1).expectComplete().verify(); + } + + @Test + void shouldReturnFluxWhenServiceHasMultiplePortsAndPrimaryPortNameIsSet() { + kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services") + .andReturn(200, new ServiceListBuilder().addNewItem().withNewMetadata().withName("existing-service") + .withLabels(Map.of("label", "value")).endMetadata().endItem().build()) + .once(); + + Endpoints endPoint = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace("test") + .endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef().withUid("uid1") + .endTargetRef().endAddress().addNewPort("http", "http_tcp", 80, "TCP") + .addNewPort("https", "https_tcp", 443, "TCP").endSubset().build(); + + List endpointsList = new ArrayList<>(); + endpointsList.add(endPoint); + + EndpointsList endpoints = new EndpointsList(); + endpoints.setItems(endpointsList); + + kubernetesServer.expect().get() + .withPath("/api/v1/namespaces/test/endpoints?fieldSelector=metadata.name%3Dexisting-service") + .andReturn(200, endpoints).once(); + + kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services/existing-service") + .andReturn(200, new ServiceBuilder().withNewMetadata().withName("existing-service") + .withLabels(Map.of("label", "value")).endMetadata().build()) + .once(); + + ServicePortSecureResolver servicePortSecureResolver = new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT); + KubernetesNamespaceProvider namespaceProvider = new KubernetesNamespaceProvider(mockEnvironment()); + Fabric8KubernetesDiscoveryClient fabric8KubernetesDiscoveryClient = new Fabric8KubernetesDiscoveryClient( + kubernetesClient, KubernetesDiscoveryProperties.DEFAULT, servicePortSecureResolver, namespaceProvider, + x -> true + ); + + ReactiveDiscoveryClient client = new Fabric8KubernetesReactiveDiscoveryClient(fabric8KubernetesDiscoveryClient); + Flux instances = client.getInstances("existing-service"); + StepVerifier.create(instances).expectNextCount(1).expectComplete().verify(); + } + + @Test + void shouldReturnFluxOfServicesAcrossAllNamespaces() { + kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services") + .andReturn(200, new ServiceListBuilder().addNewItem().withNewMetadata().withName("existing-service") + .withLabels(Map.of("label", "value")).endMetadata().endItem().build()) + .once(); + + Endpoints endpoints = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace("test") + .endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef().withUid("uid1") + .endTargetRef().endAddress().addNewPort("http", "http_tcp", 80, "TCP") + .addNewPort("https", "https_tcp", 443, "TCP").endSubset().build(); + + EndpointsList endpointsList = new EndpointsList(); + endpointsList.setItems(singletonList(endpoints)); + + kubernetesServer.expect().get().withPath("/api/v1/endpoints?fieldSelector=metadata.name%3Dexisting-service") + .andReturn(200, endpointsList).once(); + + kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services/existing-service") + .andReturn(200, new ServiceBuilder().withNewMetadata().withName("existing-service") + .withLabels(Map.of("label", "value")).endMetadata().build()) + .once(); + + ServicePortSecureResolver servicePortSecureResolver = new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT); + KubernetesNamespaceProvider namespaceProvider = new KubernetesNamespaceProvider(mockEnvironment()); + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, + false, null, Set.of(), Map.of(), "https_tcp", Metadata.DEFAULT, 0, true); + Fabric8KubernetesDiscoveryClient fabric8KubernetesDiscoveryClient = new Fabric8KubernetesDiscoveryClient( + kubernetesClient, properties, servicePortSecureResolver, namespaceProvider, + x -> true + ); + + ReactiveDiscoveryClient client = new Fabric8KubernetesReactiveDiscoveryClient(fabric8KubernetesDiscoveryClient); + Flux instances = client.getInstances("existing-service"); + StepVerifier.create(instances).expectNextCount(1).expectComplete().verify(); + } + + private Environment mockEnvironment() { + MockEnvironment mockEnvironment = new MockEnvironment(); + mockEnvironment.setProperty("spring.cloud.kubernetes.client.namespace", "test"); + return mockEnvironment; + } } diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/ServicePortSecureResolverTest.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/ServicePortSecureResolverTest.java index d390195ba2..f3363afd7c 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/ServicePortSecureResolverTest.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/ServicePortSecureResolverTest.java @@ -56,13 +56,19 @@ void testPortNumbersOnly() { ServicePortSecureResolver secureResolver = new ServicePortSecureResolver(properties); - assertThat(secureResolver.resolve(new ServicePortSecureResolver.Input(null, "dummy"))).isFalse(); - assertThat(secureResolver.resolve(new ServicePortSecureResolver.Input(8080, "dummy"))).isFalse(); - assertThat(secureResolver.resolve(new ServicePortSecureResolver.Input(1234, "dummy"))).isFalse(); - - assertThat(secureResolver.resolve(new ServicePortSecureResolver.Input(443, "dummy"))).isTrue(); - assertThat(secureResolver.resolve(new ServicePortSecureResolver.Input(8443, "dummy"))).isTrue(); - assertThat(secureResolver.resolve(new ServicePortSecureResolver.Input(12345, "dummy"))).isTrue(); + assertThat(secureResolver.resolve(new ServicePortSecureResolver.Input(null, "dummy", Map.of(), Map.of()))) + .isFalse(); + assertThat(secureResolver.resolve(new ServicePortSecureResolver.Input(8080, "dummy", Map.of(), Map.of()))) + .isFalse(); + assertThat(secureResolver.resolve(new ServicePortSecureResolver.Input(1234, "dummy", Map.of(), Map.of()))) + .isFalse(); + + assertThat(secureResolver.resolve(new ServicePortSecureResolver.Input(443, "dummy", Map.of(), Map.of()))) + .isTrue(); + assertThat(secureResolver.resolve(new ServicePortSecureResolver.Input(8443, "dummy", Map.of(), Map.of()))) + .isTrue(); + assertThat(secureResolver.resolve(new ServicePortSecureResolver.Input(12345, "dummy", Map.of(), Map.of()))) + .isTrue(); } @Test From c9ea39e206c471ece9b40c64bdd4adb1a4453bce Mon Sep 17 00:00:00 2001 From: wind57 Date: Sat, 25 Feb 2023 21:19:26 +0200 Subject: [PATCH 025/151] dirty - working on tests --- .../KubernetesInformerAutoConfiguration.java | 1 + ...onditionalOnBlockingOrReactiveEnabled.java | 2 +- ...overyClientPredicateAutoConfiguration.java | 1 + .../KubernetesDiscoveryClientFilterTest.java | 217 ++-- .../KubernetesDiscoveryClientTest.java | 995 +++++++++--------- ...ubernetesReactiveDiscoveryClientTests.java | 43 +- 6 files changed, 641 insertions(+), 618 deletions(-) rename {spring-cloud-kubernetes-client-discovery/src/main/java/org/springframework/cloud/kubernetes/client => spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons}/discovery/ConditionalOnBlockingOrReactiveEnabled.java (96%) diff --git a/spring-cloud-kubernetes-client-discovery/src/main/java/org/springframework/cloud/kubernetes/client/discovery/KubernetesInformerAutoConfiguration.java b/spring-cloud-kubernetes-client-discovery/src/main/java/org/springframework/cloud/kubernetes/client/discovery/KubernetesInformerAutoConfiguration.java index 00b1bf4017..97b31f483b 100644 --- a/spring-cloud-kubernetes-client-discovery/src/main/java/org/springframework/cloud/kubernetes/client/discovery/KubernetesInformerAutoConfiguration.java +++ b/spring-cloud-kubernetes-client-discovery/src/main/java/org/springframework/cloud/kubernetes/client/discovery/KubernetesInformerAutoConfiguration.java @@ -37,6 +37,7 @@ import org.springframework.cloud.client.discovery.simple.SimpleDiscoveryClientAutoConfiguration; import org.springframework.cloud.kubernetes.client.KubernetesClientAutoConfiguration; import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider; +import org.springframework.cloud.kubernetes.commons.discovery.ConditionalOnBlockingOrReactiveEnabled; import org.springframework.cloud.kubernetes.commons.discovery.ConditionalOnKubernetesDiscoveryEnabled; import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryPropertiesAutoConfiguration; diff --git a/spring-cloud-kubernetes-client-discovery/src/main/java/org/springframework/cloud/kubernetes/client/discovery/ConditionalOnBlockingOrReactiveEnabled.java b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/ConditionalOnBlockingOrReactiveEnabled.java similarity index 96% rename from spring-cloud-kubernetes-client-discovery/src/main/java/org/springframework/cloud/kubernetes/client/discovery/ConditionalOnBlockingOrReactiveEnabled.java rename to spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/ConditionalOnBlockingOrReactiveEnabled.java index b89a564b01..7b64425b76 100644 --- a/spring-cloud-kubernetes-client-discovery/src/main/java/org/springframework/cloud/kubernetes/client/discovery/ConditionalOnBlockingOrReactiveEnabled.java +++ b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/ConditionalOnBlockingOrReactiveEnabled.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.cloud.kubernetes.client.discovery; +package org.springframework.cloud.kubernetes.commons.discovery; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryClientPredicateAutoConfiguration.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryClientPredicateAutoConfiguration.java index deb2c4dc9b..2f0f4483fa 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryClientPredicateAutoConfiguration.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryClientPredicateAutoConfiguration.java @@ -23,6 +23,7 @@ import org.springframework.boot.cloud.CloudPlatform; import org.springframework.cloud.client.ConditionalOnBlockingDiscoveryEnabled; import org.springframework.cloud.client.ConditionalOnDiscoveryEnabled; +import org.springframework.cloud.kubernetes.commons.discovery.ConditionalOnBlockingOrReactiveEnabled; import org.springframework.cloud.kubernetes.commons.discovery.ConditionalOnKubernetesDiscoveryEnabled; import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryPropertiesAutoConfiguration; diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientFilterTest.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientFilterTest.java index 9c4d655a8f..351b3e440e 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientFilterTest.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientFilterTest.java @@ -26,113 +26,138 @@ import io.fabric8.kubernetes.api.model.Service; import io.fabric8.kubernetes.api.model.ServiceList; import io.fabric8.kubernetes.client.KubernetesClient; +import io.fabric8.kubernetes.client.dsl.FilterNested; +import io.fabric8.kubernetes.client.dsl.FilterWatchListDeletable; import io.fabric8.kubernetes.client.dsl.MixedOperation; import io.fabric8.kubernetes.client.dsl.ServiceResource; import org.junit.jupiter.api.Test; import org.mockito.Mockito; +import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider; import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; +import org.springframework.core.env.Environment; +import org.springframework.mock.env.MockEnvironment; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.when; +@SuppressWarnings("unchecked") class KubernetesDiscoveryClientFilterTest { -// private final KubernetesClient kubernetesClient = Mockito.mock(KubernetesClient.class); -// -// private final KubernetesClientServicesFunction kubernetesClientServicesFunction = KubernetesClient::services; -// -// private final MixedOperation> serviceOperation = Mockito -// .mock(MixedOperation.class); -// -// @Test -// void testFilteredServices() { -// List springBootServiceNames = Arrays.asList("serviceA", "serviceB"); -// List services = createSpringBootServiceByName(springBootServiceNames); -// -// // Add non spring boot service -// Service service = new Service(); -// ObjectMeta objectMeta = new ObjectMeta(); -// objectMeta.setName("ServiceNonSpringBoot"); -// service.setMetadata(objectMeta); -// services.add(service); -// -// ServiceList serviceList = new ServiceList(); -// serviceList.setItems(services); -// when(this.serviceOperation.list()).thenReturn(serviceList); -// when(this.kubernetesClient.services()).thenReturn(this.serviceOperation); -// -// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, -// false, "metadata.additionalProperties['spring-boot']", Set.of(), Map.of(), null, -// KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, true); -// Fabric8KubernetesDiscoveryClient client = new Fabric8KubernetesDiscoveryClient(this.kubernetesClient, properties, -// this.kubernetesClientServicesFunction); -// -// List filteredServices = client.getServices(); -// assertThat(filteredServices).isEqualTo(springBootServiceNames); -// -// } -// -// @Test -// void testFilteredServicesByPrefix() { -// List springBootServiceNames = Arrays.asList("serviceA", "serviceB", "serviceC"); -// List services = createSpringBootServiceByName(springBootServiceNames); -// -// // Add non spring boot service -// Service service = new Service(); -// ObjectMeta objectMeta = new ObjectMeta(); -// objectMeta.setName("anotherService"); -// service.setMetadata(objectMeta); -// services.add(service); -// -// ServiceList serviceList = new ServiceList(); -// serviceList.setItems(services); -// when(this.serviceOperation.list()).thenReturn(serviceList); -// when(this.kubernetesClient.services()).thenReturn(this.serviceOperation); -// -// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, -// false, "metadata.name.startsWith('service')", Set.of(), Map.of(), null, -// KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, true); -// Fabric8KubernetesDiscoveryClient client = new Fabric8KubernetesDiscoveryClient(this.kubernetesClient, properties, -// this.kubernetesClientServicesFunction); -// -// List filteredServices = client.getServices(); -// assertThat(filteredServices).isEqualTo(springBootServiceNames); -// -// } -// -// @Test -// void testNoExpression() { -// List springBootServiceNames = Arrays.asList("serviceA", "serviceB", "serviceC"); -// List services = createSpringBootServiceByName(springBootServiceNames); -// -// ServiceList serviceList = new ServiceList(); -// serviceList.setItems(services); -// when(this.serviceOperation.list()).thenReturn(serviceList); -// when(this.kubernetesClient.services()).thenReturn(this.serviceOperation); -// -// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, -// false, "", Set.of(), Map.of(), null, KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, true); -// Fabric8KubernetesDiscoveryClient client = new Fabric8KubernetesDiscoveryClient(this.kubernetesClient, properties, -// this.kubernetesClientServicesFunction); -// -// List filteredServices = client.getServices(); -// -// assertThat(filteredServices).isEqualTo(springBootServiceNames); -// -// } -// -// private List createSpringBootServiceByName(List serviceNames) { -// List serviceCollection = new ArrayList<>(serviceNames.size()); -// for (String serviceName : serviceNames) { -// Service service = new Service(); -// ObjectMeta objectMeta = new ObjectMeta(); -// objectMeta.setName(serviceName); -// objectMeta.setAdditionalProperty("spring-boot", "true"); -// service.setMetadata(objectMeta); -// serviceCollection.add(service); -// } -// return serviceCollection; -// } + private static final ServicePortSecureResolver SERVICE_PORT_SECURE_RESOLVER = + new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT); + + private static final KubernetesNamespaceProvider NAMESPACE_PROVIDER = new KubernetesNamespaceProvider(mockEnvironment()); + + private final KubernetesClient kubernetesClient = Mockito.mock(KubernetesClient.class); + + private final MixedOperation> serviceOperation = Mockito + .mock(MixedOperation.class); + + private final FilterNested>> filterNested = Mockito + .mock(FilterNested.class); + + private final FilterWatchListDeletable> filter = Mockito + .mock(FilterWatchListDeletable.class); + + @Test + void testFilteredServices() { + List springBootServiceNames = Arrays.asList("serviceA", "serviceB"); + List services = createSpringBootServiceByName(springBootServiceNames); + + // Add non spring boot service + Service service = new Service(); + ObjectMeta objectMeta = new ObjectMeta(); + objectMeta.setName("ServiceNonSpringBoot"); + service.setMetadata(objectMeta); + services.add(service); + + ServiceList serviceList = new ServiceList(); + serviceList.setItems(services); + when(kubernetesClient.services()).thenReturn(serviceOperation); + when(serviceOperation.inNamespace(Mockito.anyString())).thenReturn(serviceOperation); + when(serviceOperation.withNewFilter()).thenReturn(filterNested); + when(filterNested.withLabels(Mockito.anyMap())).thenReturn(filterNested); + when(filterNested.endFilter()).thenReturn(filter); + when(filter.list()).thenReturn(serviceList); + + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, + false, "metadata.additionalProperties['spring-boot']", Set.of(), Map.of(), null, + KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, true); + Fabric8KubernetesDiscoveryClient client = new Fabric8KubernetesDiscoveryClient(kubernetesClient, properties, + SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true); + + List filteredServices = client.getServices(); + assertThat(filteredServices).isEqualTo(springBootServiceNames); + + } + + @Test + void testFilteredServicesByPrefix() { + List springBootServiceNames = Arrays.asList("serviceA", "serviceB", "serviceC"); + List services = createSpringBootServiceByName(springBootServiceNames); + + // Add non spring boot service + Service service = new Service(); + ObjectMeta objectMeta = new ObjectMeta(); + objectMeta.setName("anotherService"); + service.setMetadata(objectMeta); + services.add(service); + + ServiceList serviceList = new ServiceList(); + serviceList.setItems(services); + when(serviceOperation.list()).thenReturn(serviceList); + when(kubernetesClient.services()).thenReturn(serviceOperation); + + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, + false, "metadata.name.startsWith('service')", Set.of(), Map.of(), null, + KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, true); + Fabric8KubernetesDiscoveryClient client = new Fabric8KubernetesDiscoveryClient(kubernetesClient, properties, + SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true); + + List filteredServices = client.getServices(); + assertThat(filteredServices).isEqualTo(springBootServiceNames); + + } + + @Test + void testNoExpression() { + List springBootServiceNames = Arrays.asList("serviceA", "serviceB", "serviceC"); + List services = createSpringBootServiceByName(springBootServiceNames); + + ServiceList serviceList = new ServiceList(); + serviceList.setItems(services); + when(serviceOperation.list()).thenReturn(serviceList); + when(kubernetesClient.services()).thenReturn(serviceOperation); + + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, + false, "", Set.of(), Map.of(), null, KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, true); + Fabric8KubernetesDiscoveryClient client = new Fabric8KubernetesDiscoveryClient(kubernetesClient, properties, + SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true); + + List filteredServices = client.getServices(); + + assertThat(filteredServices).isEqualTo(springBootServiceNames); + + } + + private List createSpringBootServiceByName(List serviceNames) { + List serviceCollection = new ArrayList<>(serviceNames.size()); + for (String serviceName : serviceNames) { + Service service = new Service(); + ObjectMeta objectMeta = new ObjectMeta(); + objectMeta.setName(serviceName); + objectMeta.setAdditionalProperty("spring-boot", "true"); + service.setMetadata(objectMeta); + serviceCollection.add(service); + } + return serviceCollection; + } + + private static Environment mockEnvironment() { + MockEnvironment environment = new MockEnvironment(); + environment.setProperty("spring.cloud.kubernetes.client.namespace", "test"); + return environment; + } } diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientTest.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientTest.java index db6348c0d1..21a2bc508b 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientTest.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientTest.java @@ -36,8 +36,11 @@ import org.springframework.cloud.client.ServiceInstance; import org.springframework.cloud.client.discovery.DiscoveryClient; +import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider; import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; import org.springframework.cloud.kubernetes.commons.discovery.KubernetesServiceInstance; +import org.springframework.core.env.Environment; +import org.springframework.mock.env.MockEnvironment; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties.Metadata; @@ -45,498 +48,504 @@ @EnableKubernetesMockClient(crud = true, https = false) class KubernetesDiscoveryClientTest { -// private KubernetesClient mockClient; -// -// @BeforeEach -// void setup() { -// // Configure the kubernetes master url to point to the mock server -// System.setProperty(Config.KUBERNETES_MASTER_SYSTEM_PROPERTY, mockClient.getConfiguration().getMasterUrl()); -// System.setProperty(Config.KUBERNETES_TRUST_CERT_SYSTEM_PROPERTY, "true"); -// System.setProperty(Config.KUBERNETES_AUTH_TRYKUBECONFIG_SYSTEM_PROPERTY, "false"); -// System.setProperty(Config.KUBERNETES_AUTH_TRYSERVICEACCOUNT_SYSTEM_PROPERTY, "false"); -// System.setProperty(Config.KUBERNETES_HTTP2_DISABLE, "true"); -// } -// -// @AfterEach -// void afterEach() { -// mockClient.close(); -// } -// -// @Test -// void getInstancesShouldBeAbleToHandleEndpointsSingleAddress() { -// Map labels = Map.of("l", "v"); -// -// Endpoints endPoint = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace("test") -// .withLabels(labels).endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef() -// .withUid("10").endTargetRef().endAddress().addNewPort("http", "http_tcp", 80, "TCP").endSubset() -// .build(); -// -// mockClient.endpoints().inNamespace("test").resource(endPoint).create(); -// -// Service service = new ServiceBuilder().withNewMetadata().withName("endpoint").withNamespace("test") -// .withLabels(labels).endMetadata().build(); -// -// mockClient.services().inNamespace("test").resource(service).create(); -// -// DiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, -// KubernetesDiscoveryProperties.DEFAULT, KubernetesClient::services, null, -// new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT)); -// -// List instances = discoveryClient.getInstances("endpoint"); -// -// assertThat(instances).hasSize(1).filteredOn(s -> s.getHost().equals("ip1") && !s.isSecure()).hasSize(1) -// .filteredOn(s -> s.getInstanceId().equals("10")).hasSize(1); -// } -// -// @Test -// void getInstancesShouldBeAbleToHandleEndpointsSingleAddressAndMultiplePorts() { -// Map labels = Map.of("l2", "v2"); -// -// Endpoints endPoint = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace("test") -// .withLabels(labels).endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef() -// .withUid("20").endTargetRef().endAddress().addNewPort("mgmt", "mgmt_tcp", 900, "TCP") -// .addNewPort("http", "http_tcp", 80, "TCP").endSubset().build(); -// -// mockClient.endpoints().inNamespace("test").resource(endPoint).create(); -// -// Service service = new ServiceBuilder().withNewMetadata().withName("endpoint").withNamespace("test") -// .withLabels(labels).withAnnotations(labels).endMetadata().build(); -// -// mockClient.services().inNamespace("test").resource(service).create(); -// -// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, -// false, null, Set.of(), labels, "http_tcp", Metadata.DEFAULT, 0, true); -// -// DiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, properties, -// KubernetesClient::services, null, new ServicePortSecureResolver(properties)); -// -// List instances = discoveryClient.getInstances("endpoint"); -// -// assertThat(instances).hasSize(1).filteredOn(s -> s.getHost().equals("ip1") && !s.isSecure()).hasSize(1) -// .filteredOn(s -> s.getInstanceId().equals("20")).hasSize(1).filteredOn(s -> 80 == s.getPort()) -// .hasSize(1); -// } -// -// @Test -// void getEndPointsListTest() { -// Map labels = Map.of("l", "v"); -// -// Endpoints endPoint = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace("test") -// .withLabels(labels).endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef() -// .withUid("30").endTargetRef().endAddress().addNewPort("http", "http_tcp", 80, "TCP").endSubset() -// .build(); -// -// mockClient.endpoints().inNamespace("test").resource(endPoint).create(); -// -// Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, -// KubernetesDiscoveryProperties.DEFAULT, KubernetesClient::services, null, -// new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT)); -// -// List result_endpoints = discoveryClient.getEndPointsList("endpoint"); -// -// assertThat(result_endpoints).hasSize(1); -// } -// -// @Test -// void getEndPointsListTestAllNamespaces() { -// -// String namespace1 = "ns1"; -// String namespace2 = "ns2"; -// -// Endpoints endPoint1 = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace(namespace1) -// .endMetadata().build(); -// -// Endpoints endPoint2 = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace(namespace2) -// .endMetadata().build(); -// -// mockClient.endpoints().inNamespace(namespace1).resource(endPoint1).create(); -// mockClient.endpoints().inNamespace(namespace2).resource(endPoint2).create(); -// -// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, -// false, null, Set.of(), Map.of(), null, KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, false); -// -// Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, properties, -// KubernetesClient::services, null, new ServicePortSecureResolver(properties)); -// -// List result_endpoints = discoveryClient.getEndPointsList("endpoint"); -// -// assertThat(result_endpoints).hasSize(2); -// } -// -// @Test -// void getEndPointsListShouldHandleNamespaces() { -// -// String namespace1 = "ns1"; -// String namespace2 = "ns2"; -// String namespace3 = "ns3"; -// -// Endpoints endPoint1 = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace(namespace1) -// .endMetadata().build(); -// Endpoints endPoint2 = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace(namespace2) -// .endMetadata().build(); -// Endpoints endPoint3 = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace(namespace3) -// .endMetadata().build(); -// -// mockClient.endpoints().inNamespace(namespace1).resource(endPoint1).create(); -// mockClient.endpoints().inNamespace(namespace2).resource(endPoint2).create(); -// mockClient.endpoints().inNamespace(namespace3).resource(endPoint3).create(); -// -// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, -// Set.of(namespace1, namespace3), true, 60, false, null, Set.of(), Map.of(), null, -// KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, false); -// -// Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, properties, -// KubernetesClient::services, null, new ServicePortSecureResolver(properties)); -// -// List result_endpoints = discoveryClient.getEndPointsList("endpoint"); -// -// assertThat(result_endpoints).hasSize(2); -// assertThat(result_endpoints.stream().map(Endpoints::getMetadata).map(ObjectMeta::getNamespace) -// .collect(Collectors.toList())).containsOnly(namespace1, namespace3); -// } -// -// @Test -// void getInstancesShouldBeAbleToHandleEndpointsMultipleAddresses() { -// Map labels = Map.of("l1", "v1"); -// -// Endpoints endPoint = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace("test") -// .withLabels(labels).endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef() -// .withUid("40").endTargetRef().endAddress().addNewAddress().withIp("ip2").withNewTargetRef() -// .withUid("50").endTargetRef().endAddress().addNewPort("https", "https_tcp", 443, "TCP").endSubset() -// .build(); -// -// mockClient.endpoints().inNamespace("test").resource(endPoint).create(); -// -// Service service = new ServiceBuilder().withNewMetadata().withName("endpoint").withNamespace("test") -// .withLabels(labels).endMetadata().build(); -// -// mockClient.services().inNamespace("test").resource(service).create(); -// -// Metadata metadata = new Metadata(false, null, false, null, true, "port."); -// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, -// false, null, Set.of(443, 8443), labels, null, metadata, 0, true); -// -// DiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, properties, -// KubernetesClient::services, null, new ServicePortSecureResolver(properties)); -// -// List instances = discoveryClient.getInstances("endpoint"); -// -// assertThat(instances).hasSize(2).filteredOn(ServiceInstance::isSecure).extracting(ServiceInstance::getHost) -// .containsOnly("ip1", "ip2"); -// } -// -// @Test -// void getServicesShouldReturnAllServicesWhenNoLabelsAreAppliedToTheClient() { -// -// Map service1Labels = Collections.singletonMap("label", "value"); -// Service service1 = new ServiceBuilder().withNewMetadata().withName("s1").withNamespace("test") -// .withLabels(service1Labels).endMetadata().build(); -// -// Map service2Labels = Map.of("label", "value", "label2", "value2"); -// Service service2 = new ServiceBuilder().withNewMetadata().withName("s2").withNamespace("test") -// .withLabels(service2Labels).endMetadata().build(); -// -// Service service3 = new ServiceBuilder().withNewMetadata().withName("s3").withNamespace("test").endMetadata() -// .build(); -// mockClient.services().inNamespace("test").resource(service1).create(); -// mockClient.services().inNamespace("test").resource(service2).create(); -// mockClient.services().inNamespace("test").resource(service3).create(); -// -// DiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, -// KubernetesDiscoveryProperties.DEFAULT, KubernetesClient::services, null, -// new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT)); -// -// List services = discoveryClient.getServices(); -// -// assertThat(services).containsOnly("s1", "s2", "s3"); -// } -// -// @Test -// void getServicesShouldReturnOnlyMatchingServicesWhenLabelsAreAppliedToTheClient() { -// -// Map service1Labels = Collections.singletonMap("label", "value"); -// Service service1 = new ServiceBuilder().withNewMetadata().withName("s1").withNamespace("test") -// .withLabels(service1Labels).endMetadata().build(); -// -// Map service2Labels = Map.of("label", "value", "label2", "value2"); -// Service service2 = new ServiceBuilder().withNewMetadata().withName("s2").withNamespace("test") -// .withLabels(service2Labels).endMetadata().build(); -// -// mockClient.services().inNamespace("test").resource(service1).create(); -// mockClient.services().inNamespace("test").resource(service2).create(); -// -// DiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, -// KubernetesDiscoveryProperties.DEFAULT, -// client -> client.services().withLabels(Collections.singletonMap("label", "value")), null, -// new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT)); -// -// List services = discoveryClient.getServices(); -// -// assertThat(services).containsOnly("s1", "s2"); -// } -// -// @Test -// void getServicesShouldReturnServicesInNamespaces() { -// -// String nameSpace1 = "ns1"; -// String nameSpace2 = "ns2"; -// String nameSpace3 = "ns3"; -// -// Service service1 = new ServiceBuilder().withNewMetadata().withName("s1").withNamespace(nameSpace1).endMetadata() -// .build(); -// -// Service service2 = new ServiceBuilder().withNewMetadata().withName("s2").withNamespace(nameSpace2).endMetadata() -// .build(); -// -// Service service3 = new ServiceBuilder().withNewMetadata().withName("s3").withNamespace(nameSpace3).endMetadata() -// .build(); -// -// mockClient.services().inNamespace(nameSpace1).resource(service1).create(); -// mockClient.services().inNamespace(nameSpace2).resource(service2).create(); -// mockClient.services().inNamespace(nameSpace3).resource(service3).create(); -// -// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, -// Set.of(nameSpace1, nameSpace2), true, 60, false, null, Set.of(), Map.of(), null, -// KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, false); -// -// DiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, properties, -// KubernetesClient::services, null, new ServicePortSecureResolver(properties)); -// -// List services = discoveryClient.getServices(); -// -// assertThat(services).containsOnly("s1", "s2"); -// } -// -// @Test -// void getInstancesShouldBeAbleToHandleEndpointsFromMultipleNamespaces() { -// Endpoints endPoints1 = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace("test") -// .endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef().withUid("60") -// .endTargetRef().endAddress().addNewPort("http", "http_tcp", 80, "TCP").endSubset().build(); -// -// Endpoints endPoints2 = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace("test2") -// .endMetadata().addNewSubset().addNewAddress().withIp("ip2").withNewTargetRef().withUid("70") -// .endTargetRef().endAddress().addNewPort("http", "http_tcp", 80, "TCP").endSubset().build(); -// -// mockClient.endpoints().inNamespace("test").resource(endPoints1).create(); -// mockClient.endpoints().inNamespace("test2").resource(endPoints2).create(); -// -// Service service1 = new ServiceBuilder().withNewMetadata().withName("endpoint").withNamespace("test") -// .withLabels(Collections.singletonMap("l", "v")).endMetadata().build(); -// -// Service service2 = new ServiceBuilder().withNewMetadata().withName("endpoint").withNamespace("test2") -// .withLabels(Collections.singletonMap("l", "v")).endMetadata().build(); -// -// mockClient.services().inNamespace("test").resource(service1).create(); -// mockClient.services().inNamespace("test2").resource(service2).create(); -// -// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, -// false, null, Set.of(), Map.of(), null, Metadata.DEFAULT, 0, true); -// -// DiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, properties, -// KubernetesClient::services, null, new ServicePortSecureResolver(properties)); -// -// List instances = discoveryClient.getInstances("endpoint"); -// -// assertThat(instances).hasSize(2); -// assertThat(instances).filteredOn(s -> s.getHost().equals("ip1") && !s.isSecure()).hasSize(1); -// assertThat(instances).filteredOn(s -> s.getHost().equals("ip2") && !s.isSecure()).hasSize(1); -// assertThat(instances).filteredOn(s -> s.getServiceId().contains("endpoint") -// && ((KubernetesServiceInstance) s).getNamespace().equals("test")).hasSize(1); -// assertThat(instances).filteredOn(s -> s.getServiceId().contains("endpoint") -// && ((KubernetesServiceInstance) s).getNamespace().equals("test2")).hasSize(1); -// assertThat(instances).filteredOn(s -> s.getInstanceId().equals("60")).hasSize(1); -// assertThat(instances).filteredOn(s -> s.getInstanceId().equals("70")).hasSize(1); -// } -// -// @Test -// void instanceWithoutPortsShouldBeSkipped() { -// Endpoints endPoint = new EndpointsBuilder().withNewMetadata().withName("endpoint1").withNamespace("test") -// .withLabels(Collections.emptyMap()).endMetadata().build(); -// -// mockClient.endpoints().inNamespace("test").resource(endPoint).create(); -// -// Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, -// KubernetesDiscoveryProperties.DEFAULT, KubernetesClient::services, null, -// new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT)); -// -// List instances = discoveryClient.getInstances("endpoint1"); -// -// assertThat(instances).isEmpty(); -// } -// -// @Test -// void getInstancesShouldBeAbleToHandleEndpointsSingleAddressAndMultiplePortsUsingPrimaryPortNameLabel() { -// Map labels = Map.of("primary-port-name", "https"); -// -// Endpoints endPoint1 = new EndpointsBuilder().withNewMetadata().withName("endpoint2").withNamespace("test") -// .withLabels(labels).endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef() -// .withUid("80").endTargetRef().endAddress().addNewPort("http", "https", 443, "TCP") -// .addNewPort("http", "http", 80, "TCP").endSubset().build(); -// -// mockClient.endpoints().inNamespace("test").resource(endPoint1).create(); -// -// Service service = new ServiceBuilder().withNewMetadata().withName("endpoint2").withNamespace("test") -// .withLabels(labels).withAnnotations(labels).endMetadata().build(); -// -// mockClient.services().inNamespace("test").resource(service).create(); -// -// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, -// false, null, Set.of(443, 8443), Map.of(), null, Metadata.DEFAULT, 0, true); -// -// DiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, properties, -// KubernetesClient::services, null, new ServicePortSecureResolver(properties)); -// -// List instances = discoveryClient.getInstances("endpoint2"); -// -// assertThat(instances).hasSize(1).filteredOn(s -> s.getHost().equals("ip1") && s.isSecure()).hasSize(1) -// .filteredOn(s -> s.getInstanceId().equals("80")).hasSize(1).filteredOn(s -> 443 == s.getPort()) -// .hasSize(1); -// } -// -// @Test -// void instanceWithMultiplePortsAndMisconfiguredPrimaryPortNameInLabelWithoutFallbackShouldLogWarning() { -// Map labels = Map.of("primary-port-name", "oops"); -// -// Endpoints endPoint1 = new EndpointsBuilder().withNewMetadata().withName("endpoint3").withNamespace("test") -// .withLabels(labels).endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef() -// .withUid("90").endTargetRef().endAddress().addNewPort("http", "https1", 443, "TCP") -// .addNewPort("http", "https2", 8443, "TCP").addNewPort("http", "http1", 80, "TCP") -// .addNewPort("http", "http2", 8080, "TCP").endSubset().build(); -// -// mockClient.endpoints().inNamespace("test").resource(endPoint1).create(); -// -// Service service = new ServiceBuilder().withNewMetadata().withName("endpoint3").withNamespace("test") -// .withLabels(labels).withAnnotations(labels).endMetadata().build(); -// -// mockClient.services().inNamespace("test").resource(service).create(); -// -// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, -// false, null, Set.of(443, 8443), Map.of(), null, Metadata.DEFAULT, 0, true); -// -// DiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, properties, -// KubernetesClient::services, null, new ServicePortSecureResolver(properties)); -// -// List instances = discoveryClient.getInstances("endpoint3"); -// -// assertThat(instances).hasSize(1).filteredOn(s -> s.getHost().equals("ip1") && s.isSecure()).hasSize(1) -// .filteredOn(s -> s.getInstanceId().equals("90")).hasSize(1).filteredOn(s -> 443 == s.getPort()) -// .hasSize(1); -// } -// -// @Test -// void instanceWithMultiplePortsAndMisconfiguredGenericPrimaryPortNameWithoutFallbackShouldLogWarning() { -// Map labels = Map.of(); -// -// Endpoints endPoint1 = new EndpointsBuilder().withNewMetadata().withName("endpoint4").withNamespace("test") -// .withLabels(labels).endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef() -// .withUid("100").endTargetRef().endAddress().addNewPort("http", "https1", 443, "TCP") -// .addNewPort("http", "https2", 8443, "TCP").addNewPort("http", "http1", 80, "TCP") -// .addNewPort("http", "http2", 8080, "TCP").endSubset().build(); -// -// mockClient.endpoints().inNamespace("test").resource(endPoint1).create(); -// -// Service service = new ServiceBuilder().withNewMetadata().withName("endpoint4").withNamespace("test") -// .withLabels(labels).withAnnotations(labels).endMetadata().build(); -// -// mockClient.services().inNamespace("test").resource(service).create(); -// -// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, -// false, null, Set.of(443, 8443), Map.of(), "oops", Metadata.DEFAULT, 0, true); -// -// DiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, properties, -// KubernetesClient::services, null, new ServicePortSecureResolver(properties)); -// -// List instances = discoveryClient.getInstances("endpoint4"); -// -// assertThat(instances).hasSize(1).filteredOn(s -> s.getHost().equals("ip1") && s.isSecure()).hasSize(1) -// .filteredOn(s -> s.getInstanceId().equals("100")).hasSize(1).filteredOn(s -> 443 == s.getPort()) -// .hasSize(1); -// } -// -// @Test -// void instanceWithMultiplePortsAndWithoutPrimaryPortNameSpecifiedShouldFallBackToHttps() { -// Map labels = Map.of(); -// -// Endpoints endPoint1 = new EndpointsBuilder().withNewMetadata().withName("endpoint5").withNamespace("test") -// .withLabels(labels).endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef() -// .withUid("110").endTargetRef().endAddress().addNewPort("http", "https", 443, "TCP") -// .addNewPort("http", "http", 80, "TCP").endSubset().build(); -// -// mockClient.endpoints().inNamespace("test").resource(endPoint1).create(); -// -// Service service = new ServiceBuilder().withNewMetadata().withName("endpoint5").withNamespace("test") -// .withLabels(labels).withAnnotations(labels).endMetadata().build(); -// -// mockClient.services().inNamespace("test").resource(service).create(); -// -// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, -// false, null, Set.of(443, 8443), Map.of(), null, Metadata.DEFAULT, 0, true); -// -// DiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, properties, -// KubernetesClient::services, null, new ServicePortSecureResolver(properties)); -// -// List instances = discoveryClient.getInstances("endpoint5"); -// -// assertThat(instances).hasSize(1).filteredOn(s -> s.getHost().equals("ip1") && s.isSecure()).hasSize(1) -// .filteredOn(s -> s.getInstanceId().equals("110")).hasSize(1).filteredOn(s -> 443 == s.getPort()) -// .hasSize(1); -// } -// -// @Test -// void instanceWithMultiplePortsAndWithoutPrimaryPortNameSpecifiedOrHttpsPortShouldFallBackToHttp() { -// Map labels = Map.of(); -// -// Endpoints endPoint1 = new EndpointsBuilder().withNewMetadata().withName("endpoint5").withNamespace("test") -// .withLabels(labels).endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef() -// .withUid("120").endTargetRef().endAddress().addNewPort("http", "https1", 443, "TCP") -// .addNewPort("http", "https2", 8443, "TCP").addNewPort("http", "http", 80, "TCP").endSubset().build(); -// -// mockClient.endpoints().inNamespace("test").resource(endPoint1).create(); -// -// Service service = new ServiceBuilder().withNewMetadata().withName("endpoint5").withNamespace("test") -// .withLabels(labels).withAnnotations(labels).endMetadata().build(); -// -// mockClient.services().inNamespace("test").resource(service).create(); -// -// DiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, -// KubernetesDiscoveryProperties.DEFAULT, KubernetesClient::services, null, -// new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT)); -// -// List instances = discoveryClient.getInstances("endpoint5"); -// -// assertThat(instances).hasSize(1).filteredOn(s -> s.getHost().equals("ip1") && !s.isSecure()).hasSize(1) -// .filteredOn(s -> s.getInstanceId().equals("120")).hasSize(1).filteredOn(s -> 80 == s.getPort()) -// .hasSize(1); -// } -// -// @Test -// void instanceWithMultiplePortsAndWithoutPrimaryPortNameSpecifiedShouldLogWarning() { -// Map labels = Map.of(); -// -// Endpoints endPoint1 = new EndpointsBuilder().withNewMetadata().withName("endpoint5").withNamespace("test") -// .withLabels(labels).endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef() -// .withUid("130").endTargetRef().endAddress().addNewPort("http", "https", 443, "TCP") -// .addNewPort("http", "http", 80, "TCP").endSubset().build(); -// -// mockClient.endpoints().inNamespace("test").resource(endPoint1).create(); -// -// Service service = new ServiceBuilder().withNewMetadata().withName("endpoint5").withNamespace("test") -// .withLabels(labels).withAnnotations(labels).endMetadata().build(); -// -// mockClient.services().inNamespace("test").resource(service).create(); -// -// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, -// true, null, Set.of(443, 8443), Map.of(), null, Metadata.DEFAULT, 0, true); -// -// DiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, properties, -// KubernetesClient::services, null, new ServicePortSecureResolver(properties)); -// -// List instances = discoveryClient.getInstances("endpoint5"); -// -// // We're returning the first discovered port to not change previous behaviour -// assertThat(instances).hasSize(1).filteredOn(s -> s.getHost().equals("ip1") && s.isSecure()).hasSize(1) -// .filteredOn(s -> s.getInstanceId().equals("130")).hasSize(1).filteredOn(s -> 443 == s.getPort()) -// .hasSize(1); -// } + private static final ServicePortSecureResolver SERVICE_PORT_SECURE_RESOLVER = + new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT); + + private static final KubernetesNamespaceProvider NAMESPACE_PROVIDER = new KubernetesNamespaceProvider(mockEnvironment()); + + private KubernetesClient mockClient; + + @BeforeEach + void setup() { + // Configure the kubernetes master url to point to the mock server + System.setProperty(Config.KUBERNETES_MASTER_SYSTEM_PROPERTY, mockClient.getConfiguration().getMasterUrl()); + System.setProperty(Config.KUBERNETES_TRUST_CERT_SYSTEM_PROPERTY, "true"); + System.setProperty(Config.KUBERNETES_AUTH_TRYKUBECONFIG_SYSTEM_PROPERTY, "false"); + System.setProperty(Config.KUBERNETES_AUTH_TRYSERVICEACCOUNT_SYSTEM_PROPERTY, "false"); + System.setProperty(Config.KUBERNETES_HTTP2_DISABLE, "true"); + } + + @AfterEach + void afterEach() { + mockClient.close(); + } + + @Test + void getInstancesShouldBeAbleToHandleEndpointsSingleAddress() { + Map labels = Map.of("l", "v"); + + Endpoints endPoint = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace("test") + .withLabels(labels).endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef() + .withUid("10").endTargetRef().endAddress().addNewPort("http", "http_tcp", 80, "TCP").endSubset() + .build(); + + mockClient.endpoints().inNamespace("test").resource(endPoint).create(); + + Service service = new ServiceBuilder().withNewMetadata().withName("endpoint").withNamespace("test") + .withLabels(labels).endMetadata().build(); + + mockClient.services().inNamespace("test").resource(service).create(); + + DiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, + KubernetesDiscoveryProperties.DEFAULT, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true); + + List instances = discoveryClient.getInstances("endpoint"); + + assertThat(instances).hasSize(1).filteredOn(s -> s.getHost().equals("ip1") && !s.isSecure()).hasSize(1) + .filteredOn(s -> s.getInstanceId().equals("10")).hasSize(1); + } + + @Test + void getInstancesShouldBeAbleToHandleEndpointsSingleAddressAndMultiplePorts() { + Map labels = Map.of("l2", "v2"); + + Endpoints endPoint = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace("test") + .withLabels(labels).endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef() + .withUid("20").endTargetRef().endAddress().addNewPort("mgmt", "mgmt_tcp", 900, "TCP") + .addNewPort("http", "http_tcp", 80, "TCP").endSubset().build(); + + mockClient.endpoints().inNamespace("test").resource(endPoint).create(); + + Service service = new ServiceBuilder().withNewMetadata().withName("endpoint").withNamespace("test") + .withLabels(labels).withAnnotations(labels).endMetadata().build(); + + mockClient.services().inNamespace("test").resource(service).create(); + + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, + false, null, Set.of(), labels, "http_tcp", Metadata.DEFAULT, 0, true); + + DiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, + properties, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true); + + List instances = discoveryClient.getInstances("endpoint"); + + assertThat(instances).hasSize(1).filteredOn(s -> s.getHost().equals("ip1") && !s.isSecure()).hasSize(1) + .filteredOn(s -> s.getInstanceId().equals("20")).hasSize(1).filteredOn(s -> 80 == s.getPort()) + .hasSize(1); + } + + @Test + void getEndPointsListTest() { + Map labels = Map.of("l", "v"); + + Endpoints endPoint = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace("test") + .withLabels(labels).endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef() + .withUid("30").endTargetRef().endAddress().addNewPort("http", "http_tcp", 80, "TCP").endSubset() + .build(); + + mockClient.endpoints().inNamespace("test").resource(endPoint).create(); + + ServicePortSecureResolver servicePortSecureResolver = new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT); + KubernetesNamespaceProvider namespaceProvider = new KubernetesNamespaceProvider(mockEnvironment()); + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, + KubernetesDiscoveryProperties.DEFAULT, servicePortSecureResolver, namespaceProvider, x -> true); + + List result_endpoints = discoveryClient.getEndPointsList("endpoint"); + + assertThat(result_endpoints).hasSize(1); + } + + @Test + void getEndPointsListTestAllNamespaces() { + + String namespace1 = "ns1"; + String namespace2 = "ns2"; + + Endpoints endPoint1 = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace(namespace1) + .endMetadata().build(); + + Endpoints endPoint2 = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace(namespace2) + .endMetadata().build(); + + mockClient.endpoints().inNamespace(namespace1).resource(endPoint1).create(); + mockClient.endpoints().inNamespace(namespace2).resource(endPoint2).create(); + + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, + false, null, Set.of(), Map.of(), null, KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, false); + + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, + properties, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true); + + List result_endpoints = discoveryClient.getEndPointsList("endpoint"); + + assertThat(result_endpoints).hasSize(2); + } + + @Test + void getEndPointsListShouldHandleNamespaces() { + + String namespace1 = "ns1"; + String namespace2 = "ns2"; + String namespace3 = "ns3"; + + Endpoints endPoint1 = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace(namespace1) + .endMetadata().build(); + Endpoints endPoint2 = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace(namespace2) + .endMetadata().build(); + Endpoints endPoint3 = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace(namespace3) + .endMetadata().build(); + + mockClient.endpoints().inNamespace(namespace1).resource(endPoint1).create(); + mockClient.endpoints().inNamespace(namespace2).resource(endPoint2).create(); + mockClient.endpoints().inNamespace(namespace3).resource(endPoint3).create(); + + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, + Set.of(namespace1, namespace3), true, 60, false, null, Set.of(), Map.of(), null, + KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, false); + + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, + properties, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true); + + List result_endpoints = discoveryClient.getEndPointsList("endpoint"); + + assertThat(result_endpoints).hasSize(2); + assertThat(result_endpoints.stream().map(Endpoints::getMetadata).map(ObjectMeta::getNamespace) + .collect(Collectors.toList())).containsOnly(namespace1, namespace3); + } + + @Test + void getInstancesShouldBeAbleToHandleEndpointsMultipleAddresses() { + Map labels = Map.of("l1", "v1"); + + Endpoints endPoint = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace("test") + .withLabels(labels).endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef() + .withUid("40").endTargetRef().endAddress().addNewAddress().withIp("ip2").withNewTargetRef() + .withUid("50").endTargetRef().endAddress().addNewPort("https", "https_tcp", 443, "TCP").endSubset() + .build(); + + mockClient.endpoints().inNamespace("test").resource(endPoint).create(); + + Service service = new ServiceBuilder().withNewMetadata().withName("endpoint").withNamespace("test") + .withLabels(labels).endMetadata().build(); + + mockClient.services().inNamespace("test").resource(service).create(); + + Metadata metadata = new Metadata(false, null, false, null, true, "port."); + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, + false, null, Set.of(443, 8443), labels, null, metadata, 0, true); + + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, + properties, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true); + + List instances = discoveryClient.getInstances("endpoint"); + + assertThat(instances).hasSize(2).filteredOn(ServiceInstance::isSecure).extracting(ServiceInstance::getHost) + .containsOnly("ip1", "ip2"); + } + + @Test + void getServicesShouldReturnAllServicesWhenNoLabelsAreAppliedToTheClient() { + + Map service1Labels = Collections.singletonMap("label", "value"); + Service service1 = new ServiceBuilder().withNewMetadata().withName("s1").withNamespace("test") + .withLabels(service1Labels).endMetadata().build(); + + Map service2Labels = Map.of("label", "value", "label2", "value2"); + Service service2 = new ServiceBuilder().withNewMetadata().withName("s2").withNamespace("test") + .withLabels(service2Labels).endMetadata().build(); + + Service service3 = new ServiceBuilder().withNewMetadata().withName("s3").withNamespace("test").endMetadata() + .build(); + mockClient.services().inNamespace("test").resource(service1).create(); + mockClient.services().inNamespace("test").resource(service2).create(); + mockClient.services().inNamespace("test").resource(service3).create(); + + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, + KubernetesDiscoveryProperties.DEFAULT, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true); + + List services = discoveryClient.getServices(); + + assertThat(services).containsOnly("s1", "s2", "s3"); + } + + @Test + void getServicesShouldReturnOnlyMatchingServicesWhenLabelsAreAppliedToTheClient() { + + Map service1Labels = Collections.singletonMap("label", "value"); + Service service1 = new ServiceBuilder().withNewMetadata().withName("s1").withNamespace("test") + .withLabels(service1Labels).endMetadata().build(); + + Map service2Labels = Map.of("label", "value", "label2", "value2"); + Service service2 = new ServiceBuilder().withNewMetadata().withName("s2").withNamespace("test") + .withLabels(service2Labels).endMetadata().build(); + + mockClient.services().inNamespace("test").resource(service1).create(); + mockClient.services().inNamespace("test").resource(service2).create(); + + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, + KubernetesDiscoveryProperties.DEFAULT, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true); + + List services = discoveryClient.getServices(); + + assertThat(services).containsOnly("s1", "s2"); + } + + @Test + void getServicesShouldReturnServicesInNamespaces() { + + String nameSpace1 = "ns1"; + String nameSpace2 = "ns2"; + String nameSpace3 = "ns3"; + + Service service1 = new ServiceBuilder().withNewMetadata().withName("s1").withNamespace(nameSpace1).endMetadata() + .build(); + + Service service2 = new ServiceBuilder().withNewMetadata().withName("s2").withNamespace(nameSpace2).endMetadata() + .build(); + + Service service3 = new ServiceBuilder().withNewMetadata().withName("s3").withNamespace(nameSpace3).endMetadata() + .build(); + + mockClient.services().inNamespace(nameSpace1).resource(service1).create(); + mockClient.services().inNamespace(nameSpace2).resource(service2).create(); + mockClient.services().inNamespace(nameSpace3).resource(service3).create(); + + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, + Set.of(nameSpace1, nameSpace2), true, 60, false, null, Set.of(), Map.of(), null, + KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, false); + + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, + properties, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true); + + List services = discoveryClient.getServices(); + + assertThat(services).containsOnly("s1", "s2"); + } + + @Test + void getInstancesShouldBeAbleToHandleEndpointsFromMultipleNamespaces() { + Endpoints endPoints1 = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace("test") + .endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef().withUid("60") + .endTargetRef().endAddress().addNewPort("http", "http_tcp", 80, "TCP").endSubset().build(); + + Endpoints endPoints2 = new EndpointsBuilder().withNewMetadata().withName("endpoint").withNamespace("test2") + .endMetadata().addNewSubset().addNewAddress().withIp("ip2").withNewTargetRef().withUid("70") + .endTargetRef().endAddress().addNewPort("http", "http_tcp", 80, "TCP").endSubset().build(); + + mockClient.endpoints().inNamespace("test").resource(endPoints1).create(); + mockClient.endpoints().inNamespace("test2").resource(endPoints2).create(); + + Service service1 = new ServiceBuilder().withNewMetadata().withName("endpoint").withNamespace("test") + .withLabels(Collections.singletonMap("l", "v")).endMetadata().build(); + + Service service2 = new ServiceBuilder().withNewMetadata().withName("endpoint").withNamespace("test2") + .withLabels(Collections.singletonMap("l", "v")).endMetadata().build(); + + mockClient.services().inNamespace("test").resource(service1).create(); + mockClient.services().inNamespace("test2").resource(service2).create(); + + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, + false, null, Set.of(), Map.of(), null, Metadata.DEFAULT, 0, true); + + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, + properties, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true); + + List instances = discoveryClient.getInstances("endpoint"); + + assertThat(instances).hasSize(2); + assertThat(instances).filteredOn(s -> s.getHost().equals("ip1") && !s.isSecure()).hasSize(1); + assertThat(instances).filteredOn(s -> s.getHost().equals("ip2") && !s.isSecure()).hasSize(1); + assertThat(instances).filteredOn(s -> s.getServiceId().contains("endpoint") + && ((KubernetesServiceInstance) s).getNamespace().equals("test")).hasSize(1); + assertThat(instances).filteredOn(s -> s.getServiceId().contains("endpoint") + && ((KubernetesServiceInstance) s).getNamespace().equals("test2")).hasSize(1); + assertThat(instances).filteredOn(s -> s.getInstanceId().equals("60")).hasSize(1); + assertThat(instances).filteredOn(s -> s.getInstanceId().equals("70")).hasSize(1); + } + + @Test + void instanceWithoutPortsShouldBeSkipped() { + Endpoints endPoint = new EndpointsBuilder().withNewMetadata().withName("endpoint1").withNamespace("test") + .withLabels(Collections.emptyMap()).endMetadata().build(); + + mockClient.endpoints().inNamespace("test").resource(endPoint).create(); + + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, + KubernetesDiscoveryProperties.DEFAULT, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true); + + List instances = discoveryClient.getInstances("endpoint1"); + + assertThat(instances).isEmpty(); + } + + @Test + void getInstancesShouldBeAbleToHandleEndpointsSingleAddressAndMultiplePortsUsingPrimaryPortNameLabel() { + Map labels = Map.of("primary-port-name", "https"); + + Endpoints endPoint1 = new EndpointsBuilder().withNewMetadata().withName("endpoint2").withNamespace("test") + .withLabels(labels).endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef() + .withUid("80").endTargetRef().endAddress().addNewPort("http", "https", 443, "TCP") + .addNewPort("http", "http", 80, "TCP").endSubset().build(); + + mockClient.endpoints().inNamespace("test").resource(endPoint1).create(); + + Service service = new ServiceBuilder().withNewMetadata().withName("endpoint2").withNamespace("test") + .withLabels(labels).withAnnotations(labels).endMetadata().build(); + + mockClient.services().inNamespace("test").resource(service).create(); + + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, + false, null, Set.of(443, 8443), Map.of(), null, Metadata.DEFAULT, 0, true); + + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, + properties, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true); + + List instances = discoveryClient.getInstances("endpoint2"); + + assertThat(instances).hasSize(1).filteredOn(s -> s.getHost().equals("ip1") && s.isSecure()).hasSize(1) + .filteredOn(s -> s.getInstanceId().equals("80")).hasSize(1).filteredOn(s -> 443 == s.getPort()) + .hasSize(1); + } + + @Test + void instanceWithMultiplePortsAndMisconfiguredPrimaryPortNameInLabelWithoutFallbackShouldLogWarning() { + Map labels = Map.of("primary-port-name", "oops"); + + Endpoints endPoint1 = new EndpointsBuilder().withNewMetadata().withName("endpoint3").withNamespace("test") + .withLabels(labels).endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef() + .withUid("90").endTargetRef().endAddress().addNewPort("http", "https1", 443, "TCP") + .addNewPort("http", "https2", 8443, "TCP").addNewPort("http", "http1", 80, "TCP") + .addNewPort("http", "http2", 8080, "TCP").endSubset().build(); + + mockClient.endpoints().inNamespace("test").resource(endPoint1).create(); + + Service service = new ServiceBuilder().withNewMetadata().withName("endpoint3").withNamespace("test") + .withLabels(labels).withAnnotations(labels).endMetadata().build(); + + mockClient.services().inNamespace("test").resource(service).create(); + + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, + false, null, Set.of(443, 8443), Map.of(), null, Metadata.DEFAULT, 0, true); + + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, + properties, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true); + + List instances = discoveryClient.getInstances("endpoint3"); + + assertThat(instances).hasSize(1).filteredOn(s -> s.getHost().equals("ip1") && s.isSecure()).hasSize(1) + .filteredOn(s -> s.getInstanceId().equals("90")).hasSize(1).filteredOn(s -> 443 == s.getPort()) + .hasSize(1); + } + + @Test + void instanceWithMultiplePortsAndMisconfiguredGenericPrimaryPortNameWithoutFallbackShouldLogWarning() { + Map labels = Map.of(); + + Endpoints endPoint1 = new EndpointsBuilder().withNewMetadata().withName("endpoint4").withNamespace("test") + .withLabels(labels).endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef() + .withUid("100").endTargetRef().endAddress().addNewPort("http", "https1", 443, "TCP") + .addNewPort("http", "https2", 8443, "TCP").addNewPort("http", "http1", 80, "TCP") + .addNewPort("http", "http2", 8080, "TCP").endSubset().build(); + + mockClient.endpoints().inNamespace("test").resource(endPoint1).create(); + + Service service = new ServiceBuilder().withNewMetadata().withName("endpoint4").withNamespace("test") + .withLabels(labels).withAnnotations(labels).endMetadata().build(); + + mockClient.services().inNamespace("test").resource(service).create(); + + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, + false, null, Set.of(443, 8443), Map.of(), "oops", Metadata.DEFAULT, 0, true); + + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, + properties, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true); + + List instances = discoveryClient.getInstances("endpoint4"); + + assertThat(instances).hasSize(1).filteredOn(s -> s.getHost().equals("ip1") && s.isSecure()).hasSize(1) + .filteredOn(s -> s.getInstanceId().equals("100")).hasSize(1).filteredOn(s -> 443 == s.getPort()) + .hasSize(1); + } + + @Test + void instanceWithMultiplePortsAndWithoutPrimaryPortNameSpecifiedShouldFallBackToHttps() { + Map labels = Map.of(); + + Endpoints endPoint1 = new EndpointsBuilder().withNewMetadata().withName("endpoint5").withNamespace("test") + .withLabels(labels).endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef() + .withUid("110").endTargetRef().endAddress().addNewPort("http", "https", 443, "TCP") + .addNewPort("http", "http", 80, "TCP").endSubset().build(); + + mockClient.endpoints().inNamespace("test").resource(endPoint1).create(); + + Service service = new ServiceBuilder().withNewMetadata().withName("endpoint5").withNamespace("test") + .withLabels(labels).withAnnotations(labels).endMetadata().build(); + + mockClient.services().inNamespace("test").resource(service).create(); + + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, + false, null, Set.of(443, 8443), Map.of(), null, Metadata.DEFAULT, 0, true); + + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, + properties, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true); + + List instances = discoveryClient.getInstances("endpoint5"); + + assertThat(instances).hasSize(1).filteredOn(s -> s.getHost().equals("ip1") && s.isSecure()).hasSize(1) + .filteredOn(s -> s.getInstanceId().equals("110")).hasSize(1).filteredOn(s -> 443 == s.getPort()) + .hasSize(1); + } + + @Test + void instanceWithMultiplePortsAndWithoutPrimaryPortNameSpecifiedOrHttpsPortShouldFallBackToHttp() { + Map labels = Map.of(); + + Endpoints endPoint1 = new EndpointsBuilder().withNewMetadata().withName("endpoint5").withNamespace("test") + .withLabels(labels).endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef() + .withUid("120").endTargetRef().endAddress().addNewPort("http", "https1", 443, "TCP") + .addNewPort("http", "https2", 8443, "TCP").addNewPort("http", "http", 80, "TCP").endSubset().build(); + + mockClient.endpoints().inNamespace("test").resource(endPoint1).create(); + + Service service = new ServiceBuilder().withNewMetadata().withName("endpoint5").withNamespace("test") + .withLabels(labels).withAnnotations(labels).endMetadata().build(); + + mockClient.services().inNamespace("test").resource(service).create(); + + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, + KubernetesDiscoveryProperties.DEFAULT, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true); + + List instances = discoveryClient.getInstances("endpoint5"); + + assertThat(instances).hasSize(1).filteredOn(s -> s.getHost().equals("ip1") && !s.isSecure()).hasSize(1) + .filteredOn(s -> s.getInstanceId().equals("120")).hasSize(1).filteredOn(s -> 80 == s.getPort()) + .hasSize(1); + } + + @Test + void instanceWithMultiplePortsAndWithoutPrimaryPortNameSpecifiedShouldLogWarning() { + Map labels = Map.of(); + + Endpoints endPoint1 = new EndpointsBuilder().withNewMetadata().withName("endpoint5").withNamespace("test") + .withLabels(labels).endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef() + .withUid("130").endTargetRef().endAddress().addNewPort("http", "https", 443, "TCP") + .addNewPort("http", "http", 80, "TCP").endSubset().build(); + + mockClient.endpoints().inNamespace("test").resource(endPoint1).create(); + + Service service = new ServiceBuilder().withNewMetadata().withName("endpoint5").withNamespace("test") + .withLabels(labels).withAnnotations(labels).endMetadata().build(); + + mockClient.services().inNamespace("test").resource(service).create(); + + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, + true, null, Set.of(443, 8443), Map.of(), null, Metadata.DEFAULT, 0, true); + + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, + properties, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true); + + List instances = discoveryClient.getInstances("endpoint5"); + + // We're returning the first discovered port to not change previous behaviour + assertThat(instances).hasSize(1).filteredOn(s -> s.getHost().equals("ip1") && s.isSecure()).hasSize(1) + .filteredOn(s -> s.getInstanceId().equals("130")).hasSize(1).filteredOn(s -> 443 == s.getPort()) + .hasSize(1); + } + + private static Environment mockEnvironment() { + MockEnvironment environment = new MockEnvironment(); + environment.setProperty("spring.cloud.kubernetes.client.namespace", "test"); + return environment; + } } diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesReactiveDiscoveryClientTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesReactiveDiscoveryClientTests.java index 839fccdd54..5cc5f50c85 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesReactiveDiscoveryClientTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesReactiveDiscoveryClientTests.java @@ -54,6 +54,11 @@ @EnableKubernetesMockClient(crud = true, https = false) class KubernetesReactiveDiscoveryClientTests { + private static final ServicePortSecureResolver SERVICE_PORT_SECURE_RESOLVER = + new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT); + + private static final KubernetesNamespaceProvider NAMESPACE_PROVIDER = new KubernetesNamespaceProvider(mockEnvironment()); + private static KubernetesMockServer kubernetesServer; private static KubernetesClient kubernetesClient; @@ -76,10 +81,8 @@ void afterEach() { @Test void verifyDefaults() { - ServicePortSecureResolver servicePortSecureResolver = new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT); - KubernetesNamespaceProvider namespaceProvider = new KubernetesNamespaceProvider(mockEnvironment()); Fabric8KubernetesDiscoveryClient fabric8KubernetesDiscoveryClient = new Fabric8KubernetesDiscoveryClient( - kubernetesClient, KubernetesDiscoveryProperties.DEFAULT, servicePortSecureResolver, namespaceProvider, + kubernetesClient, KubernetesDiscoveryProperties.DEFAULT, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true ); ReactiveDiscoveryClient client = new Fabric8KubernetesReactiveDiscoveryClient(fabric8KubernetesDiscoveryClient); @@ -95,10 +98,8 @@ void shouldReturnFluxOfServices() { .withName("s2").withLabels(Map.of("label", "value", "label2", "value2")).endMetadata().endItem() .addNewItem().withNewMetadata().withName("s3").endMetadata().endItem().build()) .once(); - ServicePortSecureResolver servicePortSecureResolver = new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT); - KubernetesNamespaceProvider namespaceProvider = new KubernetesNamespaceProvider(mockEnvironment()); Fabric8KubernetesDiscoveryClient fabric8KubernetesDiscoveryClient = new Fabric8KubernetesDiscoveryClient( - kubernetesClient, KubernetesDiscoveryProperties.DEFAULT, servicePortSecureResolver, namespaceProvider, + kubernetesClient, KubernetesDiscoveryProperties.DEFAULT, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true ); ReactiveDiscoveryClient client = new Fabric8KubernetesReactiveDiscoveryClient(fabric8KubernetesDiscoveryClient); @@ -111,10 +112,8 @@ void shouldReturnEmptyFluxOfServicesWhenNoInstancesFound() { kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services") .andReturn(200, new ServiceListBuilder().build()).once(); - ServicePortSecureResolver servicePortSecureResolver = new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT); - KubernetesNamespaceProvider namespaceProvider = new KubernetesNamespaceProvider(mockEnvironment()); Fabric8KubernetesDiscoveryClient fabric8KubernetesDiscoveryClient = new Fabric8KubernetesDiscoveryClient( - kubernetesClient, KubernetesDiscoveryProperties.DEFAULT, servicePortSecureResolver, namespaceProvider, + kubernetesClient, KubernetesDiscoveryProperties.DEFAULT, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true ); ReactiveDiscoveryClient client = new Fabric8KubernetesReactiveDiscoveryClient(fabric8KubernetesDiscoveryClient); @@ -128,10 +127,8 @@ void shouldReturnEmptyFluxForNonExistingService() { .withPath("/api/v1/namespaces/test/endpoints?fieldSelector=metadata.name%3Dnonexistent-service") .andReturn(200, new EndpointsBuilder().build()).once(); - ServicePortSecureResolver servicePortSecureResolver = new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT); - KubernetesNamespaceProvider namespaceProvider = new KubernetesNamespaceProvider(mockEnvironment()); Fabric8KubernetesDiscoveryClient fabric8KubernetesDiscoveryClient = new Fabric8KubernetesDiscoveryClient( - kubernetesClient, KubernetesDiscoveryProperties.DEFAULT, servicePortSecureResolver, namespaceProvider, + kubernetesClient, KubernetesDiscoveryProperties.DEFAULT, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true ); @@ -151,10 +148,8 @@ void shouldReturnEmptyFluxWhenServiceHasNoSubsets() { .withPath("/api/v1/namespaces/test/endpoints?fieldSelector=metadata.name%3Dexisting-service") .andReturn(200, new EndpointsBuilder().build()).once(); - ServicePortSecureResolver servicePortSecureResolver = new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT); - KubernetesNamespaceProvider namespaceProvider = new KubernetesNamespaceProvider(mockEnvironment()); Fabric8KubernetesDiscoveryClient fabric8KubernetesDiscoveryClient = new Fabric8KubernetesDiscoveryClient( - kubernetesClient, KubernetesDiscoveryProperties.DEFAULT, servicePortSecureResolver, namespaceProvider, + kubernetesClient, KubernetesDiscoveryProperties.DEFAULT, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true ); @@ -186,10 +181,8 @@ void shouldReturnFlux() { kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services/existing-service") .andReturn(200, services.getItems().get(0)).once(); - ServicePortSecureResolver servicePortSecureResolver = new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT); - KubernetesNamespaceProvider namespaceProvider = new KubernetesNamespaceProvider(mockEnvironment()); Fabric8KubernetesDiscoveryClient fabric8KubernetesDiscoveryClient = new Fabric8KubernetesDiscoveryClient( - kubernetesClient, KubernetesDiscoveryProperties.DEFAULT, servicePortSecureResolver, namespaceProvider, + kubernetesClient, KubernetesDiscoveryProperties.DEFAULT, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true ); @@ -225,10 +218,8 @@ void shouldReturnFluxWithPrefixedMetadata() { .withLabels(Map.of("label", "value")).endMetadata().build()) .once(); - ServicePortSecureResolver servicePortSecureResolver = new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT); - KubernetesNamespaceProvider namespaceProvider = new KubernetesNamespaceProvider(mockEnvironment()); Fabric8KubernetesDiscoveryClient fabric8KubernetesDiscoveryClient = new Fabric8KubernetesDiscoveryClient( - kubernetesClient, KubernetesDiscoveryProperties.DEFAULT, servicePortSecureResolver, namespaceProvider, + kubernetesClient, KubernetesDiscoveryProperties.DEFAULT, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true ); @@ -264,10 +255,8 @@ void shouldReturnFluxWhenServiceHasMultiplePortsAndPrimaryPortNameIsSet() { .withLabels(Map.of("label", "value")).endMetadata().build()) .once(); - ServicePortSecureResolver servicePortSecureResolver = new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT); - KubernetesNamespaceProvider namespaceProvider = new KubernetesNamespaceProvider(mockEnvironment()); Fabric8KubernetesDiscoveryClient fabric8KubernetesDiscoveryClient = new Fabric8KubernetesDiscoveryClient( - kubernetesClient, KubernetesDiscoveryProperties.DEFAULT, servicePortSecureResolver, namespaceProvider, + kubernetesClient, KubernetesDiscoveryProperties.DEFAULT, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true ); @@ -299,12 +288,10 @@ void shouldReturnFluxOfServicesAcrossAllNamespaces() { .withLabels(Map.of("label", "value")).endMetadata().build()) .once(); - ServicePortSecureResolver servicePortSecureResolver = new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT); - KubernetesNamespaceProvider namespaceProvider = new KubernetesNamespaceProvider(mockEnvironment()); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, false, null, Set.of(), Map.of(), "https_tcp", Metadata.DEFAULT, 0, true); Fabric8KubernetesDiscoveryClient fabric8KubernetesDiscoveryClient = new Fabric8KubernetesDiscoveryClient( - kubernetesClient, properties, servicePortSecureResolver, namespaceProvider, + kubernetesClient, properties, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true ); @@ -313,7 +300,7 @@ void shouldReturnFluxOfServicesAcrossAllNamespaces() { StepVerifier.create(instances).expectNextCount(1).expectComplete().verify(); } - private Environment mockEnvironment() { + private static Environment mockEnvironment() { MockEnvironment mockEnvironment = new MockEnvironment(); mockEnvironment.setProperty("spring.cloud.kubernetes.client.namespace", "test"); return mockEnvironment; From e8968d610851293884151195adc99f606391c2fb Mon Sep 17 00:00:00 2001 From: wind57 Date: Sun, 26 Feb 2023 09:48:46 +0200 Subject: [PATCH 026/151] dirty - working on tests --- ....java => Fabric8DiscoveryFilterTests.java} | 201 ++++---- ...CatalogServicesWatchConfigurationTest.java | 3 +- ...oConfigurationApplicationContextTests.java | 63 ++- ...oConfigurationApplicationContextTests.java | 269 +++++----- ...lientAutoConfigurationPropertiesTests.java | 5 +- ...etesDiscoveryClientFilterMetadataTest.java | 472 +++++++++--------- .../KubernetesDiscoveryClientFilterTest.java | 21 +- 7 files changed, 531 insertions(+), 503 deletions(-) rename spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/{Fabric8DiscoveryServicesAdapterTests.java => Fabric8DiscoveryFilterTests.java} (80%) diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryServicesAdapterTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryFilterTests.java similarity index 80% rename from spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryServicesAdapterTests.java rename to spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryFilterTests.java index 81326f2b6e..817b63b2ca 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryServicesAdapterTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryFilterTests.java @@ -35,102 +35,107 @@ import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider; import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; import org.springframework.cloud.kubernetes.fabric8.Fabric8Utils; +import org.springframework.core.env.Environment; import org.springframework.mock.env.MockEnvironment; +import static org.springframework.cloud.kubernetes.fabric8.discovery.Fabric8KubernetesDiscoveryClientUtils.services; + /** * @author wind57 */ @EnableKubernetesMockClient(crud = true, https = false) -class Fabric8DiscoveryServicesAdapterTests { +class Fabric8DiscoveryFilterTests { -// private static KubernetesClient client; -// -// private static MockedStatic utils; -// -// @BeforeEach -// void beforeEach() { -// utils = Mockito.mockStatic(Fabric8Utils.class); -// } -// -// @AfterEach -// void afterEach() { -// client.services().inAnyNamespace().delete(); -// utils.close(); -// } -// -// /** -// *
-//	 *     - all-namespaces = true
-//	 *     - labels = {}
-//	 *     - filter = null
-//	 *
-//	 *     - serviceA exists in namespaceA with labels = {color=red}
-//	 *     - serviceB exists in namespaceB with labels = {color=blue}
-//	 *
-//	 *     - we get both services as a result.
-//	 * 
-// */ -// @Test -// void testAllNamespacesWithoutLabelsWithoutFilter() { -// boolean allNamespaces = true; -// Map labels = Map.of(); -// String spelFilter = null; -// -// MockEnvironment environment = new MockEnvironment(); -// -// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), -// true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false); -// -// Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( -// new Fabric8KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, -// null); -// -// service("namespaceA", "serviceA", Map.of("color", "red")); -// service("namespaceB", "serviceB", Map.of("color", "blue")); -// -// List result = adapter.apply(client); -// Assertions.assertEquals(result.size(), 2); -// Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); -// Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); -// Assertions.assertEquals(result.get(1).getMetadata().getName(), "serviceB"); -// Assertions.assertEquals(result.get(1).getMetadata().getNamespace(), "namespaceB"); -// } -// -// /** -// *
-//	 *     - all-namespaces = true
-//	 *     - labels = {color=red}
-//	 *     - filter = null
-//	 *
-//	 *     - serviceA exists in namespaceA with labels = {color=red}
-//	 *     - serviceB exists in namespaceB with labels = {color=blue}
-//	 *
-//	 *     - we get only serviceA as a result.
-//	 * 
-// */ -// @Test -// void testAllNamespacesWithLabelsWithoutFilter() { -// boolean allNamespaces = true; -// Map labels = Map.of("color", "red"); -// String spelFilter = null; -// -// MockEnvironment environment = new MockEnvironment(); -// -// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), -// true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false); -// -// Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( -// new Fabric8KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, -// null); -// -// service("namespaceA", "serviceA", Map.of("color", "red")); -// service("namespaceB", "serviceB", Map.of("color", "blue")); -// -// List result = adapter.apply(client); -// Assertions.assertEquals(result.size(), 1); -// Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); -// Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); -// } + private static final ServicePortSecureResolver SERVICE_PORT_SECURE_RESOLVER = + new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT); + + private static final KubernetesNamespaceProvider NAMESPACE_PROVIDER = new KubernetesNamespaceProvider(mockEnvironment()); + + private static KubernetesClient client; + + private static MockedStatic utils; + + @BeforeEach + void beforeEach() { + utils = Mockito.mockStatic(Fabric8Utils.class); + } + + @AfterEach + void afterEach() { + client.services().inAnyNamespace().delete(); + utils.close(); + } + + /** + *
+	 *     - all-namespaces = true
+	 *     - labels = {}
+	 *     - filter = null
+	 *
+	 *     - serviceA exists in namespaceA with labels = {color=red}
+	 *     - serviceB exists in namespaceB with labels = {color=blue}
+	 *
+	 *     - we get both services as a result.
+	 * 
+ */ + @Test + void testAllNamespacesWithoutLabelsWithoutFilter() { + boolean allNamespaces = true; + Map labels = Map.of(); + String spelFilter = null; + + MockEnvironment environment = new MockEnvironment(); + + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), + true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false); + + List result = services(properties, client, NAMESPACE_PROVIDER, spelFilter, "dummy-target"); + + service("namespaceA", "serviceA", Map.of("color", "red")); + service("namespaceB", "serviceB", Map.of("color", "blue")); + + Assertions.assertEquals(result.size(), 2); + Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); + Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); + Assertions.assertEquals(result.get(1).getMetadata().getName(), "serviceB"); + Assertions.assertEquals(result.get(1).getMetadata().getNamespace(), "namespaceB"); + } + + /** + *
+	 *     - all-namespaces = true
+	 *     - labels = {color=red}
+	 *     - filter = null
+	 *
+	 *     - serviceA exists in namespaceA with labels = {color=red}
+	 *     - serviceB exists in namespaceB with labels = {color=blue}
+	 *
+	 *     - we get only serviceA as a result.
+	 * 
+ */ + @Test + void testAllNamespacesWithLabelsWithoutFilter() { + boolean allNamespaces = true; + Map labels = Map.of("color", "red"); + String spelFilter = null; + + MockEnvironment environment = new MockEnvironment(); + + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), + true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false); + + Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( + new Fabric8KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, + null); + + service("namespaceA", "serviceA", Map.of("color", "red")); + service("namespaceB", "serviceB", Map.of("color", "blue")); + + List result = adapter.apply(client); + Assertions.assertEquals(result.size(), 1); + Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); + Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); + } // // /** // *
@@ -469,11 +474,17 @@ class Fabric8DiscoveryServicesAdapterTests {
 //		Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA");
 //		Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA");
 //	}
-//
-//	private void service(String namespace, String name, Map labels) {
-//		client.services().inNamespace(namespace)
-//				.resource(new ServiceBuilder().withNewMetadata().withName(name).withLabels(labels).and().build())
-//				.create();
-//	}
+
+	private void service(String namespace, String name, Map labels) {
+		client.services().inNamespace(namespace)
+				.resource(new ServiceBuilder().withNewMetadata().withName(name).withLabels(labels).and().build())
+				.create();
+	}
+
+	private static Environment mockEnvironment() {
+		MockEnvironment environment = new MockEnvironment();
+		environment.setProperty("spring.cloud.kubernetes.client.namespace", "test");
+		return environment;
+	}
 
 }
diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesCatalogServicesWatchConfigurationTest.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesCatalogServicesWatchConfigurationTest.java
index 60fc44d1e0..eac9f9a137 100644
--- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesCatalogServicesWatchConfigurationTest.java
+++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesCatalogServicesWatchConfigurationTest.java
@@ -82,7 +82,8 @@ private void setup(String... env) {
 		envList.add("spring.cloud.config.enabled=false");
 		context = new SpringApplicationBuilder(PropertyPlaceholderAutoConfiguration.class,
 				KubernetesClientTestConfiguration.class, Fabric8KubernetesCatalogWatchAutoConfiguration.class,
-				Fabric8KubernetesDiscoveryClientAutoConfiguration.class, KubernetesDiscoveryPropertiesAutoConfiguration.class)
+				Fabric8KubernetesDiscoveryClientAutoConfiguration.class, KubernetesDiscoveryPropertiesAutoConfiguration.class,
+				Fabric8DiscoveryClientPredicateAutoConfiguration.class)
 						.web(WebApplicationType.NONE).properties(envList.toArray(new String[0])).run();
 	}
 
diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesCatalogWatchAutoConfigurationApplicationContextTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesCatalogWatchAutoConfigurationApplicationContextTests.java
index 9a877374fc..a5969dda2d 100644
--- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesCatalogWatchAutoConfigurationApplicationContextTests.java
+++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesCatalogWatchAutoConfigurationApplicationContextTests.java
@@ -68,42 +68,41 @@ void kubernetesDiscoveryDisabled() {
 		applicationContextRunner.run(context -> assertThat(context).hasSingleBean(Fabric8KubernetesCatalogWatch.class));
 	}
 
-//	/**
-//	 * both blocking and reactive configs are disabled, should not influence catalog
-//	 * watcher in any way.
-//	 */
-//	@Test
-//	void disableBlockingAndReactive() {
-//		setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false",
-//				"spring.cloud.discovery.blocking.enabled=false", "spring.cloud.discovery.reactive.enabled=false");
-//		applicationContextRunner.run(context -> {
-//			assertThat(context).hasSingleBean(Fabric8KubernetesCatalogWatch.class);
-//			assertThat(context).doesNotHaveBean(KubernetesClientServicesFunction.class);
-//			assertThat(context).doesNotHaveBean(Fabric8KubernetesDiscoveryClient.class);
-//			assertThat(context).doesNotHaveBean(Fabric8KubernetesReactiveDiscoveryClient.class);
-//		});
-//	}
-//
-//	/**
-//	 * spring.cloud.kubernetes.discovery.enabled is false, but does not influence catalog
-//	 * watcher.
-//	 */
-//	@Test
-//	void disableKubernetesDiscovery() {
-//		setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false",
-//				"spring.cloud.kubernetes.discovery.enabled=false");
-//		applicationContextRunner.run(context -> {
-//			assertThat(context).hasSingleBean(Fabric8KubernetesCatalogWatch.class);
-//			assertThat(context).doesNotHaveBean(KubernetesClientServicesFunction.class);
-//			assertThat(context).doesNotHaveBean(Fabric8KubernetesDiscoveryClient.class);
-//			assertThat(context).doesNotHaveBean(Fabric8KubernetesReactiveDiscoveryClient.class);
-//		});
-//	}
+	/**
+	 * both blocking and reactive configs are disabled, should not influence catalog
+	 * watcher in any way.
+	 */
+	@Test
+	void disableBlockingAndReactive() {
+		setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false",
+				"spring.cloud.discovery.blocking.enabled=false", "spring.cloud.discovery.reactive.enabled=false");
+		applicationContextRunner.run(context -> {
+			assertThat(context).hasSingleBean(Fabric8KubernetesCatalogWatch.class);
+			assertThat(context).doesNotHaveBean(Fabric8KubernetesDiscoveryClient.class);
+			assertThat(context).doesNotHaveBean(Fabric8KubernetesReactiveDiscoveryClient.class);
+		});
+	}
+
+	/**
+	 * spring.cloud.kubernetes.discovery.enabled is false, but does not influence catalog
+	 * watcher.
+	 */
+	@Test
+	void disableKubernetesDiscovery() {
+		setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false",
+				"spring.cloud.kubernetes.discovery.enabled=false");
+		applicationContextRunner.run(context -> {
+			assertThat(context).hasSingleBean(Fabric8KubernetesCatalogWatch.class);
+			assertThat(context).doesNotHaveBean(Fabric8KubernetesDiscoveryClient.class);
+			assertThat(context).doesNotHaveBean(Fabric8KubernetesReactiveDiscoveryClient.class);
+		});
+	}
 
 	private void setup(String... properties) {
 		applicationContextRunner = new ApplicationContextRunner().withConfiguration(
 				AutoConfigurations.of(Fabric8KubernetesCatalogWatchAutoConfiguration.class, Fabric8AutoConfiguration.class,
-						KubernetesCommonsAutoConfiguration.class, KubernetesDiscoveryPropertiesAutoConfiguration.class))
+						KubernetesCommonsAutoConfiguration.class, KubernetesDiscoveryPropertiesAutoConfiguration.class,
+						Fabric8DiscoveryClientPredicateAutoConfiguration.class))
 				.withPropertyValues(properties);
 	}
 
diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientAutoConfigurationApplicationContextTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientAutoConfigurationApplicationContextTests.java
index 1e37c431d9..56cb122df0 100644
--- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientAutoConfigurationApplicationContextTests.java
+++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientAutoConfigurationApplicationContextTests.java
@@ -36,144 +36,135 @@
  */
 class KubernetesDiscoveryClientAutoConfigurationApplicationContextTests {
 
-//	private ApplicationContextRunner applicationContextRunner;
-//
-//	@Test
-//	void discoveryEnabledDefault() {
-//		setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false");
-//		applicationContextRunner.run(context -> {
-//			assertThat(context).hasSingleBean(KubernetesClientServicesFunction.class);
-//			assertThat(context).hasSingleBean(Fabric8KubernetesDiscoveryClient.class);
-//			assertThat(context).hasSingleBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class);
-//		});
-//	}
-//
-//	@Test
-//	void discoveryEnabled() {
-//		setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false",
-//				"spring.cloud.discovery.enabled=true");
-//		applicationContextRunner.run(context -> {
-//			assertThat(context).hasSingleBean(KubernetesClientServicesFunction.class);
-//			assertThat(context).hasSingleBean(Fabric8KubernetesDiscoveryClient.class);
-//			assertThat(context).hasSingleBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class);
-//		});
-//	}
-//
-//	@Test
-//	void discoveryDisabled() {
-//		setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false",
-//				"spring.cloud.discovery.enabled=false");
-//		applicationContextRunner.run(context -> {
-//			assertThat(context).doesNotHaveBean(KubernetesClientServicesFunction.class);
-//			assertThat(context).doesNotHaveBean(Fabric8KubernetesDiscoveryClient.class);
-//			assertThat(context).doesNotHaveBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class);
-//		});
-//	}
-//
-//	@Test
-//	void kubernetesDiscoveryEnabled() {
-//		setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false",
-//				"spring.cloud.kubernetes.discovery.enabled=true");
-//		applicationContextRunner.run(context -> {
-//			assertThat(context).hasSingleBean(KubernetesClientServicesFunction.class);
-//			assertThat(context).hasSingleBean(Fabric8KubernetesDiscoveryClient.class);
-//			assertThat(context).hasSingleBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class);
-//		});
-//	}
-//
-//	@Test
-//	void kubernetesDiscoveryDisabled() {
-//		setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false",
-//				"spring.cloud.kubernetes.discovery.enabled=false");
-//		applicationContextRunner.run(context -> {
-//			assertThat(context).doesNotHaveBean(KubernetesClientServicesFunction.class);
-//			assertThat(context).doesNotHaveBean(Fabric8KubernetesDiscoveryClient.class);
-//			assertThat(context).doesNotHaveBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class);
-//		});
-//	}
-//
-//	@Test
-//	void kubernetesDiscoveryBlockingEnabled() {
-//		setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false",
-//				"spring.cloud.discovery.blocking.enabled=true");
-//		applicationContextRunner.run(context -> {
-//			assertThat(context).hasSingleBean(KubernetesClientServicesFunction.class);
-//			assertThat(context).hasSingleBean(Fabric8KubernetesDiscoveryClient.class);
-//			assertThat(context).hasSingleBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class);
-//		});
-//	}
-//
-//	@Test
-//	void kubernetesDiscoveryBlockingDisabled() {
-//		setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false",
-//				"spring.cloud.discovery.blocking.enabled=false");
-//		applicationContextRunner.run(context -> {
-//			assertThat(context).doesNotHaveBean(KubernetesClientServicesFunction.class);
-//			assertThat(context).doesNotHaveBean(Fabric8KubernetesDiscoveryClient.class);
-//			assertThat(context).doesNotHaveBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class);
-//		});
-//	}
-//
-//	@Test
-//	void kubernetesDiscoveryHealthIndicatorEnabled() {
-//		setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false",
-//				"spring.cloud.discovery.client.health-indicator.enabled=true");
-//		applicationContextRunner.run(context -> {
-//			assertThat(context).hasSingleBean(KubernetesClientServicesFunction.class);
-//			assertThat(context).hasSingleBean(Fabric8KubernetesDiscoveryClient.class);
-//			assertThat(context).hasSingleBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class);
-//		});
-//	}
-//
-//	@Test
-//	void kubernetesDiscoveryHealthIndicatorDisabled() {
-//		setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false",
-//				"spring.cloud.discovery.client.health-indicator.enabled=false");
-//		applicationContextRunner.run(context -> {
-//			assertThat(context).hasSingleBean(KubernetesClientServicesFunction.class);
-//			assertThat(context).hasSingleBean(Fabric8KubernetesDiscoveryClient.class);
-//			assertThat(context).doesNotHaveBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class);
-//		});
-//	}
-//
-//	@Test
-//	void kubernetesDiscoveryHealthIndicatorEnabledHealthIndicatorMissing() {
-//		setupWithFilteredClassLoader(HealthIndicator.class, "spring.main.cloud-platform=KUBERNETES",
-//				"spring.cloud.config.enabled=false", "spring.cloud.discovery.client.health-indicator.enabled=true");
-//		applicationContextRunner.run(context -> {
-//			assertThat(context).hasSingleBean(KubernetesClientServicesFunction.class);
-//			assertThat(context).hasSingleBean(Fabric8KubernetesDiscoveryClient.class);
-//			assertThat(context).doesNotHaveBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class);
-//		});
-//	}
-//
-//	/**
-//	 * reactive is disabled and should not impact blocking in any way
-//	 */
-//	@Test
-//	void reactiveDisabled() {
-//		setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false",
-//				"spring.cloud.discovery.reactive.enabled=false");
-//		applicationContextRunner.run(context -> {
-//			assertThat(context).hasSingleBean(KubernetesClientServicesFunction.class);
-//			assertThat(context).hasSingleBean(Fabric8KubernetesDiscoveryClient.class);
-//			assertThat(context).hasSingleBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class);
-//		});
-//	}
-//
-//	private void setup(String... properties) {
-//		applicationContextRunner = new ApplicationContextRunner().withConfiguration(
-//				AutoConfigurations.of(Fabric8KubernetesDiscoveryClientAutoConfiguration.class, Fabric8AutoConfiguration.class,
-//						KubernetesCommonsAutoConfiguration.class, KubernetesDiscoveryPropertiesAutoConfiguration.class))
-//				.withPropertyValues(properties);
-//	}
-//
-//	private void setupWithFilteredClassLoader(Class cls, String... properties) {
-//		applicationContextRunner = new ApplicationContextRunner()
-//				.withConfiguration(AutoConfigurations.of(Fabric8KubernetesDiscoveryClientAutoConfiguration.class,
-//						Fabric8AutoConfiguration.class, KubernetesCommonsAutoConfiguration.class,
-//						KubernetesDiscoveryPropertiesAutoConfiguration.class))
-//				.withClassLoader(new FilteredClassLoader(cls)).withPropertyValues(properties);
-//	}
+	private ApplicationContextRunner applicationContextRunner;
+
+	@Test
+	void discoveryEnabledDefault() {
+		setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false");
+		applicationContextRunner.run(context -> {
+			assertThat(context).hasSingleBean(Fabric8KubernetesDiscoveryClient.class);
+			assertThat(context).hasSingleBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class);
+		});
+	}
+
+	@Test
+	void discoveryEnabled() {
+		setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false",
+				"spring.cloud.discovery.enabled=true");
+		applicationContextRunner.run(context -> {
+			assertThat(context).hasSingleBean(Fabric8KubernetesDiscoveryClient.class);
+			assertThat(context).hasSingleBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class);
+		});
+	}
+
+	@Test
+	void discoveryDisabled() {
+		setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false",
+				"spring.cloud.discovery.enabled=false");
+		applicationContextRunner.run(context -> {
+			assertThat(context).doesNotHaveBean(Fabric8KubernetesDiscoveryClient.class);
+			assertThat(context).doesNotHaveBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class);
+		});
+	}
+
+	@Test
+	void kubernetesDiscoveryEnabled() {
+		setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false",
+				"spring.cloud.kubernetes.discovery.enabled=true");
+		applicationContextRunner.run(context -> {
+			assertThat(context).hasSingleBean(Fabric8KubernetesDiscoveryClient.class);
+			assertThat(context).hasSingleBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class);
+		});
+	}
+
+	@Test
+	void kubernetesDiscoveryDisabled() {
+		setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false",
+				"spring.cloud.kubernetes.discovery.enabled=false");
+		applicationContextRunner.run(context -> {
+			assertThat(context).doesNotHaveBean(Fabric8KubernetesDiscoveryClient.class);
+			assertThat(context).doesNotHaveBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class);
+		});
+	}
+
+	@Test
+	void kubernetesDiscoveryBlockingEnabled() {
+		setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false",
+				"spring.cloud.discovery.blocking.enabled=true");
+		applicationContextRunner.run(context -> {
+			assertThat(context).hasSingleBean(Fabric8KubernetesDiscoveryClient.class);
+			assertThat(context).hasSingleBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class);
+		});
+	}
+
+	@Test
+	void kubernetesDiscoveryBlockingDisabled() {
+		setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false",
+				"spring.cloud.discovery.blocking.enabled=false");
+		applicationContextRunner.run(context -> {
+			assertThat(context).doesNotHaveBean(Fabric8KubernetesDiscoveryClient.class);
+			assertThat(context).doesNotHaveBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class);
+		});
+	}
+
+	@Test
+	void kubernetesDiscoveryHealthIndicatorEnabled() {
+		setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false",
+				"spring.cloud.discovery.client.health-indicator.enabled=true");
+		applicationContextRunner.run(context -> {
+			assertThat(context).hasSingleBean(Fabric8KubernetesDiscoveryClient.class);
+			assertThat(context).hasSingleBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class);
+		});
+	}
+
+	@Test
+	void kubernetesDiscoveryHealthIndicatorDisabled() {
+		setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false",
+				"spring.cloud.discovery.client.health-indicator.enabled=false");
+		applicationContextRunner.run(context -> {
+			assertThat(context).hasSingleBean(Fabric8KubernetesDiscoveryClient.class);
+			assertThat(context).doesNotHaveBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class);
+		});
+	}
+
+	@Test
+	void kubernetesDiscoveryHealthIndicatorEnabledHealthIndicatorMissing() {
+		setupWithFilteredClassLoader(HealthIndicator.class, "spring.main.cloud-platform=KUBERNETES",
+				"spring.cloud.config.enabled=false", "spring.cloud.discovery.client.health-indicator.enabled=true");
+		applicationContextRunner.run(context -> {
+			assertThat(context).hasSingleBean(Fabric8KubernetesDiscoveryClient.class);
+			assertThat(context).doesNotHaveBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class);
+		});
+	}
+
+	/**
+	 * reactive is disabled and should not impact blocking in any way
+	 */
+	@Test
+	void reactiveDisabled() {
+		setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false",
+				"spring.cloud.discovery.reactive.enabled=false");
+		applicationContextRunner.run(context -> {
+			assertThat(context).hasSingleBean(Fabric8KubernetesDiscoveryClient.class);
+			assertThat(context).hasSingleBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class);
+		});
+	}
+
+	private void setup(String... properties) {
+		applicationContextRunner = new ApplicationContextRunner().withConfiguration(
+				AutoConfigurations.of(Fabric8KubernetesDiscoveryClientAutoConfiguration.class, Fabric8AutoConfiguration.class,
+						KubernetesCommonsAutoConfiguration.class, KubernetesDiscoveryPropertiesAutoConfiguration.class,
+						Fabric8DiscoveryClientPredicateAutoConfiguration.class))
+				.withPropertyValues(properties);
+	}
+
+	private void setupWithFilteredClassLoader(Class cls, String... properties) {
+		applicationContextRunner = new ApplicationContextRunner()
+				.withConfiguration(AutoConfigurations.of(Fabric8KubernetesDiscoveryClientAutoConfiguration.class,
+						Fabric8AutoConfiguration.class, KubernetesCommonsAutoConfiguration.class,
+						KubernetesDiscoveryPropertiesAutoConfiguration.class,
+						Fabric8DiscoveryClientPredicateAutoConfiguration.class))
+				.withClassLoader(new FilteredClassLoader(cls)).withPropertyValues(properties);
+	}
 
 }
diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientAutoConfigurationPropertiesTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientAutoConfigurationPropertiesTests.java
index f77d5bb204..ba6c9496f6 100644
--- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientAutoConfigurationPropertiesTests.java
+++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientAutoConfigurationPropertiesTests.java
@@ -25,6 +25,7 @@
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.Test;
 
+import org.springframework.boot.WebApplicationType;
 import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
 import org.springframework.boot.builder.SpringApplicationBuilder;
 import org.springframework.cloud.kubernetes.commons.PodUtils;
@@ -82,8 +83,8 @@ private void setup(String... env) {
 		envList.add("spring.cloud.config.enabled=false");
 		context = new SpringApplicationBuilder(PropertyPlaceholderAutoConfiguration.class,
 				KubernetesClientTestConfiguration.class, Fabric8KubernetesDiscoveryClientAutoConfiguration.class,
-				KubernetesDiscoveryPropertiesAutoConfiguration.class)
-						.web(org.springframework.boot.WebApplicationType.NONE)
+				KubernetesDiscoveryPropertiesAutoConfiguration.class, Fabric8DiscoveryClientPredicateAutoConfiguration.class)
+						.web(WebApplicationType.NONE)
 						.properties(envList.toArray(new String[0])).run();
 	}
 
diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientFilterMetadataTest.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientFilterMetadataTest.java
index d673f44517..5a8c890393 100644
--- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientFilterMetadataTest.java
+++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientFilterMetadataTest.java
@@ -43,6 +43,7 @@
 import org.mockito.Mockito;
 
 import org.springframework.cloud.client.ServiceInstance;
+import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider;
 import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
 import org.springframework.core.env.Environment;
 import org.springframework.mock.env.MockEnvironment;
@@ -59,234 +60,247 @@
 @SuppressWarnings("unchecked")
 class KubernetesDiscoveryClientFilterMetadataTest {
 
-//	private static final KubernetesClient CLIENT = Mockito.mock(KubernetesClient.class);
-//
-//	private final MixedOperation> serviceOperation = Mockito
-//			.mock(MixedOperation.class);
-//
-//	private final MixedOperation> endpointsOperation = Mockito
-//			.mock(MixedOperation.class);
-//
-//	private final ServiceResource serviceResource = Mockito.mock(ServiceResource.class);
-//
-//	private final FilterWatchListDeletable> filter = Mockito
-//			.mock(FilterWatchListDeletable.class);
-//
-//	private final FilterNested>> filterNested = Mockito
-//			.mock(FilterNested.class);
-//
-//	@Test
-//	void testAllExtraMetadataDisabled() {
-//		String serviceId = "s";
-//
-//		Metadata metadata = new Metadata(false, null, false, null, false, null);
-//		KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60,
-//				false, null, Set.of(), Map.of(), null, metadata, 0, true);
-//
-//		Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(CLIENT, properties, a -> null);
-//		discoveryClient.setEnvironment(withClientNamespace());
-//
-//		setupServiceWithLabelsAndAnnotationsAndPorts(serviceId, "ns", Map.of("l1", "lab"), Map.of("l1", "lab"),
-//				Map.of(80, "http", 5555, ""));
-//
-//		List instances = discoveryClient.getInstances(serviceId);
-//		assertThat(instances).hasSize(1);
-//		assertThat(instances.get(0).getMetadata()).isEqualTo(Map.of("k8s_namespace", "ns"));
-//	}
-//
-//	@Test
-//	void testLabelsEnabled() {
-//		String serviceId = "s";
-//
-//		Metadata metadata = new Metadata(true, null, false, null, false, null);
-//		KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60,
-//				false, null, Set.of(), Map.of(), null, metadata, 0, true);
-//
-//		Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(CLIENT, properties, a -> null);
-//		discoveryClient.setEnvironment(withClientNamespace());
-//
-//		setupServiceWithLabelsAndAnnotationsAndPorts(serviceId, "ns", Map.of("l1", "v1", "l2", "v2"),
-//				Map.of("l1", "lab"), Map.of(80, "http", 5555, ""));
-//
-//		List instances = discoveryClient.getInstances(serviceId);
-//		assertThat(instances).hasSize(1);
-//		assertThat(instances.get(0).getMetadata()).containsOnly(entry("l1", "v1"), entry("l2", "v2"),
-//				entry("k8s_namespace", "ns"));
-//	}
-//
-//	@Test
-//	void testLabelsEnabledWithPrefix() {
-//		String serviceId = "s";
-//
-//		Metadata metadata = new Metadata(true, "l_", false, null, false, null);
-//		KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60,
-//				false, null, Set.of(), Map.of(), null, metadata, 0, true);
-//
-//		Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(CLIENT, properties, a -> null);
-//		discoveryClient.setEnvironment(withClientNamespace());
-//
-//		setupServiceWithLabelsAndAnnotationsAndPorts(serviceId, "ns", Map.of("l1", "v1", "l2", "v2"),
-//				Map.of("l1", "lab"), Map.of(80, "http", 5555, ""));
-//
-//		List instances = discoveryClient.getInstances(serviceId);
-//		assertThat(instances).hasSize(1);
-//		assertThat(instances.get(0).getMetadata()).containsOnly(entry("l_l1", "v1"), entry("l_l2", "v2"),
-//				entry("k8s_namespace", "ns"));
-//	}
-//
-//	@Test
-//	void testAnnotationsEnabled() {
-//		String serviceId = "s";
-//
-//		Metadata metadata = new Metadata(false, null, true, null, false, null);
-//		KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60,
-//				false, null, Set.of(), Map.of(), null, metadata, 0, true);
-//
-//		Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(CLIENT, properties, a -> null);
-//		discoveryClient.setEnvironment(withClientNamespace());
-//
-//		setupServiceWithLabelsAndAnnotationsAndPorts(serviceId, "ns", Map.of("l1", "v1"),
-//				Map.of("a1", "v1", "a2", "v2"), Map.of(80, "http", 5555, ""));
-//
-//		List instances = discoveryClient.getInstances(serviceId);
-//		assertThat(instances).hasSize(1);
-//		assertThat(instances.get(0).getMetadata()).containsOnly(entry("a1", "v1"), entry("a2", "v2"),
-//				entry("k8s_namespace", "ns"));
-//	}
-//
-//	@Test
-//	void testAnnotationsEnabledWithPrefix() {
-//		String serviceId = "s";
-//
-//		Metadata metadata = new Metadata(false, null, true, "a_", false, null);
-//		KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60,
-//				false, null, Set.of(), Map.of(), null, metadata, 0, true);
-//
-//		Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(CLIENT, properties, a -> null);
-//		discoveryClient.setEnvironment(withClientNamespace());
-//
-//		setupServiceWithLabelsAndAnnotationsAndPorts(serviceId, "ns", Map.of("l1", "v1"),
-//				Map.of("a1", "v1", "a2", "v2"), Map.of(80, "http", 5555, ""));
-//
-//		List instances = discoveryClient.getInstances(serviceId);
-//		assertThat(instances).hasSize(1);
-//		assertThat(instances.get(0).getMetadata()).containsOnly(entry("a_a1", "v1"), entry("a_a2", "v2"),
-//				entry("k8s_namespace", "ns"));
-//	}
-//
-//	@Test
-//	void testPortsEnabled() {
-//		String serviceId = "s";
-//
-//		Metadata metadata = new Metadata(false, null, false, null, true, null);
-//		KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60,
-//				false, null, Set.of(), Map.of(), null, metadata, 0, true);
-//
-//		Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(CLIENT, properties, a -> null);
-//		discoveryClient.setEnvironment(withClientNamespace());
-//
-//		setupServiceWithLabelsAndAnnotationsAndPorts(serviceId, "test", Map.of("l1", "v1"),
-//				Map.of("a1", "v1", "a2", "v2"), Map.of(80, "http", 5555, ""));
-//
-//		List instances = discoveryClient.getInstances(serviceId);
-//		assertThat(instances).hasSize(1);
-//		assertThat(instances.get(0).getMetadata()).containsOnly(entry("http", "80"), entry("k8s_namespace", "test"));
-//	}
-//
-//	@Test
-//	void testPortsEnabledWithPrefix() {
-//		String serviceId = "s";
-//
-//		Metadata metadata = new Metadata(false, null, false, null, true, "p_");
-//		KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60,
-//				false, null, Set.of(), Map.of(), null, metadata, 0, true);
-//
-//		Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(CLIENT, properties, a -> null);
-//		discoveryClient.setEnvironment(withClientNamespace());
-//
-//		setupServiceWithLabelsAndAnnotationsAndPorts(serviceId, "ns", Map.of("l1", "v1"),
-//				Map.of("a1", "v1", "a2", "v2"), Map.of(80, "http", 5555, ""));
-//
-//		List instances = discoveryClient.getInstances(serviceId);
-//		assertThat(instances).hasSize(1);
-//		assertThat(instances.get(0).getMetadata()).containsOnly(entry("p_http", "80"), entry("k8s_namespace", "ns"));
-//	}
-//
-//	@Test
-//	void testLabelsAndAnnotationsAndPortsEnabledWithPrefix() {
-//		String serviceId = "s";
-//
-//		Metadata metadata = new Metadata(true, "l_", true, "a_", true, "p_");
-//		KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60,
-//				false, null, Set.of(), Map.of(), null, metadata, 0, true);
-//
-//		Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(CLIENT, properties, a -> null);
-//		discoveryClient.setEnvironment(withClientNamespace());
-//
-//		setupServiceWithLabelsAndAnnotationsAndPorts(serviceId, "ns", Map.of("l1", "la1"),
-//				Map.of("a1", "an1", "a2", "an2"), Map.of(80, "http", 5555, ""));
-//
-//		List instances = discoveryClient.getInstances(serviceId);
-//		assertThat(instances).hasSize(1);
-//		assertThat(instances.get(0).getMetadata()).containsOnly(entry("a_a1", "an1"), entry("a_a2", "an2"),
-//				entry("l_l1", "la1"), entry("p_http", "80"), entry("k8s_namespace", "ns"));
-//	}
-//
-//	private void setupServiceWithLabelsAndAnnotationsAndPorts(String serviceId, String namespace,
-//			Map labels, Map annotations, Map ports) {
-//		Service service = new ServiceBuilder().withNewMetadata().withNamespace(namespace).withLabels(labels)
-//				.withAnnotations(annotations).endMetadata().withNewSpec().withPorts(getServicePorts(ports)).endSpec()
-//				.build();
-//		when(serviceOperation.withName(serviceId)).thenReturn(serviceResource);
-//		when(serviceResource.get()).thenReturn(service);
-//		when(CLIENT.services()).thenReturn(serviceOperation);
-//		when(CLIENT.services().inNamespace(anyString())).thenReturn(serviceOperation);
-//
-//		ObjectMeta objectMeta = new ObjectMeta();
-//		objectMeta.setNamespace(namespace);
-//
-//		Endpoints endpoints = new EndpointsBuilder().withMetadata(objectMeta).addNewSubset()
-//				.addAllToPorts(getEndpointPorts(ports)).addNewAddress().endAddress().endSubset().build();
-//
-//		when(CLIENT.endpoints()).thenReturn(endpointsOperation);
-//		when(endpointsOperation.inNamespace(Mockito.anyString())).thenReturn(endpointsOperation);
-//		when(endpointsOperation.withNewFilter()).thenReturn(filterNested);
-//
-//		EndpointsList endpointsList = new EndpointsList(null, Collections.singletonList(endpoints), null, null);
-//		when(filter.list()).thenReturn(endpointsList);
-//		when(filterNested.withLabels(anyMap())).thenReturn(filterNested);
-//
-//		when(filterNested.withField(eq("metadata.name"), eq(serviceId))).thenReturn(filterNested);
-//		when(filterNested.endFilter()).thenReturn(filter);
-//
-//	}
-//
-//	private List getServicePorts(Map ports) {
-//		return ports.entrySet().stream().map(e -> {
-//			ServicePortBuilder servicePortBuilder = new ServicePortBuilder();
-//			servicePortBuilder.withPort(e.getKey());
-//			if (!Strings.isNullOrEmpty(e.getValue())) {
-//				servicePortBuilder.withName(e.getValue());
-//			}
-//			return servicePortBuilder.build();
-//		}).collect(toList());
-//	}
-//
-//	private List getEndpointPorts(Map ports) {
-//		return ports.entrySet().stream().map(e -> {
-//			EndpointPortBuilder endpointPortBuilder = new EndpointPortBuilder();
-//			endpointPortBuilder.withPort(e.getKey());
-//			if (!Strings.isNullOrEmpty(e.getValue())) {
-//				endpointPortBuilder.withName(e.getValue());
-//			}
-//			return endpointPortBuilder.build();
-//		}).collect(toList());
-//	}
-//
-//	private static Environment withClientNamespace() {
-//		MockEnvironment mockEnvironment = new MockEnvironment();
-//		mockEnvironment.setProperty("spring.cloud.kubernetes.client.namespace", "test");
-//		return mockEnvironment;
-//	}
+	private static final ServicePortSecureResolver SERVICE_PORT_SECURE_RESOLVER =
+		new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT);
+
+	private static final KubernetesNamespaceProvider NAMESPACE_PROVIDER = new KubernetesNamespaceProvider(mockEnvironment());
+
+	private static final KubernetesClient CLIENT = Mockito.mock(KubernetesClient.class);
+
+	private final MixedOperation> serviceOperation = Mockito
+			.mock(MixedOperation.class);
+
+	private final MixedOperation> endpointsOperation = Mockito
+			.mock(MixedOperation.class);
+
+	private final ServiceResource serviceResource = Mockito.mock(ServiceResource.class);
+
+	private final FilterWatchListDeletable> filter = Mockito
+			.mock(FilterWatchListDeletable.class);
+
+	private final FilterNested>> filterNested = Mockito
+			.mock(FilterNested.class);
+
+	@Test
+	void testAllExtraMetadataDisabled() {
+		String serviceId = "s";
+
+		Metadata metadata = new Metadata(false, null, false, null, false, null);
+		KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60,
+				false, null, Set.of(), Map.of(), null, metadata, 0, true);
+
+		Fabric8KubernetesDiscoveryClient client = new Fabric8KubernetesDiscoveryClient(CLIENT, properties,
+			SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER,
+			new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties));
+
+		setupServiceWithLabelsAndAnnotationsAndPorts(serviceId, "ns", Map.of("l1", "lab"), Map.of("l1", "lab"),
+				Map.of(80, "http", 5555, ""));
+
+		List instances = client.getInstances(serviceId);
+		assertThat(instances).hasSize(1);
+		assertThat(instances.get(0).getMetadata()).isEqualTo(Map.of("k8s_namespace", "ns"));
+	}
+
+	@Test
+	void testLabelsEnabled() {
+		String serviceId = "s";
+
+		Metadata metadata = new Metadata(true, null, false, null, false, null);
+		KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60,
+				false, null, Set.of(), Map.of(), null, metadata, 0, true);
+
+		Fabric8KubernetesDiscoveryClient client = new Fabric8KubernetesDiscoveryClient(CLIENT, properties,
+			SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER,
+			new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties));
+
+		setupServiceWithLabelsAndAnnotationsAndPorts(serviceId, "ns", Map.of("l1", "v1", "l2", "v2"),
+				Map.of("l1", "lab"), Map.of(80, "http", 5555, ""));
+
+		List instances = client.getInstances(serviceId);
+		assertThat(instances).hasSize(1);
+		assertThat(instances.get(0).getMetadata()).containsOnly(entry("l1", "v1"), entry("l2", "v2"),
+				entry("k8s_namespace", "ns"));
+	}
+
+	@Test
+	void testLabelsEnabledWithPrefix() {
+		String serviceId = "s";
+
+		Metadata metadata = new Metadata(true, "l_", false, null, false, null);
+		KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60,
+				false, null, Set.of(), Map.of(), null, metadata, 0, true);
+
+		Fabric8KubernetesDiscoveryClient client = new Fabric8KubernetesDiscoveryClient(CLIENT, properties,
+			SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER,
+			new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties));
+
+		setupServiceWithLabelsAndAnnotationsAndPorts(serviceId, "ns", Map.of("l1", "v1", "l2", "v2"),
+				Map.of("l1", "lab"), Map.of(80, "http", 5555, ""));
+
+		List instances = client.getInstances(serviceId);
+		assertThat(instances).hasSize(1);
+		assertThat(instances.get(0).getMetadata()).containsOnly(entry("l_l1", "v1"), entry("l_l2", "v2"),
+				entry("k8s_namespace", "ns"));
+	}
+
+	@Test
+	void testAnnotationsEnabled() {
+		String serviceId = "s";
+
+		Metadata metadata = new Metadata(false, null, true, null, false, null);
+		KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60,
+				false, null, Set.of(), Map.of(), null, metadata, 0, true);
+
+		Fabric8KubernetesDiscoveryClient client = new Fabric8KubernetesDiscoveryClient(CLIENT, properties,
+			SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER,
+			new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties));
+
+		setupServiceWithLabelsAndAnnotationsAndPorts(serviceId, "ns", Map.of("l1", "v1"),
+				Map.of("a1", "v1", "a2", "v2"), Map.of(80, "http", 5555, ""));
+
+		List instances = client.getInstances(serviceId);
+		assertThat(instances).hasSize(1);
+		assertThat(instances.get(0).getMetadata()).containsOnly(entry("a1", "v1"), entry("a2", "v2"),
+				entry("k8s_namespace", "ns"));
+	}
+
+	@Test
+	void testAnnotationsEnabledWithPrefix() {
+		String serviceId = "s";
+
+		Metadata metadata = new Metadata(false, null, true, "a_", false, null);
+		KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60,
+				false, null, Set.of(), Map.of(), null, metadata, 0, true);
+
+		Fabric8KubernetesDiscoveryClient client = new Fabric8KubernetesDiscoveryClient(CLIENT, properties,
+			SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER,
+			new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties));
+
+		setupServiceWithLabelsAndAnnotationsAndPorts(serviceId, "ns", Map.of("l1", "v1"),
+				Map.of("a1", "v1", "a2", "v2"), Map.of(80, "http", 5555, ""));
+
+		List instances = client.getInstances(serviceId);
+		assertThat(instances).hasSize(1);
+		assertThat(instances.get(0).getMetadata()).containsOnly(entry("a_a1", "v1"), entry("a_a2", "v2"),
+				entry("k8s_namespace", "ns"));
+	}
+
+	@Test
+	void testPortsEnabled() {
+		String serviceId = "s";
+
+		Metadata metadata = new Metadata(false, null, false, null, true, null);
+		KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60,
+				false, null, Set.of(), Map.of(), null, metadata, 0, true);
+
+		Fabric8KubernetesDiscoveryClient client = new Fabric8KubernetesDiscoveryClient(CLIENT, properties,
+			SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER,
+			new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties));
+
+		setupServiceWithLabelsAndAnnotationsAndPorts(serviceId, "test", Map.of("l1", "v1"),
+				Map.of("a1", "v1", "a2", "v2"), Map.of(80, "http", 5555, ""));
+
+		List instances = client.getInstances(serviceId);
+		assertThat(instances).hasSize(1);
+		assertThat(instances.get(0).getMetadata()).containsOnly(entry("http", "80"), entry("k8s_namespace", "test"));
+	}
+
+	@Test
+	void testPortsEnabledWithPrefix() {
+		String serviceId = "s";
+
+		Metadata metadata = new Metadata(false, null, false, null, true, "p_");
+		KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60,
+				false, null, Set.of(), Map.of(), null, metadata, 0, true);
+
+		Fabric8KubernetesDiscoveryClient client = new Fabric8KubernetesDiscoveryClient(CLIENT, properties,
+			SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER,
+			new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties));
+
+		setupServiceWithLabelsAndAnnotationsAndPorts(serviceId, "ns", Map.of("l1", "v1"),
+				Map.of("a1", "v1", "a2", "v2"), Map.of(80, "http", 5555, ""));
+
+		List instances = client.getInstances(serviceId);
+		assertThat(instances).hasSize(1);
+		assertThat(instances.get(0).getMetadata()).containsOnly(entry("p_http", "80"), entry("k8s_namespace", "ns"));
+	}
+
+	@Test
+	void testLabelsAndAnnotationsAndPortsEnabledWithPrefix() {
+		String serviceId = "s";
+
+		Metadata metadata = new Metadata(true, "l_", true, "a_", true, "p_");
+		KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60,
+				false, null, Set.of(), Map.of(), null, metadata, 0, true);
+
+		Fabric8KubernetesDiscoveryClient client = new Fabric8KubernetesDiscoveryClient(CLIENT, properties,
+			SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER,
+			new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties));
+
+		setupServiceWithLabelsAndAnnotationsAndPorts(serviceId, "ns", Map.of("l1", "la1"),
+				Map.of("a1", "an1", "a2", "an2"), Map.of(80, "http", 5555, ""));
+
+		List instances = client.getInstances(serviceId);
+		assertThat(instances).hasSize(1);
+		assertThat(instances.get(0).getMetadata()).containsOnly(entry("a_a1", "an1"), entry("a_a2", "an2"),
+				entry("l_l1", "la1"), entry("p_http", "80"), entry("k8s_namespace", "ns"));
+	}
+
+	private void setupServiceWithLabelsAndAnnotationsAndPorts(String serviceId, String namespace,
+			Map labels, Map annotations, Map ports) {
+		Service service = new ServiceBuilder().withNewMetadata().withNamespace(namespace).withLabels(labels)
+				.withAnnotations(annotations).endMetadata().withNewSpec().withPorts(getServicePorts(ports)).endSpec()
+				.build();
+		when(serviceOperation.withName(serviceId)).thenReturn(serviceResource);
+		when(serviceResource.get()).thenReturn(service);
+		when(CLIENT.services()).thenReturn(serviceOperation);
+		when(CLIENT.services().inNamespace(anyString())).thenReturn(serviceOperation);
+
+		ObjectMeta objectMeta = new ObjectMeta();
+		objectMeta.setNamespace(namespace);
+
+		Endpoints endpoints = new EndpointsBuilder().withMetadata(objectMeta).addNewSubset()
+				.addAllToPorts(getEndpointPorts(ports)).addNewAddress().endAddress().endSubset().build();
+
+		when(CLIENT.endpoints()).thenReturn(endpointsOperation);
+		when(endpointsOperation.inNamespace(Mockito.anyString())).thenReturn(endpointsOperation);
+		when(endpointsOperation.withNewFilter()).thenReturn(filterNested);
+
+		EndpointsList endpointsList = new EndpointsList(null, Collections.singletonList(endpoints), null, null);
+		when(filter.list()).thenReturn(endpointsList);
+		when(filterNested.withLabels(anyMap())).thenReturn(filterNested);
+
+		when(filterNested.withField(eq("metadata.name"), eq(serviceId))).thenReturn(filterNested);
+		when(filterNested.endFilter()).thenReturn(filter);
+
+	}
+
+	private List getServicePorts(Map ports) {
+		return ports.entrySet().stream().map(e -> {
+			ServicePortBuilder servicePortBuilder = new ServicePortBuilder();
+			servicePortBuilder.withPort(e.getKey());
+			if (!Strings.isNullOrEmpty(e.getValue())) {
+				servicePortBuilder.withName(e.getValue());
+			}
+			return servicePortBuilder.build();
+		}).collect(toList());
+	}
+
+	private List getEndpointPorts(Map ports) {
+		return ports.entrySet().stream().map(e -> {
+			EndpointPortBuilder endpointPortBuilder = new EndpointPortBuilder();
+			endpointPortBuilder.withPort(e.getKey());
+			if (!Strings.isNullOrEmpty(e.getValue())) {
+				endpointPortBuilder.withName(e.getValue());
+			}
+			return endpointPortBuilder.build();
+		}).collect(toList());
+	}
+
+	private static Environment mockEnvironment() {
+		MockEnvironment environment = new MockEnvironment();
+		environment.setProperty("spring.cloud.kubernetes.client.namespace", "test");
+		return environment;
+	}
 
 }
diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientFilterTest.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientFilterTest.java
index 351b3e440e..f70ce045c0 100644
--- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientFilterTest.java
+++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientFilterTest.java
@@ -85,7 +85,8 @@ void testFilteredServices() {
 				false, "metadata.additionalProperties['spring-boot']", Set.of(), Map.of(), null,
 				KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, true);
 		Fabric8KubernetesDiscoveryClient client = new Fabric8KubernetesDiscoveryClient(kubernetesClient, properties,
-				SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true);
+				SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER,
+				new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties));
 
 		List filteredServices = client.getServices();
 		assertThat(filteredServices).isEqualTo(springBootServiceNames);
@@ -106,14 +107,19 @@ void testFilteredServicesByPrefix() {
 
 		ServiceList serviceList = new ServiceList();
 		serviceList.setItems(services);
-		when(serviceOperation.list()).thenReturn(serviceList);
 		when(kubernetesClient.services()).thenReturn(serviceOperation);
+		when(serviceOperation.inNamespace(Mockito.anyString())).thenReturn(serviceOperation);
+		when(serviceOperation.withNewFilter()).thenReturn(filterNested);
+		when(filterNested.withLabels(Mockito.anyMap())).thenReturn(filterNested);
+		when(filterNested.endFilter()).thenReturn(filter);
+		when(filter.list()).thenReturn(serviceList);
 
 		KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60,
 				false, "metadata.name.startsWith('service')", Set.of(), Map.of(), null,
 				KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, true);
 		Fabric8KubernetesDiscoveryClient client = new Fabric8KubernetesDiscoveryClient(kubernetesClient, properties,
-			SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true);
+			SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER,
+			new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties));
 
 		List filteredServices = client.getServices();
 		assertThat(filteredServices).isEqualTo(springBootServiceNames);
@@ -127,13 +133,18 @@ void testNoExpression() {
 
 		ServiceList serviceList = new ServiceList();
 		serviceList.setItems(services);
-		when(serviceOperation.list()).thenReturn(serviceList);
 		when(kubernetesClient.services()).thenReturn(serviceOperation);
+		when(serviceOperation.inNamespace(Mockito.anyString())).thenReturn(serviceOperation);
+		when(serviceOperation.withNewFilter()).thenReturn(filterNested);
+		when(filterNested.withLabels(Mockito.anyMap())).thenReturn(filterNested);
+		when(filterNested.endFilter()).thenReturn(filter);
+		when(filter.list()).thenReturn(serviceList);
 
 		KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60,
 				false, "", Set.of(), Map.of(), null, KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, true);
 		Fabric8KubernetesDiscoveryClient client = new Fabric8KubernetesDiscoveryClient(kubernetesClient, properties,
-			SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true);
+			SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER,
+			new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties));
 
 		List filteredServices = client.getServices();
 

From 8dcf24e4d0b5d10020d08464288b60a730fd214a Mon Sep 17 00:00:00 2001
From: wind57 
Date: Sun, 26 Feb 2023 10:50:19 +0200
Subject: [PATCH 027/151] dirty - working on tests

---
 .../Fabric8DiscoveryFilterTests.java          | 652 ++++++++----------
 ...atalogServicesWatchConfigurationTest.java} |   2 +-
 ...ConfigurationApplicationContextTests.java} |   2 +-
 ...=> Fabric8KubernetesCatalogWatchTest.java} |   2 +-
 ...ConfigurationApplicationContextTests.java} |   2 +-
 ...ientAutoConfigurationPropertiesTests.java} |   2 +-
 ...iscoveryClientAutoConfigurationTests.java} |   2 +-
 ...figClientBootstrapConfigurationTests.java} |   2 +-
 ...tesDiscoveryClientFilterMetadataTest.java} |   2 +-
 ...8KubernetesDiscoveryClientFilterTest.java} |   2 +-
 ...Fabric8KubernetesDiscoveryClientTest.java} |   2 +-
 ...abric8KubernetesDiscoveryClientTests.java} |   2 +-
 ...8KubernetesDiscoveryClientUtilsTests.java} |   2 +-
 ...ConfigurationApplicationContextTests.java} |   2 +-
 ...iscoveryClientAutoConfigurationTests.java} |   4 +-
 ...bernetesReactiveDiscoveryClientTests.java} |   2 +-
 16 files changed, 314 insertions(+), 370 deletions(-)
 rename spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/{KubernetesCatalogServicesWatchConfigurationTest.java => Fabric8KubernetesCatalogServicesWatchConfigurationTest.java} (98%)
 rename spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/{KubernetesCatalogWatchAutoConfigurationApplicationContextTests.java => Fabric8KubernetesCatalogWatchAutoConfigurationApplicationContextTests.java} (98%)
 rename spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/{KubernetesCatalogWatchTest.java => Fabric8KubernetesCatalogWatchTest.java} (99%)
 rename spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/{KubernetesDiscoveryClientAutoConfigurationApplicationContextTests.java => Fabric8KubernetesDiscoveryClientAutoConfigurationApplicationContextTests.java} (98%)
 rename spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/{KubernetesDiscoveryClientAutoConfigurationPropertiesTests.java => Fabric8KubernetesDiscoveryClientAutoConfigurationPropertiesTests.java} (98%)
 rename spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/{KubernetesDiscoveryClientAutoConfigurationTests.java => Fabric8KubernetesDiscoveryClientAutoConfigurationTests.java} (96%)
 rename spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/{KubernetesDiscoveryClientConfigClientBootstrapConfigurationTests.java => Fabric8KubernetesDiscoveryClientConfigClientBootstrapConfigurationTests.java} (98%)
 rename spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/{KubernetesDiscoveryClientFilterMetadataTest.java => Fabric8KubernetesDiscoveryClientFilterMetadataTest.java} (99%)
 rename spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/{KubernetesDiscoveryClientFilterTest.java => Fabric8KubernetesDiscoveryClientFilterTest.java} (99%)
 rename spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/{KubernetesDiscoveryClientTest.java => Fabric8KubernetesDiscoveryClientTest.java} (99%)
 rename spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/{KubernetesDiscoveryClientTests.java => Fabric8KubernetesDiscoveryClientTests.java} (99%)
 rename spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/{KubernetesDiscoveryClientUtilsTests.java => Fabric8KubernetesDiscoveryClientUtilsTests.java} (99%)
 rename spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/{KubernetesReactiveDiscoveryClientAutoConfigurationApplicationContextTests.java => Fabric8KubernetesReactiveDiscoveryClientAutoConfigurationApplicationContextTests.java} (98%)
 rename spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/{KubernetesReactiveDiscoveryClientAutoConfigurationTests.java => Fabric8KubernetesReactiveDiscoveryClientAutoConfigurationTests.java} (94%)
 rename spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/{KubernetesReactiveDiscoveryClientTests.java => Fabric8KubernetesReactiveDiscoveryClientTests.java} (99%)

diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryFilterTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryFilterTests.java
index 817b63b2ca..9c6c42d073 100644
--- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryFilterTests.java
+++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryFilterTests.java
@@ -46,9 +46,6 @@
 @EnableKubernetesMockClient(crud = true, https = false)
 class Fabric8DiscoveryFilterTests {
 
-	private static final ServicePortSecureResolver SERVICE_PORT_SECURE_RESOLVER =
-		new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT);
-
 	private static final KubernetesNamespaceProvider NAMESPACE_PROVIDER = new KubernetesNamespaceProvider(mockEnvironment());
 
 	private static KubernetesClient client;
@@ -82,18 +79,16 @@ void afterEach() {
 	void testAllNamespacesWithoutLabelsWithoutFilter() {
 		boolean allNamespaces = true;
 		Map labels = Map.of();
-		String spelFilter = null;
-
-		MockEnvironment environment = new MockEnvironment();
 
 		KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(),
-				true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false);
-
-		List result = services(properties, client, NAMESPACE_PROVIDER, spelFilter, "dummy-target");
+				true, 60L, false, null, Set.of(), labels, null, null, 0, false);
 
 		service("namespaceA", "serviceA", Map.of("color", "red"));
 		service("namespaceB", "serviceB", Map.of("color", "blue"));
 
+		List result = services(properties, client, NAMESPACE_PROVIDER,
+			new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties), "dummy-target");
+
 		Assertions.assertEquals(result.size(), 2);
 		Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA");
 		Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA");
@@ -117,363 +112,314 @@ void testAllNamespacesWithoutLabelsWithoutFilter() {
 	void testAllNamespacesWithLabelsWithoutFilter() {
 		boolean allNamespaces = true;
 		Map labels = Map.of("color", "red");
-		String spelFilter = null;
 
-		MockEnvironment environment = new MockEnvironment();
+		KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(),
+				true, 60L, false, null, Set.of(), labels, null, null, 0, false);
+
+		service("namespaceA", "serviceA", Map.of("color", "red"));
+		service("namespaceB", "serviceB", Map.of("color", "blue"));
+
+		List result = services(properties, client, NAMESPACE_PROVIDER,
+			new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties), "dummy-target");
+		Assertions.assertEquals(result.size(), 1);
+		Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA");
+		Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA");
+	}
+
+	/**
+	 * 
+	 *     - all-namespaces = true
+	 *     - labels = {}
+	 *     - filter = "#root.metadata.namespace matches '^.+A$'"
+	 *       (ends in A)
+	 *
+	 *     - serviceA exists in namespaceA with labels = {color=red}
+	 *     - serviceB exists in namespaceB with labels = {color=blue}
+	 *
+	 *     - we get only serviceA as a result.
+	 * 
+ */ + @Test + void testAllNamespacesWithoutLabelsWithNamespaceFilter() { + boolean allNamespaces = true; + Map labels = Map.of(); + String spelFilter = """ + #root.metadata.namespace matches "^.+A$" + """; KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false); - Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( - new Fabric8KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, - null); + service("namespaceA", "serviceA", Map.of("color", "red")); + service("namespaceB", "serviceB", Map.of("color", "blue")); + + List result = services(properties, client, NAMESPACE_PROVIDER, + new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties), "dummy-target"); + Assertions.assertEquals(result.size(), 1); + Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); + Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); + } + + /** + *
+	 *     - all-namespaces = true
+	 *     - labels = {}
+	 *     - filter = "#root.metadata.namespace matches '^namespace[A|B]$'"
+	 *       (namespaceA or namespaceB)
+	 *
+	 *     - serviceA exists in namespaceA with labels = {color=red}
+	 *     - serviceB exists in namespaceB with labels = {color=blue}
+	 *     - serviceC exists in namespaceC with labels = {color=purple}
+	 *
+	 *     - we get only serviceA and serviceB as a result.
+	 * 
+ */ + @Test + void testAllNamespacesWithoutLabelsWithNamespacesFilter() { + boolean allNamespaces = true; + Map labels = Map.of(); + String spelFilter = """ + #root.metadata.namespace matches "^namespace[A|B]$" + """; + + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), + true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false); service("namespaceA", "serviceA", Map.of("color", "red")); service("namespaceB", "serviceB", Map.of("color", "blue")); + service("namespaceC", "serviceC", Map.of("color", "purple")); + + List result = services(properties, client, NAMESPACE_PROVIDER, + new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties), "dummy-target"); + Assertions.assertEquals(result.size(), 2); + Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); + Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); + Assertions.assertEquals(result.get(1).getMetadata().getName(), "serviceB"); + Assertions.assertEquals(result.get(1).getMetadata().getNamespace(), "namespaceB"); + } + + /** + *
+	 *     - all-namespaces = false
+	 *     - specific namespace = namespaceA
+	 *     - labels = {}
+	 *
+	 *     - serviceA exists in namespaceA with labels = {color=red}
+	 *     - serviceB exists in namespaceB with labels = {color=blue}
+	 *
+	 *     - we get only serviceA as a result.
+	 * 
+ */ + @Test + void testSpecificNamespaceWithoutLabelsWithoutFilter() { + boolean allNamespaces = false; + Map labels = Map.of(); + + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), + true, 60L, false, null, Set.of(), labels, null, null, 0, false); + + utils.when(() -> Fabric8Utils.getApplicationNamespace(Mockito.any(KubernetesClient.class), + Mockito.nullable(String.class), Mockito.anyString(), Mockito.any(KubernetesNamespaceProvider.class))) + .thenReturn("namespaceA"); + + service("namespaceA", "serviceA", Map.of("color", "red")); + service("namespaceB", "serviceB", Map.of("color", "blue")); + + List result = services(properties, client, NAMESPACE_PROVIDER, + new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties), "dummy-target"); + Assertions.assertEquals(result.size(), 1); + Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); + Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); + } + + /** + *
+	 *     - all-namespaces = false
+	 *     - specific namespace = namespaceA
+	 *     - labels = {color = purple}
+	 *
+	 *     - serviceA exists in namespaceA with labels = {color=red}
+	 *     - serviceB exists in namespaceA with labels = {color=purple}
+	 *     - serviceC exists in namespaceC with labels = {color=purple}
+	 *
+	 *     - we get only serviceB as a result, even if such labels are also
+	 *       present on a different service (but it's in a different namespace).
+	 * 
+ */ + @Test + void testSpecificNamespaceWithLabelsWithoutFilter() { + boolean allNamespaces = false; + Map labels = Map.of("color", "purple"); + + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), + true, 60L, false, null, Set.of(), labels, null, null, 0, false); + + utils.when(() -> Fabric8Utils.getApplicationNamespace(Mockito.any(KubernetesClient.class), + Mockito.nullable(String.class), Mockito.anyString(), Mockito.any(KubernetesNamespaceProvider.class))) + .thenReturn("namespaceA"); + + service("namespaceA", "serviceA", Map.of("color", "red")); + service("namespaceA", "serviceB", Map.of("color", "purple")); + service("namespaceC", "serviceC", Map.of("color", "purple")); + + List result = services(properties, client, NAMESPACE_PROVIDER, + new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties), "dummy-target"); + Assertions.assertEquals(result.size(), 1); + Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceB"); + Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); + } + + /** + *
+	 *     - all-namespaces = false
+	 *     - specific namespace = namespaceA
+	 *     - labels = {}
+	 *     - filter = "#root.metadata.labels.containsKey("number")"
+	 *       (namespaceA or namespaceB)
+	 *
+	 *     - serviceA exists in namespaceA with labels = {color=red, number=1}
+	 *     - serviceB exists in namespaceA with labels = {color=purple, cycle=create}
+	 *     - serviceC exists in namespaceC with labels = {color=purple, number=1}
+	 *
+	 *     - we get only serviceB as a result (because of the filter) even if such labels are also
+	 *       present on a different service (but it's in a different namespace).
+	 * 
+ */ + @Test + void testSpecificNamespaceWithoutLabelsWithFilter() { + boolean allNamespaces = false; + Map labels = Map.of(); + String spelFilter = """ + #root.metadata.labels.containsKey("number") + """.stripLeading(); + + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), + true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false); + + utils.when(() -> Fabric8Utils.getApplicationNamespace(Mockito.any(KubernetesClient.class), + Mockito.nullable(String.class), Mockito.anyString(), Mockito.any(KubernetesNamespaceProvider.class))) + .thenReturn("namespaceA"); + + service("namespaceA", "serviceA", Map.of("color", "red", "number", "1")); + service("namespaceA", "serviceB", Map.of("color", "purple", "cycle", "create")); + service("namespaceC", "serviceC", Map.of("color", "purple", "number", "1")); + + List result = services(properties, client, NAMESPACE_PROVIDER, + new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties), "dummy-target"); + Assertions.assertEquals(result.size(), 1); + Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); + Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); + Assertions.assertEquals(result.get(0).getMetadata().getLabels(), Map.of("color", "red", "number", "1")); + } + + /** + *
+	 *     - all-namespaces = false
+	 *     - some namespaces = [namespaceA, namespaceB]
+	 *     - labels = {}
+	 *     - filter = null
+	 *
+	 *     - serviceA exists in namespaceA with labels = {}
+	 *     - serviceB exists in namespaceB with labels = {}
+	 *     - serviceC exists in namespaceC with labels = {}
+	 *
+	 *     - we get serviceA and serviceB as a result, because their namespaces match.
+	 * 
+ */ + @Test + void testSomeNamespacesWithoutLabelsWithoutFilter() { + boolean allNamespaces = false; + Set someNamespaces = Set.of("namespaceA", "namespaceB"); + Map labels = Map.of(); + + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, + someNamespaces, true, 60L, false, null, Set.of(), labels, null, null, 0, false); + + service("namespaceA", "serviceA", Map.of()); + service("namespaceB", "serviceB", Map.of()); + service("namespaceC", "serviceC", Map.of()); + + List result = services(properties, client, NAMESPACE_PROVIDER, + new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties), "dummy-target"); + Assertions.assertEquals(result.size(), 2); + result = result.stream().sorted(Comparator.comparing(x -> x.getMetadata().getName())).toList(); + Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); + Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); + Assertions.assertEquals(result.get(1).getMetadata().getName(), "serviceB"); + Assertions.assertEquals(result.get(1).getMetadata().getNamespace(), "namespaceB"); + } + + /** + *
+	 *     - all-namespaces = false
+	 *     - some namespaces = [namespaceA, namespaceB]
+	 *     - labels = {color=purple}
+	 *     - filter = null
+	 *
+	 *     - serviceA exists in namespaceA with labels = {color=purple}
+	 *     - serviceB exists in namespaceB with labels = {color=red}
+	 *     - serviceC exists in namespaceC with labels = {color=purple}
+	 *
+	 *     - we get serviceA as a result
+	 * 
+ */ + @Test + void testSomeNamespacesWithLabelsWithoutFilter() { + boolean allNamespaces = false; + Set someNamespaces = Set.of("namespaceA", "namespaceB"); + Map labels = Map.of("color", "purple"); + String spelFilter = null; + + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, + someNamespaces, true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false); + + service("namespaceA", "serviceA", Map.of("color", "purple")); + service("namespaceB", "serviceB", Map.of("color", "red")); + service("namespaceC", "serviceC", Map.of("color", "purple")); + + List result = services(properties, client, NAMESPACE_PROVIDER, + new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties), "dummy-target"); + Assertions.assertEquals(result.size(), 1); + Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); + Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); + } + + /** + *
+	 *     - all-namespaces = false
+	 *     - some namespaces = [namespaceA, namespaceB]
+	 *     - labels = {color=purple}
+	 *     - filter = #root.metadata.labels.containsKey("number")
+	 *
+	 *     - serviceA exists in namespaceA with labels = {color=purple}
+	 *     - serviceB exists in namespaceB with labels = {color=red}
+	 *     - serviceC exists in namespaceC with labels = {color=purple}
+	 *
+	 *     - we get serviceA as a result
+	 * 
+ */ + @Test + void testSomeNamespacesWithLabelsWithFilter() { + boolean allNamespaces = false; + Set someNamespaces = Set.of("namespaceA", "namespaceB"); + Map labels = Map.of("color", "purple"); + String spelFilter = """ + #root.metadata.labels.containsKey("number") + """.stripLeading(); + + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, + someNamespaces, true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false); + + service("namespaceA", "serviceA", Map.of("color", "purple", "number", "1")); + service("namespaceB", "serviceB", Map.of("color", "purple", "cycle", "create")); + service("namespaceC", "serviceC", Map.of("color", "purple", "number", "1")); - List result = adapter.apply(client); + List result = services(properties, client, NAMESPACE_PROVIDER, + new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties), "dummy-target"); Assertions.assertEquals(result.size(), 1); Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); } -// -// /** -// *
-//	 *     - all-namespaces = true
-//	 *     - labels = {}
-//	 *     - filter = "#root.metadata.namespace matches '^.+A$'"
-//	 *       (ends in A)
-//	 *
-//	 *     - serviceA exists in namespaceA with labels = {color=red}
-//	 *     - serviceB exists in namespaceB with labels = {color=blue}
-//	 *
-//	 *     - we get only serviceA as a result.
-//	 * 
-// */ -// @Test -// void testAllNamespacesWithoutLabelsWithNamespaceFilter() { -// boolean allNamespaces = true; -// Map labels = Map.of(); -// String spelFilter = """ -// #root.metadata.namespace matches "^.+A$" -// """; -// -// MockEnvironment environment = new MockEnvironment(); -// -// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), -// true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false); -// -// Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( -// new Fabric8KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, -// null); -// -// service("namespaceA", "serviceA", Map.of("color", "red")); -// service("namespaceB", "serviceB", Map.of("color", "blue")); -// -// List result = adapter.apply(client); -// Assertions.assertEquals(result.size(), 1); -// Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); -// Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); -// } -// -// /** -// *
-//	 *     - all-namespaces = true
-//	 *     - labels = {}
-//	 *     - filter = "#root.metadata.namespace matches '^namespace[A|B]$'"
-//	 *       (namespaceA or namespaceB)
-//	 *
-//	 *     - serviceA exists in namespaceA with labels = {color=red}
-//	 *     - serviceB exists in namespaceB with labels = {color=blue}
-//	 *     - serviceC exists in namespaceC with labels = {color=purple}
-//	 *
-//	 *     - we get only serviceA and serviceB as a result.
-//	 * 
-// */ -// @Test -// void testAllNamespacesWithoutLabelsWithNamespacesFilter() { -// boolean allNamespaces = true; -// Map labels = Map.of(); -// String spelFilter = """ -// #root.metadata.namespace matches "^namespace[A|B]$" -// """; -// -// MockEnvironment environment = new MockEnvironment(); -// -// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), -// true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false); -// -// Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( -// new Fabric8KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, -// null); -// -// service("namespaceA", "serviceA", Map.of("color", "red")); -// service("namespaceB", "serviceB", Map.of("color", "blue")); -// service("namespaceC", "serviceC", Map.of("color", "purple")); -// -// List result = adapter.apply(client); -// Assertions.assertEquals(result.size(), 2); -// Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); -// Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); -// Assertions.assertEquals(result.get(1).getMetadata().getName(), "serviceB"); -// Assertions.assertEquals(result.get(1).getMetadata().getNamespace(), "namespaceB"); -// } -// -// /** -// *
-//	 *     - all-namespaces = false
-//	 *     - specific namespace = namespaceA
-//	 *     - labels = {}
-//	 *
-//	 *     - serviceA exists in namespaceA with labels = {color=red}
-//	 *     - serviceB exists in namespaceB with labels = {color=blue}
-//	 *
-//	 *     - we get only serviceA as a result.
-//	 * 
-// */ -// @Test -// void testSpecificNamespaceWithoutLabelsWithoutFilter() { -// boolean allNamespaces = false; -// Map labels = Map.of(); -// String spelFilter = null; -// -// MockEnvironment environment = new MockEnvironment(); -// -// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), -// true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false); -// -// Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( -// new Fabric8KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, -// null); -// -// utils.when(() -> Fabric8Utils.getApplicationNamespace(Mockito.any(KubernetesClient.class), -// Mockito.nullable(String.class), Mockito.anyString(), Mockito.any(KubernetesNamespaceProvider.class))) -// .thenReturn("namespaceA"); -// -// service("namespaceA", "serviceA", Map.of("color", "red")); -// service("namespaceB", "serviceB", Map.of("color", "blue")); -// -// List result = adapter.apply(client); -// Assertions.assertEquals(result.size(), 1); -// Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); -// Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); -// } -// -// /** -// *
-//	 *     - all-namespaces = false
-//	 *     - specific namespace = namespaceA
-//	 *     - labels = {color = purple}
-//	 *
-//	 *     - serviceA exists in namespaceA with labels = {color=red}
-//	 *     - serviceB exists in namespaceA with labels = {color=purple}
-//	 *     - serviceC exists in namespaceC with labels = {color=purple}
-//	 *
-//	 *     - we get only serviceB as a result, even if such labels are also
-//	 *       present on a different service (but it's in a different namespace).
-//	 * 
-// */ -// @Test -// void testSpecificNamespaceWithLabelsWithoutFilter() { -// boolean allNamespaces = false; -// Map labels = Map.of("color", "purple"); -// String spelFilter = null; -// -// MockEnvironment environment = new MockEnvironment(); -// -// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), -// true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false); -// -// Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( -// new Fabric8KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, -// null); -// -// utils.when(() -> Fabric8Utils.getApplicationNamespace(Mockito.any(KubernetesClient.class), -// Mockito.nullable(String.class), Mockito.anyString(), Mockito.any(KubernetesNamespaceProvider.class))) -// .thenReturn("namespaceA"); -// -// service("namespaceA", "serviceA", Map.of("color", "red")); -// service("namespaceA", "serviceB", Map.of("color", "purple")); -// service("namespaceC", "serviceC", Map.of("color", "purple")); -// -// List result = adapter.apply(client); -// Assertions.assertEquals(result.size(), 1); -// Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceB"); -// Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); -// } -// -// /** -// *
-//	 *     - all-namespaces = false
-//	 *     - specific namespace = namespaceA
-//	 *     - labels = {}
-//	 *     - filter = "#root.metadata.labels.containsKey("number")"
-//	 *       (namespaceA or namespaceB)
-//	 *
-//	 *     - serviceA exists in namespaceA with labels = {color=red, number=1}
-//	 *     - serviceB exists in namespaceA with labels = {color=purple, cycle=create}
-//	 *     - serviceC exists in namespaceC with labels = {color=purple, number=1}
-//	 *
-//	 *     - we get only serviceB as a result (because of the filter) even if such labels are also
-//	 *       present on a different service (but it's in a different namespace).
-//	 * 
-// */ -// @Test -// void testSpecificNamespaceWithoutLabelsWithFilter() { -// boolean allNamespaces = false; -// Map labels = Map.of(); -// String spelFilter = """ -// #root.metadata.labels.containsKey("number") -// """.stripLeading(); -// -// MockEnvironment environment = new MockEnvironment(); -// -// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), -// true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false); -// -// Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( -// new Fabric8KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, -// null); -// -// utils.when(() -> Fabric8Utils.getApplicationNamespace(Mockito.any(KubernetesClient.class), -// Mockito.nullable(String.class), Mockito.anyString(), Mockito.any(KubernetesNamespaceProvider.class))) -// .thenReturn("namespaceA"); -// -// service("namespaceA", "serviceA", Map.of("color", "red", "number", "1")); -// service("namespaceA", "serviceB", Map.of("color", "purple", "cycle", "create")); -// service("namespaceC", "serviceC", Map.of("color", "purple", "number", "1")); -// -// List result = adapter.apply(client); -// Assertions.assertEquals(result.size(), 1); -// Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); -// Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); -// Assertions.assertEquals(result.get(0).getMetadata().getLabels(), Map.of("color", "red", "number", "1")); -// } -// -// /** -// *
-//	 *     - all-namespaces = false
-//	 *     - some namespaces = [namespaceA, namespaceB]
-//	 *     - labels = {}
-//	 *     - filter = null
-//	 *
-//	 *     - serviceA exists in namespaceA with labels = {}
-//	 *     - serviceB exists in namespaceB with labels = {}
-//	 *     - serviceC exists in namespaceC with labels = {}
-//	 *
-//	 *     - we get serviceA and serviceB as a result, because their namespaces match.
-//	 * 
-// */ -// @Test -// void testSomeNamespacesWithoutLabelsWithoutFilter() { -// boolean allNamespaces = false; -// Set someNamespaces = Set.of("namespaceA", "namespaceB"); -// Map labels = Map.of(); -// String spelFilter = null; -// -// MockEnvironment environment = new MockEnvironment(); -// -// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, -// someNamespaces, true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false); -// -// Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( -// new Fabric8KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, -// null); -// -// service("namespaceA", "serviceA", Map.of()); -// service("namespaceB", "serviceB", Map.of()); -// service("namespaceC", "serviceC", Map.of()); -// -// List result = adapter.apply(client); -// Assertions.assertEquals(result.size(), 2); -// result = result.stream().sorted(Comparator.comparing(x -> x.getMetadata().getName())).toList(); -// Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); -// Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); -// Assertions.assertEquals(result.get(1).getMetadata().getName(), "serviceB"); -// Assertions.assertEquals(result.get(1).getMetadata().getNamespace(), "namespaceB"); -// } -// -// /** -// *
-//	 *     - all-namespaces = false
-//	 *     - some namespaces = [namespaceA, namespaceB]
-//	 *     - labels = {color=purple}
-//	 *     - filter = null
-//	 *
-//	 *     - serviceA exists in namespaceA with labels = {color=purple}
-//	 *     - serviceB exists in namespaceB with labels = {color=red}
-//	 *     - serviceC exists in namespaceC with labels = {color=purple}
-//	 *
-//	 *     - we get serviceA as a result
-//	 * 
-// */ -// @Test -// void testSomeNamespacesWithLabelsWithoutFilter() { -// boolean allNamespaces = false; -// Set someNamespaces = Set.of("namespaceA", "namespaceB"); -// Map labels = Map.of("color", "purple"); -// String spelFilter = null; -// -// MockEnvironment environment = new MockEnvironment(); -// -// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, -// someNamespaces, true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false); -// -// Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( -// new Fabric8KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, -// null); -// -// service("namespaceA", "serviceA", Map.of("color", "purple")); -// service("namespaceB", "serviceB", Map.of("color", "red")); -// service("namespaceC", "serviceC", Map.of("color", "purple")); -// -// List result = adapter.apply(client); -// Assertions.assertEquals(result.size(), 1); -// Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); -// Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); -// } -// -// /** -// *
-//	 *     - all-namespaces = false
-//	 *     - some namespaces = [namespaceA, namespaceB]
-//	 *     - labels = {color=purple}
-//	 *     - filter = #root.metadata.labels.containsKey("number")
-//	 *
-//	 *     - serviceA exists in namespaceA with labels = {color=purple}
-//	 *     - serviceB exists in namespaceB with labels = {color=red}
-//	 *     - serviceC exists in namespaceC with labels = {color=purple}
-//	 *
-//	 *     - we get serviceA as a result
-//	 * 
-// */ -// @Test -// void testSomeNamespacesWithLabelsWithFilter() { -// boolean allNamespaces = false; -// Set someNamespaces = Set.of("namespaceA", "namespaceB"); -// Map labels = Map.of("color", "purple"); -// String spelFilter = """ -// #root.metadata.labels.containsKey("number") -// """.stripLeading(); -// -// MockEnvironment environment = new MockEnvironment(); -// -// KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, -// someNamespaces, true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false); -// -// Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( -// new Fabric8KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, -// null); -// -// service("namespaceA", "serviceA", Map.of("color", "purple", "number", "1")); -// service("namespaceB", "serviceB", Map.of("color", "purple", "cycle", "create")); -// service("namespaceC", "serviceC", Map.of("color", "purple", "number", "1")); -// -// List result = adapter.apply(client); -// Assertions.assertEquals(result.size(), 1); -// Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); -// Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); -// } private void service(String namespace, String name, Map labels) { client.services().inNamespace(namespace) diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesCatalogServicesWatchConfigurationTest.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogServicesWatchConfigurationTest.java similarity index 98% rename from spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesCatalogServicesWatchConfigurationTest.java rename to spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogServicesWatchConfigurationTest.java index eac9f9a137..9b9fef8f36 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesCatalogServicesWatchConfigurationTest.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogServicesWatchConfigurationTest.java @@ -42,7 +42,7 @@ * @author Oleg Vyukov * @author Tim Ysewyn */ -class KubernetesCatalogServicesWatchConfigurationTest { +class Fabric8KubernetesCatalogServicesWatchConfigurationTest { private ConfigurableApplicationContext context; diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesCatalogWatchAutoConfigurationApplicationContextTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchAutoConfigurationApplicationContextTests.java similarity index 98% rename from spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesCatalogWatchAutoConfigurationApplicationContextTests.java rename to spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchAutoConfigurationApplicationContextTests.java index a5969dda2d..c46a7debe6 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesCatalogWatchAutoConfigurationApplicationContextTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchAutoConfigurationApplicationContextTests.java @@ -29,7 +29,7 @@ /** * @author wind57 */ -class KubernetesCatalogWatchAutoConfigurationApplicationContextTests { +class Fabric8KubernetesCatalogWatchAutoConfigurationApplicationContextTests { private ApplicationContextRunner applicationContextRunner; diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesCatalogWatchTest.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchTest.java similarity index 99% rename from spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesCatalogWatchTest.java rename to spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchTest.java index 67a5c0000e..73f2d22669 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesCatalogWatchTest.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchTest.java @@ -54,7 +54,7 @@ * @author Oleg Vyukov */ @SuppressWarnings({ "unchecked" }) -class KubernetesCatalogWatchTest { +class Fabric8KubernetesCatalogWatchTest { private static final KubernetesClient CLIENT = Mockito.mock(KubernetesClient.class); diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientAutoConfigurationApplicationContextTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAutoConfigurationApplicationContextTests.java similarity index 98% rename from spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientAutoConfigurationApplicationContextTests.java rename to spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAutoConfigurationApplicationContextTests.java index 56cb122df0..b3b59ee504 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientAutoConfigurationApplicationContextTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAutoConfigurationApplicationContextTests.java @@ -34,7 +34,7 @@ * * @author wind57 */ -class KubernetesDiscoveryClientAutoConfigurationApplicationContextTests { +class Fabric8KubernetesDiscoveryClientAutoConfigurationApplicationContextTests { private ApplicationContextRunner applicationContextRunner; diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientAutoConfigurationPropertiesTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAutoConfigurationPropertiesTests.java similarity index 98% rename from spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientAutoConfigurationPropertiesTests.java rename to spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAutoConfigurationPropertiesTests.java index ba6c9496f6..620e465f67 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientAutoConfigurationPropertiesTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAutoConfigurationPropertiesTests.java @@ -42,7 +42,7 @@ * @author Ryan Dawson * @author Tim Ysewyn */ -class KubernetesDiscoveryClientAutoConfigurationPropertiesTests { +class Fabric8KubernetesDiscoveryClientAutoConfigurationPropertiesTests { private ConfigurableApplicationContext context; diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientAutoConfigurationTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAutoConfigurationTests.java similarity index 96% rename from spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientAutoConfigurationTests.java rename to spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAutoConfigurationTests.java index 583f55a833..b612c4a0fd 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientAutoConfigurationTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAutoConfigurationTests.java @@ -29,7 +29,7 @@ @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { "spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", "spring.cloud.kubernetes.discovery.use-endpoint-slices=false" }) -class KubernetesDiscoveryClientAutoConfigurationTests { +class Fabric8KubernetesDiscoveryClientAutoConfigurationTests { @Autowired private DiscoveryClient discoveryClient; diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientConfigClientBootstrapConfigurationTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientConfigClientBootstrapConfigurationTests.java similarity index 98% rename from spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientConfigClientBootstrapConfigurationTests.java rename to spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientConfigClientBootstrapConfigurationTests.java index b561fe5329..ba53a1f774 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientConfigClientBootstrapConfigurationTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientConfigClientBootstrapConfigurationTests.java @@ -43,7 +43,7 @@ /** * @author Zhanwei Wang */ -class KubernetesDiscoveryClientConfigClientBootstrapConfigurationTests { +class Fabric8KubernetesDiscoveryClientConfigClientBootstrapConfigurationTests { private AnnotationConfigApplicationContext context; diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientFilterMetadataTest.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientFilterMetadataTest.java similarity index 99% rename from spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientFilterMetadataTest.java rename to spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientFilterMetadataTest.java index 5a8c890393..47281b91b6 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientFilterMetadataTest.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientFilterMetadataTest.java @@ -58,7 +58,7 @@ import static org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties.Metadata; @SuppressWarnings("unchecked") -class KubernetesDiscoveryClientFilterMetadataTest { +class Fabric8KubernetesDiscoveryClientFilterMetadataTest { private static final ServicePortSecureResolver SERVICE_PORT_SECURE_RESOLVER = new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT); diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientFilterTest.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientFilterTest.java similarity index 99% rename from spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientFilterTest.java rename to spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientFilterTest.java index f70ce045c0..1a0e3b2cc5 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientFilterTest.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientFilterTest.java @@ -42,7 +42,7 @@ import static org.mockito.Mockito.when; @SuppressWarnings("unchecked") -class KubernetesDiscoveryClientFilterTest { +class Fabric8KubernetesDiscoveryClientFilterTest { private static final ServicePortSecureResolver SERVICE_PORT_SECURE_RESOLVER = new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT); diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientTest.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientTest.java similarity index 99% rename from spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientTest.java rename to spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientTest.java index 21a2bc508b..fa20cdd652 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientTest.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientTest.java @@ -46,7 +46,7 @@ import static org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties.Metadata; @EnableKubernetesMockClient(crud = true, https = false) -class KubernetesDiscoveryClientTest { +class Fabric8KubernetesDiscoveryClientTest { private static final ServicePortSecureResolver SERVICE_PORT_SECURE_RESOLVER = new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT); diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientTests.java similarity index 99% rename from spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientTests.java rename to spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientTests.java index c58d9984cd..332454f413 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientTests.java @@ -42,7 +42,7 @@ */ @EnableKubernetesMockClient(crud = true, https = false) @ExtendWith(OutputCaptureExtension.class) -class KubernetesDiscoveryClientTests { +class Fabric8KubernetesDiscoveryClientTests { private static KubernetesClient client; diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtilsTests.java similarity index 99% rename from spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java rename to spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtilsTests.java index d1c35f3fbc..53f6d18e14 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtilsTests.java @@ -48,7 +48,7 @@ * @author wind57 */ @ExtendWith(OutputCaptureExtension.class) -class KubernetesDiscoveryClientUtilsTests { +class Fabric8KubernetesDiscoveryClientUtilsTests { @Test void testSubsetsFromEndpointsEmptySubsets() { diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesReactiveDiscoveryClientAutoConfigurationApplicationContextTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientAutoConfigurationApplicationContextTests.java similarity index 98% rename from spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesReactiveDiscoveryClientAutoConfigurationApplicationContextTests.java rename to spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientAutoConfigurationApplicationContextTests.java index 28d2d42844..089683a75f 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesReactiveDiscoveryClientAutoConfigurationApplicationContextTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientAutoConfigurationApplicationContextTests.java @@ -36,7 +36,7 @@ * * @author wind57 */ -class KubernetesReactiveDiscoveryClientAutoConfigurationApplicationContextTests { +class Fabric8KubernetesReactiveDiscoveryClientAutoConfigurationApplicationContextTests { private ApplicationContextRunner applicationContextRunner; diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesReactiveDiscoveryClientAutoConfigurationTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientAutoConfigurationTests.java similarity index 94% rename from spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesReactiveDiscoveryClientAutoConfigurationTests.java rename to spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientAutoConfigurationTests.java index cffd95a9a4..46e520b1b6 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesReactiveDiscoveryClientAutoConfigurationTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientAutoConfigurationTests.java @@ -28,15 +28,13 @@ import org.springframework.cloud.kubernetes.commons.KubernetesCommonsAutoConfiguration; import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryPropertiesAutoConfiguration; import org.springframework.cloud.kubernetes.fabric8.Fabric8AutoConfiguration; -import org.springframework.cloud.kubernetes.fabric8.discovery.Fabric8KubernetesDiscoveryClientAutoConfiguration; -import org.springframework.cloud.kubernetes.fabric8.discovery.Fabric8KubernetesReactiveDiscoveryClientAutoConfiguration; import static org.assertj.core.api.Assertions.assertThat; /** * @author Tim Ysewyn */ -class KubernetesReactiveDiscoveryClientAutoConfigurationTests { +class Fabric8KubernetesReactiveDiscoveryClientAutoConfigurationTests { private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() .withConfiguration(AutoConfigurations.of(UtilAutoConfiguration.class, diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesReactiveDiscoveryClientTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientTests.java similarity index 99% rename from spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesReactiveDiscoveryClientTests.java rename to spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientTests.java index 5cc5f50c85..afd4d8cddf 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesReactiveDiscoveryClientTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientTests.java @@ -52,7 +52,7 @@ * @author Tim Ysewyn */ @EnableKubernetesMockClient(crud = true, https = false) -class KubernetesReactiveDiscoveryClientTests { +class Fabric8KubernetesReactiveDiscoveryClientTests { private static final ServicePortSecureResolver SERVICE_PORT_SECURE_RESOLVER = new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT); From 9fbf4c12f4231dc18f9f5c31518188a442b8994a Mon Sep 17 00:00:00 2001 From: wind57 Date: Sun, 26 Feb 2023 17:59:24 +0200 Subject: [PATCH 028/151] first fraft --- ...overyClientPredicateAutoConfiguration.java | 11 ++- .../Fabric8EndpointSliceV1CatalogWatch.java | 3 +- .../Fabric8KubernetesCatalogWatch.java | 2 +- ...bernetesCatalogWatchAutoConfiguration.java | 2 +- .../Fabric8KubernetesDiscoveryClient.java | 7 +- ...netesDiscoveryClientAutoConfiguration.java | 11 ++- ...Fabric8KubernetesDiscoveryClientUtils.java | 34 +++++---- ...ctiveDiscoveryClientAutoConfiguration.java | 11 ++- .../discovery/ServicePortSecureResolver.java | 2 +- .../Fabric8DiscoveryFilterTests.java | 23 +++--- ...abric8EndpointsAndEndpointSlicesTests.java | 19 +++-- ...CatalogServicesWatchConfigurationTest.java | 7 +- ...oConfigurationApplicationContextTests.java | 10 ++- ...atalogWatchEndpointSlicesSupportTests.java | 12 ++- ...rnetesCatalogWatchEndpointSlicesTests.java | 19 ++--- ...8KubernetesCatalogWatchEndpointsTests.java | 19 ++--- ...oConfigurationApplicationContextTests.java | 7 +- ...lientAutoConfigurationPropertiesTests.java | 4 +- ...DiscoveryClientAutoConfigurationTests.java | 5 +- ...nfigClientBootstrapConfigurationTests.java | 2 +- ...etesDiscoveryClientFilterMetadataTest.java | 39 +++++----- ...c8KubernetesDiscoveryClientFilterTest.java | 15 ++-- .../Fabric8KubernetesDiscoveryClientTest.java | 64 ++++++++-------- ...Fabric8KubernetesDiscoveryClientTests.java | 48 ++++++++---- ...c8KubernetesDiscoveryClientUtilsTests.java | 54 +++++++------ ...oConfigurationApplicationContextTests.java | 76 ++++++++++--------- ...DiscoveryClientAutoConfigurationTests.java | 9 ++- ...ubernetesReactiveDiscoveryClientTests.java | 61 +++++++-------- .../ServicePortSecureResolverTest.java | 12 +-- 29 files changed, 316 insertions(+), 272 deletions(-) diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryClientPredicateAutoConfiguration.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryClientPredicateAutoConfiguration.java index 2f0f4483fa..5d7182eb6f 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryClientPredicateAutoConfiguration.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryClientPredicateAutoConfiguration.java @@ -16,15 +16,17 @@ package org.springframework.cloud.kubernetes.fabric8.discovery; +import java.util.Optional; +import java.util.function.Predicate; + import io.fabric8.kubernetes.api.model.Service; + import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnCloudPlatform; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.cloud.CloudPlatform; -import org.springframework.cloud.client.ConditionalOnBlockingDiscoveryEnabled; import org.springframework.cloud.client.ConditionalOnDiscoveryEnabled; import org.springframework.cloud.kubernetes.commons.discovery.ConditionalOnBlockingOrReactiveEnabled; -import org.springframework.cloud.kubernetes.commons.discovery.ConditionalOnKubernetesDiscoveryEnabled; import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryPropertiesAutoConfiguration; import org.springframework.context.annotation.Bean; @@ -33,9 +35,6 @@ import org.springframework.expression.spel.standard.SpelExpressionParser; import org.springframework.expression.spel.support.SimpleEvaluationContext; -import java.util.Optional; -import java.util.function.Predicate; - /** * @author wind57 */ @@ -51,7 +50,7 @@ class Fabric8DiscoveryClientPredicateAutoConfiguration { Predicate predicate(KubernetesDiscoveryProperties properties) { SpelExpressionParser parser = new SpelExpressionParser(); SimpleEvaluationContext evaluationContext = SimpleEvaluationContext.forReadOnlyDataBinding() - .withInstanceMethods().build(); + .withInstanceMethods().build(); String spelExpression = properties.filter(); Predicate predicate; diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8EndpointSliceV1CatalogWatch.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8EndpointSliceV1CatalogWatch.java index b2dc19d854..0ec47ac4d6 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8EndpointSliceV1CatalogWatch.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8EndpointSliceV1CatalogWatch.java @@ -25,6 +25,7 @@ import io.fabric8.kubernetes.api.model.discovery.v1.EndpointSlice; import org.springframework.cloud.kubernetes.commons.discovery.EndpointNameAndNamespace; + import static org.springframework.cloud.kubernetes.fabric8.discovery.Fabric8KubernetesDiscoveryClientUtils.endpointSlices; /** @@ -38,7 +39,7 @@ final class Fabric8EndpointSliceV1CatalogWatch @Override public List apply(Fabric8CatalogWatchContext context) { List endpointSlices = endpointSlices(context.properties(), context.kubernetesClient(), - context.namespaceProvider(), "catalog-watcher"); + context.namespaceProvider(), "catalog-watcher"); Stream references = endpointSlices.stream().map(EndpointSlice::getEndpoints) .flatMap(List::stream).map(Endpoint::getTargetRef); diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatch.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatch.java index f9f69355f3..3691dd0979 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatch.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatch.java @@ -56,7 +56,7 @@ final class Fabric8KubernetesCatalogWatch implements ApplicationEventPublisherAw private ApplicationEventPublisher publisher; - public Fabric8KubernetesCatalogWatch(KubernetesClient kubernetesClient, KubernetesDiscoveryProperties properties, + Fabric8KubernetesCatalogWatch(KubernetesClient kubernetesClient, KubernetesDiscoveryProperties properties, KubernetesNamespaceProvider namespaceProvider) { context = new Fabric8CatalogWatchContext(kubernetesClient, properties, namespaceProvider); } diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchAutoConfiguration.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchAutoConfiguration.java index f2a7b85ebd..f7b2c4e651 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchAutoConfiguration.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchAutoConfiguration.java @@ -47,7 +47,7 @@ class Fabric8KubernetesCatalogWatchAutoConfiguration { @Bean @ConditionalOnMissingBean Fabric8KubernetesCatalogWatch kubernetesCatalogWatch(KubernetesClient client, - KubernetesDiscoveryProperties properties, Environment environment) { + KubernetesDiscoveryProperties properties, Environment environment) { return new Fabric8KubernetesCatalogWatch(client, properties, new KubernetesNamespaceProvider(environment)); } diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClient.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClient.java index 163f236bf9..b2587b78bb 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClient.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClient.java @@ -64,8 +64,7 @@ final class Fabric8KubernetesDiscoveryClient implements DiscoveryClient { Fabric8KubernetesDiscoveryClient(KubernetesClient client, KubernetesDiscoveryProperties kubernetesDiscoveryProperties, - ServicePortSecureResolver servicePortSecureResolver, - KubernetesNamespaceProvider namespaceProvider, + ServicePortSecureResolver servicePortSecureResolver, KubernetesNamespaceProvider namespaceProvider, Predicate predicate) { this.client = client; @@ -128,8 +127,8 @@ private List getNamespaceServiceInstances(EndpointSubsetNS es, @Override public List getServices() { - return services(properties, client, namespaceProvider, predicate, "fabric8 discovery") - .stream().map(service -> service.getMetadata().getName()).toList(); + return services(properties, client, namespaceProvider, predicate, "fabric8 discovery").stream() + .map(service -> service.getMetadata().getName()).toList(); } @Override diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAutoConfiguration.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAutoConfiguration.java index 808af213fc..ae30d711b9 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAutoConfiguration.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAutoConfiguration.java @@ -16,6 +16,8 @@ package org.springframework.cloud.kubernetes.fabric8.discovery; +import java.util.function.Predicate; + import io.fabric8.kubernetes.api.model.Service; import io.fabric8.kubernetes.client.KubernetesClient; @@ -43,8 +45,6 @@ import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; -import java.util.function.Predicate; - /** * Auto configuration for discovery clients. * @@ -58,7 +58,7 @@ @ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES) @AutoConfigureBefore({ SimpleDiscoveryClientAutoConfiguration.class, CommonsClientAutoConfiguration.class }) @AutoConfigureAfter({ Fabric8AutoConfiguration.class, KubernetesDiscoveryPropertiesAutoConfiguration.class, - Fabric8DiscoveryClientPredicateAutoConfiguration.class }) + Fabric8DiscoveryClientPredicateAutoConfiguration.class }) class Fabric8KubernetesDiscoveryClientAutoConfiguration { @Bean @@ -67,9 +67,8 @@ Fabric8KubernetesDiscoveryClient kubernetesDiscoveryClient(KubernetesClient clie KubernetesDiscoveryProperties properties, Predicate predicate, Environment environment) { ServicePortSecureResolver servicePortSecureResolver = new ServicePortSecureResolver(properties); KubernetesNamespaceProvider namespaceProvider = new KubernetesNamespaceProvider(environment); - return new Fabric8KubernetesDiscoveryClient( - client, properties, servicePortSecureResolver, namespaceProvider, predicate - ); + return new Fabric8KubernetesDiscoveryClient(client, properties, servicePortSecureResolver, namespaceProvider, + predicate); } @Bean diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtils.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtils.java index c6b42d0138..0891632bda 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtils.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtils.java @@ -63,7 +63,8 @@ */ final class Fabric8KubernetesDiscoveryClientUtils { - private static final LogAccessor LOG = new LogAccessor(LogFactory.getLog(Fabric8KubernetesDiscoveryClientUtils.class)); + private static final LogAccessor LOG = new LogAccessor( + LogFactory.getLog(Fabric8KubernetesDiscoveryClientUtils.class)); private Fabric8KubernetesDiscoveryClientUtils() { @@ -184,14 +185,15 @@ static List services(KubernetesDiscoveryProperties properties, Kubernet else if (!properties.namespaces().isEmpty()) { LOG.debug(() -> "discovering services in namespaces : " + properties.namespaces()); List inner = new ArrayList<>(properties.namespaces().size()); - properties.namespaces().forEach(namespace -> inner.addAll(filteredServices( - client.services().inNamespace(namespace).withNewFilter(), properties, predicate))); + properties.namespaces().forEach(namespace -> inner.addAll( + filteredServices(client.services().inNamespace(namespace).withNewFilter(), properties, predicate))); services = inner; } else { String namespace = Fabric8Utils.getApplicationNamespace(client, null, target, namespaceProvider); LOG.debug(() -> "discovering services in namespace : " + namespace); - services = filteredServices(client.services().inNamespace(namespace).withNewFilter(), properties, predicate); + services = filteredServices(client.services().inNamespace(namespace).withNewFilter(), properties, + predicate); } return services; @@ -204,19 +206,23 @@ static List endpointSlices(KubernetesDiscoveryProperties properti if (properties.allNamespaces()) { LOG.debug(() -> "discovering endpoint slices in all namespaces"); - endpointSlices = filteredEndpointSlices(client.discovery().v1().endpointSlices().inAnyNamespace().withNewFilter(), properties); + endpointSlices = filteredEndpointSlices( + client.discovery().v1().endpointSlices().inAnyNamespace().withNewFilter(), properties); } else if (!properties.namespaces().isEmpty()) { LOG.debug(() -> "discovering endpoint slices in namespaces : " + properties.namespaces()); List inner = new ArrayList<>(properties.namespaces().size()); - properties.namespaces().forEach(namespace -> inner.addAll(filteredEndpointSlices( - client.discovery().v1().endpointSlices().inNamespace(namespace).withNewFilter(), properties))); + properties.namespaces() + .forEach(namespace -> inner.addAll(filteredEndpointSlices( + client.discovery().v1().endpointSlices().inNamespace(namespace).withNewFilter(), + properties))); endpointSlices = inner; } else { String namespace = Fabric8Utils.getApplicationNamespace(client, null, target, namespaceProvider); LOG.debug(() -> "discovering endpoint slices in namespace : " + namespace); - endpointSlices = filteredEndpointSlices(client.discovery().v1().endpointSlices().inNamespace(namespace).withNewFilter(), properties); + endpointSlices = filteredEndpointSlices( + client.discovery().v1().endpointSlices().inNamespace(namespace).withNewFilter(), properties); } return endpointSlices; @@ -298,22 +304,22 @@ static ServiceInstance serviceInstance(ServicePortSecureResolver servicePortSecu } private static List filteredEndpointSlices( - FilterNested>> filterNested, - KubernetesDiscoveryProperties properties) { + FilterNested>> filterNested, + KubernetesDiscoveryProperties properties) { FilterNested>> partial = filterNested - .withLabels(properties.serviceLabels()); + .withLabels(properties.serviceLabels()); return partial.endFilter().list().getItems(); } private static List filteredServices( - FilterNested>> filterNested, - KubernetesDiscoveryProperties properties, Predicate predicate) { + FilterNested>> filterNested, + KubernetesDiscoveryProperties properties, Predicate predicate) { FilterNested>> partial = filterNested - .withLabels(properties.serviceLabels()); + .withLabels(properties.serviceLabels()); return partial.endFilter().list().getItems().stream().filter(predicate).toList(); diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientAutoConfiguration.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientAutoConfiguration.java index 33ab754d70..200a6454f1 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientAutoConfiguration.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientAutoConfiguration.java @@ -16,6 +16,8 @@ package org.springframework.cloud.kubernetes.fabric8.discovery; +import java.util.function.Predicate; + import io.fabric8.kubernetes.api.model.Service; import io.fabric8.kubernetes.client.KubernetesClient; @@ -41,8 +43,6 @@ import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; -import java.util.function.Predicate; - /** * Auto configuration for reactive discovery client. * @@ -66,9 +66,8 @@ Fabric8KubernetesReactiveDiscoveryClient kubernetesReactiveDiscoveryClient(Kuber KubernetesDiscoveryProperties properties, Predicate predicate, Environment environment) { ServicePortSecureResolver servicePortSecureResolver = new ServicePortSecureResolver(properties); KubernetesNamespaceProvider namespaceProvider = new KubernetesNamespaceProvider(environment); - Fabric8KubernetesDiscoveryClient fabric8KubernetesDiscoveryClient = new Fabric8KubernetesDiscoveryClient( - client, properties, servicePortSecureResolver, namespaceProvider, predicate - ); + Fabric8KubernetesDiscoveryClient fabric8KubernetesDiscoveryClient = new Fabric8KubernetesDiscoveryClient(client, + properties, servicePortSecureResolver, namespaceProvider, predicate); return new Fabric8KubernetesReactiveDiscoveryClient(fabric8KubernetesDiscoveryClient); } @@ -76,7 +75,7 @@ Fabric8KubernetesReactiveDiscoveryClient kubernetesReactiveDiscoveryClient(Kuber @ConditionalOnClass(name = "org.springframework.boot.actuate.health.ReactiveHealthIndicator") @ConditionalOnDiscoveryHealthIndicatorEnabled ReactiveDiscoveryClientHealthIndicator kubernetesReactiveDiscoveryClientHealthIndicator( - Fabric8KubernetesReactiveDiscoveryClient client, DiscoveryClientHealthIndicatorProperties properties) { + Fabric8KubernetesReactiveDiscoveryClient client, DiscoveryClientHealthIndicatorProperties properties) { return new ReactiveDiscoveryClientHealthIndicator(client, properties); } diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/ServicePortSecureResolver.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/ServicePortSecureResolver.java index 082e4e912e..add845e9e2 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/ServicePortSecureResolver.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/ServicePortSecureResolver.java @@ -83,7 +83,7 @@ private static void logEntry(String serviceName, Integer port, String reason) { record Input(Integer port, String serviceName, Map serviceLabels, Map serviceAnnotations) { - public Input(Integer port, String serviceName, Map serviceLabels, + Input(Integer port, String serviceName, Map serviceLabels, Map serviceAnnotations) { this.port = port; this.serviceName = serviceName; diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryFilterTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryFilterTests.java index 9c6c42d073..c4bbf91f3f 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryFilterTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryFilterTests.java @@ -46,7 +46,8 @@ @EnableKubernetesMockClient(crud = true, https = false) class Fabric8DiscoveryFilterTests { - private static final KubernetesNamespaceProvider NAMESPACE_PROVIDER = new KubernetesNamespaceProvider(mockEnvironment()); + private static final KubernetesNamespaceProvider NAMESPACE_PROVIDER = new KubernetesNamespaceProvider( + mockEnvironment()); private static KubernetesClient client; @@ -87,7 +88,7 @@ void testAllNamespacesWithoutLabelsWithoutFilter() { service("namespaceB", "serviceB", Map.of("color", "blue")); List result = services(properties, client, NAMESPACE_PROVIDER, - new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties), "dummy-target"); + new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties), "dummy-target"); Assertions.assertEquals(result.size(), 2); Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); @@ -120,7 +121,7 @@ void testAllNamespacesWithLabelsWithoutFilter() { service("namespaceB", "serviceB", Map.of("color", "blue")); List result = services(properties, client, NAMESPACE_PROVIDER, - new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties), "dummy-target"); + new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties), "dummy-target"); Assertions.assertEquals(result.size(), 1); Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); @@ -154,7 +155,7 @@ void testAllNamespacesWithoutLabelsWithNamespaceFilter() { service("namespaceB", "serviceB", Map.of("color", "blue")); List result = services(properties, client, NAMESPACE_PROVIDER, - new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties), "dummy-target"); + new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties), "dummy-target"); Assertions.assertEquals(result.size(), 1); Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); @@ -190,7 +191,7 @@ void testAllNamespacesWithoutLabelsWithNamespacesFilter() { service("namespaceC", "serviceC", Map.of("color", "purple")); List result = services(properties, client, NAMESPACE_PROVIDER, - new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties), "dummy-target"); + new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties), "dummy-target"); Assertions.assertEquals(result.size(), 2); Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); @@ -226,7 +227,7 @@ void testSpecificNamespaceWithoutLabelsWithoutFilter() { service("namespaceB", "serviceB", Map.of("color", "blue")); List result = services(properties, client, NAMESPACE_PROVIDER, - new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties), "dummy-target"); + new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties), "dummy-target"); Assertions.assertEquals(result.size(), 1); Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); @@ -263,7 +264,7 @@ void testSpecificNamespaceWithLabelsWithoutFilter() { service("namespaceC", "serviceC", Map.of("color", "purple")); List result = services(properties, client, NAMESPACE_PROVIDER, - new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties), "dummy-target"); + new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties), "dummy-target"); Assertions.assertEquals(result.size(), 1); Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceB"); Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); @@ -305,7 +306,7 @@ void testSpecificNamespaceWithoutLabelsWithFilter() { service("namespaceC", "serviceC", Map.of("color", "purple", "number", "1")); List result = services(properties, client, NAMESPACE_PROVIDER, - new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties), "dummy-target"); + new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties), "dummy-target"); Assertions.assertEquals(result.size(), 1); Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); @@ -340,7 +341,7 @@ void testSomeNamespacesWithoutLabelsWithoutFilter() { service("namespaceC", "serviceC", Map.of()); List result = services(properties, client, NAMESPACE_PROVIDER, - new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties), "dummy-target"); + new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties), "dummy-target"); Assertions.assertEquals(result.size(), 2); result = result.stream().sorted(Comparator.comparing(x -> x.getMetadata().getName())).toList(); Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); @@ -378,7 +379,7 @@ void testSomeNamespacesWithLabelsWithoutFilter() { service("namespaceC", "serviceC", Map.of("color", "purple")); List result = services(properties, client, NAMESPACE_PROVIDER, - new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties), "dummy-target"); + new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties), "dummy-target"); Assertions.assertEquals(result.size(), 1); Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); @@ -415,7 +416,7 @@ void testSomeNamespacesWithLabelsWithFilter() { service("namespaceC", "serviceC", Map.of("color", "purple", "number", "1")); List result = services(properties, client, NAMESPACE_PROVIDER, - new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties), "dummy-target"); + new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties), "dummy-target"); Assertions.assertEquals(result.size(), 1); Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8EndpointsAndEndpointSlicesTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8EndpointsAndEndpointSlicesTests.java index 0d7829e10e..5f393bec3b 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8EndpointsAndEndpointSlicesTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8EndpointsAndEndpointSlicesTests.java @@ -233,13 +233,14 @@ void afterEach() { */ abstract void testTwoNamespacesOutOfThree(); - Fabric8KubernetesCatalogWatch createWatcherInAllNamespacesWithLabels(Map labels, Set namespaces, - boolean endpointSlices) { + Fabric8KubernetesCatalogWatch createWatcherInAllNamespacesWithLabels(Map labels, + Set namespaces, boolean endpointSlices) { boolean allNamespaces = true; KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, true, 60, false, "", Set.of(), labels, "", null, 0, endpointSlices); - Fabric8KubernetesCatalogWatch watch = new Fabric8KubernetesCatalogWatch(mockClient(), properties, NAMESPACE_PROVIDER); + Fabric8KubernetesCatalogWatch watch = new Fabric8KubernetesCatalogWatch(mockClient(), properties, + NAMESPACE_PROVIDER); if (endpointSlices) { watch = Mockito.spy(watch); @@ -252,15 +253,16 @@ Fabric8KubernetesCatalogWatch createWatcherInAllNamespacesWithLabels(Map labels, - boolean endpointSlices) { + Fabric8KubernetesCatalogWatch createWatcherInSpecificNamespaceWithLabels(String namespace, + Map labels, boolean endpointSlices) { when(NAMESPACE_PROVIDER.getNamespace()).thenReturn(namespace); boolean allNamespaces = false; KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, Set.of(namespace), true, 60, false, "", Set.of(), labels, "", null, 0, endpointSlices); - Fabric8KubernetesCatalogWatch watch = new Fabric8KubernetesCatalogWatch(mockClient(), properties, NAMESPACE_PROVIDER); + Fabric8KubernetesCatalogWatch watch = new Fabric8KubernetesCatalogWatch(mockClient(), properties, + NAMESPACE_PROVIDER); if (endpointSlices) { watch = Mockito.spy(watch); @@ -274,12 +276,13 @@ Fabric8KubernetesCatalogWatch createWatcherInSpecificNamespaceWithLabels(String } Fabric8KubernetesCatalogWatch createWatcherInSpecificNamespacesWithLabels(Set namespaces, - Map labels, boolean endpointSlices) { + Map labels, boolean endpointSlices) { // all-namespaces = false KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, namespaces, true, 60, false, "", Set.of(), labels, "", null, 0, false); - Fabric8KubernetesCatalogWatch watch = new Fabric8KubernetesCatalogWatch(mockClient(), properties, NAMESPACE_PROVIDER); + Fabric8KubernetesCatalogWatch watch = new Fabric8KubernetesCatalogWatch(mockClient(), properties, + NAMESPACE_PROVIDER); if (endpointSlices) { watch = Mockito.spy(watch); diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogServicesWatchConfigurationTest.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogServicesWatchConfigurationTest.java index 9b9fef8f36..755ea25a43 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogServicesWatchConfigurationTest.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogServicesWatchConfigurationTest.java @@ -82,9 +82,10 @@ private void setup(String... env) { envList.add("spring.cloud.config.enabled=false"); context = new SpringApplicationBuilder(PropertyPlaceholderAutoConfiguration.class, KubernetesClientTestConfiguration.class, Fabric8KubernetesCatalogWatchAutoConfiguration.class, - Fabric8KubernetesDiscoveryClientAutoConfiguration.class, KubernetesDiscoveryPropertiesAutoConfiguration.class, - Fabric8DiscoveryClientPredicateAutoConfiguration.class) - .web(WebApplicationType.NONE).properties(envList.toArray(new String[0])).run(); + Fabric8KubernetesDiscoveryClientAutoConfiguration.class, + KubernetesDiscoveryPropertiesAutoConfiguration.class, + Fabric8DiscoveryClientPredicateAutoConfiguration.class).web(WebApplicationType.NONE) + .properties(envList.toArray(new String[0])).run(); } @Configuration(proxyBeanMethods = false) diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchAutoConfigurationApplicationContextTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchAutoConfigurationApplicationContextTests.java index c46a7debe6..ed2eefcb69 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchAutoConfigurationApplicationContextTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchAutoConfigurationApplicationContextTests.java @@ -50,7 +50,8 @@ void discoveryEnabled() { void discoveryDisabled() { setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", "spring.cloud.discovery.enabled=false"); - applicationContextRunner.run(context -> assertThat(context).doesNotHaveBean(Fabric8KubernetesCatalogWatch.class)); + applicationContextRunner + .run(context -> assertThat(context).doesNotHaveBean(Fabric8KubernetesCatalogWatch.class)); } @Test @@ -99,9 +100,10 @@ void disableKubernetesDiscovery() { } private void setup(String... properties) { - applicationContextRunner = new ApplicationContextRunner().withConfiguration( - AutoConfigurations.of(Fabric8KubernetesCatalogWatchAutoConfiguration.class, Fabric8AutoConfiguration.class, - KubernetesCommonsAutoConfiguration.class, KubernetesDiscoveryPropertiesAutoConfiguration.class, + applicationContextRunner = new ApplicationContextRunner() + .withConfiguration(AutoConfigurations.of(Fabric8KubernetesCatalogWatchAutoConfiguration.class, + Fabric8AutoConfiguration.class, KubernetesCommonsAutoConfiguration.class, + KubernetesDiscoveryPropertiesAutoConfiguration.class, Fabric8DiscoveryClientPredicateAutoConfiguration.class)) .withPropertyValues(properties); } diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchEndpointSlicesSupportTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchEndpointSlicesSupportTests.java index 1f372258c9..f13f984ce5 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchEndpointSlicesSupportTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchEndpointSlicesSupportTests.java @@ -68,7 +68,8 @@ void testEndpointSlicesEnabledButNotSupportedViaApiGroups() { APIGroupList groupList = new APIGroupListBuilder().build(); mockServer.expect().withPath("/apis").andReturn(200, groupList).always(); - Fabric8KubernetesCatalogWatch watch = new Fabric8KubernetesCatalogWatch(mockClient, properties, NAMESPACE_PROVIDER); + Fabric8KubernetesCatalogWatch watch = new Fabric8KubernetesCatalogWatch(mockClient, properties, + NAMESPACE_PROVIDER); IllegalArgumentException ex = Assertions.assertThrows(IllegalArgumentException.class, watch::postConstruct); Assertions.assertEquals("EndpointSlices are not supported on the cluster", ex.getMessage()); } @@ -94,7 +95,8 @@ void testEndpointSlicesEnabledButNotSupportedViaApiVersions() { APIResourceList apiResourceList = new APIResourceListBuilder().build(); mockServer.expect().withPath("/apis/discovery.k8s.io/v1").andReturn(200, apiResourceList).always(); - Fabric8KubernetesCatalogWatch watch = new Fabric8KubernetesCatalogWatch(mockClient, properties, NAMESPACE_PROVIDER); + Fabric8KubernetesCatalogWatch watch = new Fabric8KubernetesCatalogWatch(mockClient, properties, + NAMESPACE_PROVIDER); IllegalArgumentException ex = Assertions.assertThrows(IllegalArgumentException.class, watch::postConstruct); Assertions.assertEquals("EndpointSlices are not supported on the cluster", ex.getMessage()); } @@ -107,7 +109,8 @@ void testEndpointSlicesEnabledButNotSupportedViaApiVersions() { void testEndpointsSupport() { KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, false, "", Set.of(), Map.of(), "", null, 0, false); - Fabric8KubernetesCatalogWatch watch = new Fabric8KubernetesCatalogWatch(mockClient, properties, NAMESPACE_PROVIDER); + Fabric8KubernetesCatalogWatch watch = new Fabric8KubernetesCatalogWatch(mockClient, properties, + NAMESPACE_PROVIDER); Assertions.assertEquals(Fabric8EndpointsCatalogWatch.class, watch.stateGenerator().getClass()); } @@ -120,7 +123,8 @@ void testEndpointsSupport() { void testEndpointSlicesSupport() { KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, false, "", Set.of(), Map.of(), "", null, 0, true); - Fabric8KubernetesCatalogWatch watch = new Fabric8KubernetesCatalogWatch(mockClient, properties, NAMESPACE_PROVIDER); + Fabric8KubernetesCatalogWatch watch = new Fabric8KubernetesCatalogWatch(mockClient, properties, + NAMESPACE_PROVIDER); GroupVersionForDiscovery forDiscovery = new GroupVersionForDiscoveryBuilder() .withGroupVersion("discovery.k8s.io/v1").build(); diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchEndpointSlicesTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchEndpointSlicesTests.java index cd371e06ea..cd9a8e2423 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchEndpointSlicesTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchEndpointSlicesTests.java @@ -42,8 +42,8 @@ class Fabric8KubernetesCatalogWatchEndpointSlicesTests extends Fabric8EndpointsA @Override void testInSpecificNamespaceWithServiceLabels() { - Fabric8KubernetesCatalogWatch watch = createWatcherInSpecificNamespaceWithLabels("namespaceA", Map.of("color", "blue"), - ENDPOINT_SLICES); + Fabric8KubernetesCatalogWatch watch = createWatcherInSpecificNamespaceWithLabels("namespaceA", + Map.of("color", "blue"), ENDPOINT_SLICES); endpointSlice("namespaceA", Map.of(), "podA"); endpointSlice("namespaceA", Map.of("color", "blue"), "podB"); @@ -94,7 +94,8 @@ void testInAllNamespacesWithServiceLabels() { @Override void testInAllNamespacesWithoutServiceLabels() { - Fabric8KubernetesCatalogWatch watch = createWatcherInAllNamespacesWithLabels(Map.of(), Set.of(), ENDPOINT_SLICES); + Fabric8KubernetesCatalogWatch watch = createWatcherInAllNamespacesWithLabels(Map.of(), Set.of(), + ENDPOINT_SLICES); endpointSlice("namespaceA", Map.of(), "podA"); endpointSlice("namespaceA", Map.of("color", "blue"), "podB"); @@ -112,8 +113,8 @@ void testInAllNamespacesWithoutServiceLabels() { @Override void testAllNamespacesTrueOtherBranchesNotCalled() { - Fabric8KubernetesCatalogWatch watch = createWatcherInAllNamespacesWithLabels(Map.of("color", "blue"), Set.of("B"), - ENDPOINT_SLICES); + Fabric8KubernetesCatalogWatch watch = createWatcherInAllNamespacesWithLabels(Map.of("color", "blue"), + Set.of("B"), ENDPOINT_SLICES); endpointSlice("namespaceA", Map.of(), "podA"); endpointSlice("namespaceA", Map.of("color", "blue"), "podB"); @@ -145,8 +146,8 @@ void testAllNamespacesFalseNamespacesPresent() { @Override void testAllNamespacesFalseNamespacesNotPresent() { - Fabric8KubernetesCatalogWatch watch = createWatcherInSpecificNamespaceWithLabels("namespaceA", Map.of("color", "blue"), - ENDPOINT_SLICES); + Fabric8KubernetesCatalogWatch watch = createWatcherInSpecificNamespaceWithLabels("namespaceA", + Map.of("color", "blue"), ENDPOINT_SLICES); endpointSlice("namespaceA", Map.of(), "podA"); endpointSlice("namespaceA", Map.of("color", "blue"), "podB"); @@ -161,8 +162,8 @@ void testAllNamespacesFalseNamespacesNotPresent() { @Override void testTwoNamespacesOutOfThree() { - Fabric8KubernetesCatalogWatch watch = createWatcherInSpecificNamespacesWithLabels(Set.of("namespaceA", "namespaceB"), - Map.of("color", "blue"), ENDPOINT_SLICES); + Fabric8KubernetesCatalogWatch watch = createWatcherInSpecificNamespacesWithLabels( + Set.of("namespaceA", "namespaceB"), Map.of("color", "blue"), ENDPOINT_SLICES); endpointSlice("namespaceA", Map.of(), "podA"); endpointSlice("namespaceA", Map.of("color", "blue"), "podB"); diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchEndpointsTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchEndpointsTests.java index d40e2804b5..145f9cd27e 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchEndpointsTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchEndpointsTests.java @@ -42,8 +42,8 @@ class Fabric8KubernetesCatalogWatchEndpointsTests extends Fabric8EndpointsAndEnd @Override void testInSpecificNamespaceWithServiceLabels() { - Fabric8KubernetesCatalogWatch watch = createWatcherInSpecificNamespaceWithLabels("namespaceA", Map.of("color", "blue"), - ENDPOINT_SLICES); + Fabric8KubernetesCatalogWatch watch = createWatcherInSpecificNamespaceWithLabels("namespaceA", + Map.of("color", "blue"), ENDPOINT_SLICES); endpoints("namespaceA", Map.of(), "podA"); endpoints("namespaceA", Map.of("color", "blue"), "podB"); @@ -94,7 +94,8 @@ void testInAllNamespacesWithServiceLabels() { @Override void testInAllNamespacesWithoutServiceLabels() { - Fabric8KubernetesCatalogWatch watch = createWatcherInAllNamespacesWithLabels(Map.of(), Set.of(), ENDPOINT_SLICES); + Fabric8KubernetesCatalogWatch watch = createWatcherInAllNamespacesWithLabels(Map.of(), Set.of(), + ENDPOINT_SLICES); endpoints("namespaceA", Map.of(), "podA"); endpoints("namespaceA", Map.of("color", "blue"), "podB"); @@ -112,8 +113,8 @@ void testInAllNamespacesWithoutServiceLabels() { @Override void testAllNamespacesTrueOtherBranchesNotCalled() { - Fabric8KubernetesCatalogWatch watch = createWatcherInAllNamespacesWithLabels(Map.of("color", "blue"), Set.of("B"), - ENDPOINT_SLICES); + Fabric8KubernetesCatalogWatch watch = createWatcherInAllNamespacesWithLabels(Map.of("color", "blue"), + Set.of("B"), ENDPOINT_SLICES); endpoints("namespaceA", Map.of(), "podA"); endpoints("namespaceA", Map.of("color", "blue"), "podB"); @@ -145,8 +146,8 @@ void testAllNamespacesFalseNamespacesPresent() { @Override void testAllNamespacesFalseNamespacesNotPresent() { - Fabric8KubernetesCatalogWatch watch = createWatcherInSpecificNamespaceWithLabels("namespaceA", Map.of("color", "blue"), - ENDPOINT_SLICES); + Fabric8KubernetesCatalogWatch watch = createWatcherInSpecificNamespaceWithLabels("namespaceA", + Map.of("color", "blue"), ENDPOINT_SLICES); endpoints("namespaceA", Map.of(), "podA"); endpoints("namespaceA", Map.of("color", "blue"), "podB"); @@ -161,8 +162,8 @@ void testAllNamespacesFalseNamespacesNotPresent() { @Override void testTwoNamespacesOutOfThree() { - Fabric8KubernetesCatalogWatch watch = createWatcherInSpecificNamespacesWithLabels(Set.of("namespaceA", "namespaceB"), - Map.of("color", "blue"), ENDPOINT_SLICES); + Fabric8KubernetesCatalogWatch watch = createWatcherInSpecificNamespacesWithLabels( + Set.of("namespaceA", "namespaceB"), Map.of("color", "blue"), ENDPOINT_SLICES); endpoints("namespaceA", Map.of(), "podA"); endpoints("namespaceA", Map.of("color", "blue"), "podB"); diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAutoConfigurationApplicationContextTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAutoConfigurationApplicationContextTests.java index b3b59ee504..6afb639dd9 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAutoConfigurationApplicationContextTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAutoConfigurationApplicationContextTests.java @@ -151,9 +151,10 @@ void reactiveDisabled() { } private void setup(String... properties) { - applicationContextRunner = new ApplicationContextRunner().withConfiguration( - AutoConfigurations.of(Fabric8KubernetesDiscoveryClientAutoConfiguration.class, Fabric8AutoConfiguration.class, - KubernetesCommonsAutoConfiguration.class, KubernetesDiscoveryPropertiesAutoConfiguration.class, + applicationContextRunner = new ApplicationContextRunner() + .withConfiguration(AutoConfigurations.of(Fabric8KubernetesDiscoveryClientAutoConfiguration.class, + Fabric8AutoConfiguration.class, KubernetesCommonsAutoConfiguration.class, + KubernetesDiscoveryPropertiesAutoConfiguration.class, Fabric8DiscoveryClientPredicateAutoConfiguration.class)) .withPropertyValues(properties); } diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAutoConfigurationPropertiesTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAutoConfigurationPropertiesTests.java index 620e465f67..2fe7368933 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAutoConfigurationPropertiesTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAutoConfigurationPropertiesTests.java @@ -83,8 +83,8 @@ private void setup(String... env) { envList.add("spring.cloud.config.enabled=false"); context = new SpringApplicationBuilder(PropertyPlaceholderAutoConfiguration.class, KubernetesClientTestConfiguration.class, Fabric8KubernetesDiscoveryClientAutoConfiguration.class, - KubernetesDiscoveryPropertiesAutoConfiguration.class, Fabric8DiscoveryClientPredicateAutoConfiguration.class) - .web(WebApplicationType.NONE) + KubernetesDiscoveryPropertiesAutoConfiguration.class, + Fabric8DiscoveryClientPredicateAutoConfiguration.class).web(WebApplicationType.NONE) .properties(envList.toArray(new String[0])).run(); } diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAutoConfigurationTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAutoConfigurationTests.java index b612c4a0fd..980d2b78b3 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAutoConfigurationTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAutoConfigurationTests.java @@ -39,8 +39,9 @@ void kubernetesDiscoveryClientCreated() { assertThat(this.discoveryClient).isInstanceOf(CompositeDiscoveryClient.class); CompositeDiscoveryClient composite = (CompositeDiscoveryClient) this.discoveryClient; - assertThat(composite.getDiscoveryClients().stream().anyMatch(dc -> dc instanceof Fabric8KubernetesDiscoveryClient)) - .isTrue(); + assertThat( + composite.getDiscoveryClients().stream().anyMatch(dc -> dc instanceof Fabric8KubernetesDiscoveryClient)) + .isTrue(); } @SpringBootApplication diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientConfigClientBootstrapConfigurationTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientConfigClientBootstrapConfigurationTests.java index ba53a1f774..aa294e6209 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientConfigClientBootstrapConfigurationTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientConfigClientBootstrapConfigurationTests.java @@ -88,7 +88,7 @@ private void setup(String... env) { protected static class EnvironmentKnobbler { @Bean - Fabric8KubernetesDiscoveryClient kubernetesDiscoveryClient() { + Fabric8KubernetesDiscoveryClient kubernetesDiscoveryClient() { Fabric8KubernetesDiscoveryClient client = mock(Fabric8KubernetesDiscoveryClient.class); ServiceInstance instance = new DefaultServiceInstance("configserver1", "configserver", "fake", 8888, false); given(client.getInstances("configserver")).willReturn(Collections.singletonList(instance)); diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientFilterMetadataTest.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientFilterMetadataTest.java index 47281b91b6..65100d663c 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientFilterMetadataTest.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientFilterMetadataTest.java @@ -60,10 +60,11 @@ @SuppressWarnings("unchecked") class Fabric8KubernetesDiscoveryClientFilterMetadataTest { - private static final ServicePortSecureResolver SERVICE_PORT_SECURE_RESOLVER = - new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT); + private static final ServicePortSecureResolver SERVICE_PORT_SECURE_RESOLVER = new ServicePortSecureResolver( + KubernetesDiscoveryProperties.DEFAULT); - private static final KubernetesNamespaceProvider NAMESPACE_PROVIDER = new KubernetesNamespaceProvider(mockEnvironment()); + private static final KubernetesNamespaceProvider NAMESPACE_PROVIDER = new KubernetesNamespaceProvider( + mockEnvironment()); private static final KubernetesClient CLIENT = Mockito.mock(KubernetesClient.class); @@ -90,8 +91,8 @@ void testAllExtraMetadataDisabled() { false, null, Set.of(), Map.of(), null, metadata, 0, true); Fabric8KubernetesDiscoveryClient client = new Fabric8KubernetesDiscoveryClient(CLIENT, properties, - SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, - new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties)); + SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, + new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties)); setupServiceWithLabelsAndAnnotationsAndPorts(serviceId, "ns", Map.of("l1", "lab"), Map.of("l1", "lab"), Map.of(80, "http", 5555, "")); @@ -110,8 +111,8 @@ void testLabelsEnabled() { false, null, Set.of(), Map.of(), null, metadata, 0, true); Fabric8KubernetesDiscoveryClient client = new Fabric8KubernetesDiscoveryClient(CLIENT, properties, - SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, - new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties)); + SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, + new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties)); setupServiceWithLabelsAndAnnotationsAndPorts(serviceId, "ns", Map.of("l1", "v1", "l2", "v2"), Map.of("l1", "lab"), Map.of(80, "http", 5555, "")); @@ -131,8 +132,8 @@ void testLabelsEnabledWithPrefix() { false, null, Set.of(), Map.of(), null, metadata, 0, true); Fabric8KubernetesDiscoveryClient client = new Fabric8KubernetesDiscoveryClient(CLIENT, properties, - SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, - new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties)); + SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, + new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties)); setupServiceWithLabelsAndAnnotationsAndPorts(serviceId, "ns", Map.of("l1", "v1", "l2", "v2"), Map.of("l1", "lab"), Map.of(80, "http", 5555, "")); @@ -152,8 +153,8 @@ void testAnnotationsEnabled() { false, null, Set.of(), Map.of(), null, metadata, 0, true); Fabric8KubernetesDiscoveryClient client = new Fabric8KubernetesDiscoveryClient(CLIENT, properties, - SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, - new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties)); + SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, + new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties)); setupServiceWithLabelsAndAnnotationsAndPorts(serviceId, "ns", Map.of("l1", "v1"), Map.of("a1", "v1", "a2", "v2"), Map.of(80, "http", 5555, "")); @@ -173,8 +174,8 @@ void testAnnotationsEnabledWithPrefix() { false, null, Set.of(), Map.of(), null, metadata, 0, true); Fabric8KubernetesDiscoveryClient client = new Fabric8KubernetesDiscoveryClient(CLIENT, properties, - SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, - new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties)); + SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, + new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties)); setupServiceWithLabelsAndAnnotationsAndPorts(serviceId, "ns", Map.of("l1", "v1"), Map.of("a1", "v1", "a2", "v2"), Map.of(80, "http", 5555, "")); @@ -194,8 +195,8 @@ void testPortsEnabled() { false, null, Set.of(), Map.of(), null, metadata, 0, true); Fabric8KubernetesDiscoveryClient client = new Fabric8KubernetesDiscoveryClient(CLIENT, properties, - SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, - new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties)); + SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, + new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties)); setupServiceWithLabelsAndAnnotationsAndPorts(serviceId, "test", Map.of("l1", "v1"), Map.of("a1", "v1", "a2", "v2"), Map.of(80, "http", 5555, "")); @@ -214,8 +215,8 @@ void testPortsEnabledWithPrefix() { false, null, Set.of(), Map.of(), null, metadata, 0, true); Fabric8KubernetesDiscoveryClient client = new Fabric8KubernetesDiscoveryClient(CLIENT, properties, - SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, - new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties)); + SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, + new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties)); setupServiceWithLabelsAndAnnotationsAndPorts(serviceId, "ns", Map.of("l1", "v1"), Map.of("a1", "v1", "a2", "v2"), Map.of(80, "http", 5555, "")); @@ -234,8 +235,8 @@ void testLabelsAndAnnotationsAndPortsEnabledWithPrefix() { false, null, Set.of(), Map.of(), null, metadata, 0, true); Fabric8KubernetesDiscoveryClient client = new Fabric8KubernetesDiscoveryClient(CLIENT, properties, - SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, - new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties)); + SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, + new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties)); setupServiceWithLabelsAndAnnotationsAndPorts(serviceId, "ns", Map.of("l1", "la1"), Map.of("a1", "an1", "a2", "an2"), Map.of(80, "http", 5555, "")); diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientFilterTest.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientFilterTest.java index 1a0e3b2cc5..fc95a082e6 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientFilterTest.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientFilterTest.java @@ -44,10 +44,11 @@ @SuppressWarnings("unchecked") class Fabric8KubernetesDiscoveryClientFilterTest { - private static final ServicePortSecureResolver SERVICE_PORT_SECURE_RESOLVER = - new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT); + private static final ServicePortSecureResolver SERVICE_PORT_SECURE_RESOLVER = new ServicePortSecureResolver( + KubernetesDiscoveryProperties.DEFAULT); - private static final KubernetesNamespaceProvider NAMESPACE_PROVIDER = new KubernetesNamespaceProvider(mockEnvironment()); + private static final KubernetesNamespaceProvider NAMESPACE_PROVIDER = new KubernetesNamespaceProvider( + mockEnvironment()); private final KubernetesClient kubernetesClient = Mockito.mock(KubernetesClient.class); @@ -118,8 +119,8 @@ void testFilteredServicesByPrefix() { false, "metadata.name.startsWith('service')", Set.of(), Map.of(), null, KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, true); Fabric8KubernetesDiscoveryClient client = new Fabric8KubernetesDiscoveryClient(kubernetesClient, properties, - SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, - new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties)); + SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, + new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties)); List filteredServices = client.getServices(); assertThat(filteredServices).isEqualTo(springBootServiceNames); @@ -143,8 +144,8 @@ void testNoExpression() { KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, false, "", Set.of(), Map.of(), null, KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, true); Fabric8KubernetesDiscoveryClient client = new Fabric8KubernetesDiscoveryClient(kubernetesClient, properties, - SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, - new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties)); + SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, + new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties)); List filteredServices = client.getServices(); diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientTest.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientTest.java index fa20cdd652..ab91c1fce2 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientTest.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientTest.java @@ -48,10 +48,11 @@ @EnableKubernetesMockClient(crud = true, https = false) class Fabric8KubernetesDiscoveryClientTest { - private static final ServicePortSecureResolver SERVICE_PORT_SECURE_RESOLVER = - new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT); + private static final ServicePortSecureResolver SERVICE_PORT_SECURE_RESOLVER = new ServicePortSecureResolver( + KubernetesDiscoveryProperties.DEFAULT); - private static final KubernetesNamespaceProvider NAMESPACE_PROVIDER = new KubernetesNamespaceProvider(mockEnvironment()); + private static final KubernetesNamespaceProvider NAMESPACE_PROVIDER = new KubernetesNamespaceProvider( + mockEnvironment()); private KubernetesClient mockClient; @@ -114,8 +115,8 @@ void getInstancesShouldBeAbleToHandleEndpointsSingleAddressAndMultiplePorts() { KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, false, null, Set.of(), labels, "http_tcp", Metadata.DEFAULT, 0, true); - DiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, - properties, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true); + DiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, properties, + SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true); List instances = discoveryClient.getInstances("endpoint"); @@ -135,10 +136,11 @@ void getEndPointsListTest() { mockClient.endpoints().inNamespace("test").resource(endPoint).create(); - ServicePortSecureResolver servicePortSecureResolver = new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT); + ServicePortSecureResolver servicePortSecureResolver = new ServicePortSecureResolver( + KubernetesDiscoveryProperties.DEFAULT); KubernetesNamespaceProvider namespaceProvider = new KubernetesNamespaceProvider(mockEnvironment()); Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, - KubernetesDiscoveryProperties.DEFAULT, servicePortSecureResolver, namespaceProvider, x -> true); + KubernetesDiscoveryProperties.DEFAULT, servicePortSecureResolver, namespaceProvider, x -> true); List result_endpoints = discoveryClient.getEndPointsList("endpoint"); @@ -163,8 +165,8 @@ void getEndPointsListTestAllNamespaces() { KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, false, null, Set.of(), Map.of(), null, KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, false); - Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, - properties, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true); + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, properties, + SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true); List result_endpoints = discoveryClient.getEndPointsList("endpoint"); @@ -193,8 +195,8 @@ void getEndPointsListShouldHandleNamespaces() { Set.of(namespace1, namespace3), true, 60, false, null, Set.of(), Map.of(), null, KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, false); - Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, - properties, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true); + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, properties, + SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true); List result_endpoints = discoveryClient.getEndPointsList("endpoint"); @@ -224,8 +226,8 @@ void getInstancesShouldBeAbleToHandleEndpointsMultipleAddresses() { KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, false, null, Set.of(443, 8443), labels, null, metadata, 0, true); - Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, - properties, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true); + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, properties, + new ServicePortSecureResolver(properties), NAMESPACE_PROVIDER, x -> true); List instances = discoveryClient.getInstances("endpoint"); @@ -251,7 +253,7 @@ void getServicesShouldReturnAllServicesWhenNoLabelsAreAppliedToTheClient() { mockClient.services().inNamespace("test").resource(service3).create(); Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, - KubernetesDiscoveryProperties.DEFAULT, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true); + KubernetesDiscoveryProperties.DEFAULT, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true); List services = discoveryClient.getServices(); @@ -273,7 +275,7 @@ void getServicesShouldReturnOnlyMatchingServicesWhenLabelsAreAppliedToTheClient( mockClient.services().inNamespace("test").resource(service2).create(); Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, - KubernetesDiscoveryProperties.DEFAULT, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true); + KubernetesDiscoveryProperties.DEFAULT, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true); List services = discoveryClient.getServices(); @@ -304,8 +306,8 @@ void getServicesShouldReturnServicesInNamespaces() { Set.of(nameSpace1, nameSpace2), true, 60, false, null, Set.of(), Map.of(), null, KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, false); - Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, - properties, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true); + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, properties, + SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true); List services = discoveryClient.getServices(); @@ -337,8 +339,8 @@ void getInstancesShouldBeAbleToHandleEndpointsFromMultipleNamespaces() { KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, false, null, Set.of(), Map.of(), null, Metadata.DEFAULT, 0, true); - Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, - properties, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true); + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, properties, + SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true); List instances = discoveryClient.getInstances("endpoint"); @@ -361,7 +363,7 @@ void instanceWithoutPortsShouldBeSkipped() { mockClient.endpoints().inNamespace("test").resource(endPoint).create(); Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, - KubernetesDiscoveryProperties.DEFAULT, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true); + KubernetesDiscoveryProperties.DEFAULT, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true); List instances = discoveryClient.getInstances("endpoint1"); @@ -387,8 +389,8 @@ void getInstancesShouldBeAbleToHandleEndpointsSingleAddressAndMultiplePortsUsing KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, false, null, Set.of(443, 8443), Map.of(), null, Metadata.DEFAULT, 0, true); - Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, - properties, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true); + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, properties, + new ServicePortSecureResolver(properties), NAMESPACE_PROVIDER, x -> true); List instances = discoveryClient.getInstances("endpoint2"); @@ -417,8 +419,8 @@ void instanceWithMultiplePortsAndMisconfiguredPrimaryPortNameInLabelWithoutFallb KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, false, null, Set.of(443, 8443), Map.of(), null, Metadata.DEFAULT, 0, true); - Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, - properties, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true); + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, properties, + new ServicePortSecureResolver(properties), NAMESPACE_PROVIDER, x -> true); List instances = discoveryClient.getInstances("endpoint3"); @@ -447,8 +449,8 @@ void instanceWithMultiplePortsAndMisconfiguredGenericPrimaryPortNameWithoutFallb KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, false, null, Set.of(443, 8443), Map.of(), "oops", Metadata.DEFAULT, 0, true); - Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, - properties, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true); + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, properties, + new ServicePortSecureResolver(properties), NAMESPACE_PROVIDER, x -> true); List instances = discoveryClient.getInstances("endpoint4"); @@ -476,8 +478,8 @@ void instanceWithMultiplePortsAndWithoutPrimaryPortNameSpecifiedShouldFallBackTo KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, false, null, Set.of(443, 8443), Map.of(), null, Metadata.DEFAULT, 0, true); - Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, - properties, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true); + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, properties, + new ServicePortSecureResolver(properties), NAMESPACE_PROVIDER, x -> true); List instances = discoveryClient.getInstances("endpoint5"); @@ -503,7 +505,7 @@ void instanceWithMultiplePortsAndWithoutPrimaryPortNameSpecifiedOrHttpsPortShoul mockClient.services().inNamespace("test").resource(service).create(); Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, - KubernetesDiscoveryProperties.DEFAULT, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true); + KubernetesDiscoveryProperties.DEFAULT, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true); List instances = discoveryClient.getInstances("endpoint5"); @@ -531,8 +533,8 @@ void instanceWithMultiplePortsAndWithoutPrimaryPortNameSpecifiedShouldLogWarning KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, true, null, Set.of(443, 8443), Map.of(), null, Metadata.DEFAULT, 0, true); - Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, - properties, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true); + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, properties, + new ServicePortSecureResolver(properties), NAMESPACE_PROVIDER, x -> true); List instances = discoveryClient.getInstances("endpoint5"); diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientTests.java index 332454f413..9a1afe2833 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientTests.java @@ -77,7 +77,8 @@ void testAllNamespacesEmpty(CapturedOutput output) { KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); - Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties, null, null, null); + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties, + null, null, null); List result = discoveryClient.getEndPointsList("serviceId"); Assertions.assertEquals(result.size(), 0); Assertions.assertTrue(output.getOut().contains("discovering endpoints in all namespaces")); @@ -102,7 +103,8 @@ void testAllNamespacesSingleEndpointsMatchExactLabels(CapturedOutput output) { KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); - Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties, null, null, null); + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties, + null, null, null); List result = discoveryClient.getEndPointsList("blue-service"); Assertions.assertEquals(result.size(), 1); Assertions.assertTrue(output.getOut().contains("discovering endpoints in all namespaces")); @@ -127,7 +129,8 @@ void testAllNamespacesSingleEndpointsMatchPartialLabels(CapturedOutput output) { KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); - Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties, null, null, null); + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties, + null, null, null); List result = discoveryClient.getEndPointsList("blue-service"); Assertions.assertEquals(result.size(), 1); Assertions.assertTrue(output.getOut().contains("discovering endpoints in all namespaces")); @@ -152,7 +155,8 @@ void testAllNamespacesSingleEndpointsNameMatchesLabelsDont(CapturedOutput output KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); - Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties, null, null, null); + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties, + null, null, null); List result = discoveryClient.getEndPointsList("blue-service"); Assertions.assertEquals(result.size(), 0); Assertions.assertTrue(output.getOut().contains("discovering endpoints in all namespaces")); @@ -178,7 +182,8 @@ void testAllNamespacesTwoEndpointsOneMatches(CapturedOutput output) { KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); - Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties, null, null, null); + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties, + null, null, null); List result = discoveryClient.getEndPointsList("service-one"); Assertions.assertEquals(result.size(), 1); Assertions.assertTrue(output.getOut().contains("discovering endpoints in all namespaces")); @@ -204,7 +209,8 @@ void testAllNamespacesTwoEndpointsInDifferentNamespaces(CapturedOutput output) { KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); - Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties, null, null, null); + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties, + null, null, null); List result = discoveryClient.getEndPointsList("service-one"); Assertions.assertEquals(result.size(), 2); Assertions.assertEquals( @@ -228,7 +234,8 @@ void testClientNamespaceEmpty(CapturedOutput output) { KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); - Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties, null, null, null); + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties, + null, null, null); List result = discoveryClient.getEndPointsList("serviceId"); Assertions.assertEquals(result.size(), 0); Assertions.assertTrue(output.getOut().contains("discovering endpoints in namespace : test")); @@ -253,7 +260,8 @@ void testClientNamespaceSingleEndpointsMatchExactLabels(CapturedOutput output) { KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); - Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties, null, null, null); + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties, + null, null, null); List result = discoveryClient.getEndPointsList("blue-service"); Assertions.assertEquals(result.size(), 1); Assertions.assertTrue(output.getOut().contains("discovering endpoints in namespace : test")); @@ -278,7 +286,8 @@ void testClientNamespaceSingleEndpointsMatchPartialLabels(CapturedOutput output) KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); - Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties, null, null, null); + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties, + null, null, null); List result = discoveryClient.getEndPointsList("blue-service"); Assertions.assertEquals(result.size(), 1); Assertions.assertTrue(output.getOut().contains("discovering endpoints in namespace : test")); @@ -303,7 +312,8 @@ void testClientNamespaceSingleEndpointsNameMatchesLabelsDont(CapturedOutput outp KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); - Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties, null, null, null); + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties, + null, null, null); List result = discoveryClient.getEndPointsList("blue-service"); Assertions.assertEquals(result.size(), 0); Assertions.assertTrue(output.getOut().contains("discovering endpoints in namespace : test")); @@ -329,7 +339,8 @@ void testClientNamespaceTwoEndpointsOneMatches(CapturedOutput output) { KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); - Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties, null, null, null); + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties, + null, null, null); List result = discoveryClient.getEndPointsList("service-one"); Assertions.assertEquals(result.size(), 1); Assertions.assertTrue(output.getOut().contains("discovering endpoints in namespace : test")); @@ -355,7 +366,8 @@ void testClientNamespaceTwoEndpointsInDifferentNamespaces(CapturedOutput output) KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); - Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties, null, null, null); + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties, + null, null, null); List result = discoveryClient.getEndPointsList("service-one"); Assertions.assertEquals(result.size(), 1); Assertions.assertEquals( @@ -379,7 +391,8 @@ void testSelectiveNamespacesEmpty(CapturedOutput output) { KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); - Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties, null, null, null); + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties, + null, null, null); List result = discoveryClient.getEndPointsList("serviceId"); Assertions.assertEquals(result.size(), 0); Assertions.assertTrue(output.getOut().contains("discovering endpoints in namespaces : [test]")); @@ -404,7 +417,8 @@ void testSelectiveNamespacesSingleEndpointsMatchExactLabels(CapturedOutput outpu KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); - Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties, null, null, null); + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties, + null, null, null); List result = discoveryClient.getEndPointsList("blue-service"); Assertions.assertEquals(result.size(), 1); Assertions.assertTrue(output.getOut().contains("discovering endpoints in namespaces : [test]")); @@ -431,7 +445,8 @@ void testSelectiveNamespacesMultipleNamespacesSingleMatch(CapturedOutput output) KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); - Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties, null, null, null); + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties, + null, null, null); List result = discoveryClient.getEndPointsList("blue-service"); Assertions.assertEquals(result.size(), 1); Assertions.assertEquals(result.get(0).getMetadata().getLabels(), Map.of("color", "blue", "shape", "round")); @@ -461,7 +476,8 @@ void testSelectiveNamespacesMultipleNamespacesAllMatch(CapturedOutput output) { KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); - Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties, null, null, null); + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties, + null, null, null); List result = discoveryClient.getEndPointsList("blue-service"); Assertions.assertEquals(result.size(), 2); Assertions.assertTrue(output.getOut().contains("discovering endpoints in namespaces : " + namespacesAsString)); diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtilsTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtilsTests.java index 53f6d18e14..2512fe7316 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtilsTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtilsTests.java @@ -169,7 +169,8 @@ void testEndpointsPortSinglePort(CapturedOutput output) { KubernetesDiscoveryProperties properties = KubernetesDiscoveryProperties.DEFAULT; Service service = new ServiceBuilder().build(); - Integer port = Fabric8KubernetesDiscoveryClientUtils.endpointsPort(endpointSubset, serviceId, properties, service); + Integer port = Fabric8KubernetesDiscoveryClientUtils.endpointsPort(endpointSubset, serviceId, properties, + service); Assertions.assertEquals(port, 8080); Assertions.assertTrue(output.getOut().contains("endpoint ports has a single entry, using port : 8080")); } @@ -189,7 +190,8 @@ void testEndpointsPortNullPrimaryPortName(CapturedOutput output) { KubernetesDiscoveryProperties properties = KubernetesDiscoveryProperties.DEFAULT; Service service = new ServiceBuilder().withMetadata(new ObjectMeta()).build(); - Integer port = Fabric8KubernetesDiscoveryClientUtils.endpointsPort(endpointSubset, serviceId, properties, service); + Integer port = Fabric8KubernetesDiscoveryClientUtils.endpointsPort(endpointSubset, serviceId, properties, + service); Assertions.assertEquals(port, 8080); Assertions.assertTrue(output.getOut().contains( "did not find a primary-port-name in neither properties nor service labels for service with ID : spring-k8s")); @@ -223,7 +225,8 @@ void testEndpointsPortPrimaryPortNameIsPresentButNotFound(CapturedOutput output) Service service = new ServiceBuilder().withMetadata(new ObjectMeta()).build(); - Integer port = Fabric8KubernetesDiscoveryClientUtils.endpointsPort(endpointSubset, serviceId, properties, service); + Integer port = Fabric8KubernetesDiscoveryClientUtils.endpointsPort(endpointSubset, serviceId, properties, + service); Assertions.assertEquals(port, 8080); Assertions.assertTrue( output.getOut().contains("will use primaryPortName : three for service with ID = spring-k8s")); @@ -257,7 +260,8 @@ void testEndpointsPortPrimaryPortNameFound(CapturedOutput output) { Service service = new ServiceBuilder().withMetadata(new ObjectMeta()).build(); - Integer port = Fabric8KubernetesDiscoveryClientUtils.endpointsPort(endpointSubset, serviceId, properties, service); + Integer port = Fabric8KubernetesDiscoveryClientUtils.endpointsPort(endpointSubset, serviceId, properties, + service); Assertions.assertEquals(port, 8081); Assertions.assertTrue( output.getOut().contains("will use primaryPortName : two for service with ID = spring-k8s")); @@ -286,7 +290,8 @@ void testEndpointsPortPrimaryPortHttps(CapturedOutput output) { Service service = new ServiceBuilder().withMetadata(new ObjectMeta()).build(); - Integer port = Fabric8KubernetesDiscoveryClientUtils.endpointsPort(endpointSubset, serviceId, properties, service); + Integer port = Fabric8KubernetesDiscoveryClientUtils.endpointsPort(endpointSubset, serviceId, properties, + service); Assertions.assertEquals(port, 8082); Assertions.assertTrue( output.getOut().contains("will use primaryPortName : three for service with ID = spring-k8s")); @@ -316,7 +321,8 @@ void testEndpointsPortPrimaryPortHttp(CapturedOutput output) { Service service = new ServiceBuilder().withMetadata(new ObjectMeta()).build(); - Integer port = Fabric8KubernetesDiscoveryClientUtils.endpointsPort(endpointSubset, serviceId, properties, service); + Integer port = Fabric8KubernetesDiscoveryClientUtils.endpointsPort(endpointSubset, serviceId, properties, + service); Assertions.assertEquals(port, 8082); Assertions.assertTrue( output.getOut().contains("will use primaryPortName : three for service with ID = spring-k8s")); @@ -348,8 +354,8 @@ void testServiceMetadataEmpty() { true, "", Set.of(), Map.of(), "", metadata, 0, false); Service service = new ServiceBuilder().build(); - Map result = Fabric8KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, - List.of(), namespace); + Map result = Fabric8KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, + properties, List.of(), namespace); Assertions.assertEquals(result.size(), 1); Assertions.assertEquals(result, Map.of("k8s_namespace", "default")); } @@ -378,8 +384,8 @@ void testServiceMetadataAddLabelsNoPrefix(CapturedOutput output) { Service service = new ServiceBuilder() .withMetadata(new ObjectMetaBuilder().withLabels(Map.of("a", "b")).build()).build(); - Map result = Fabric8KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, - List.of(), namespace); + Map result = Fabric8KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, + properties, List.of(), namespace); Assertions.assertEquals(result.size(), 2); Assertions.assertEquals(result, Map.of("a", "b", "k8s_namespace", "default")); String labelsMetadata = filterOnK8sNamespace(result); @@ -411,8 +417,8 @@ void testServiceMetadataAddLabelsWithPrefix(CapturedOutput output) { Service service = new ServiceBuilder() .withMetadata(new ObjectMetaBuilder().withLabels(Map.of("a", "b", "c", "d")).build()).build(); - Map result = Fabric8KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, - List.of(), namespace); + Map result = Fabric8KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, + properties, List.of(), namespace); Assertions.assertEquals(result.size(), 3); Assertions.assertEquals(result, Map.of("prefix-a", "b", "prefix-c", "d", "k8s_namespace", "default")); // so that result is deterministic in assertion @@ -446,8 +452,8 @@ void testServiceMetadataAddAnnotationsNoPrefix(CapturedOutput output) { new ObjectMetaBuilder().withAnnotations(Map.of("aa", "bb")).withLabels(Map.of("a", "b")).build()) .build(); - Map result = Fabric8KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, - List.of(), namespace); + Map result = Fabric8KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, + properties, List.of(), namespace); Assertions.assertEquals(result.size(), 2); Assertions.assertEquals(result, Map.of("aa", "bb", "k8s_namespace", "default")); Assertions @@ -478,8 +484,8 @@ void testServiceMetadataAddAnnotationsWithPrefix(CapturedOutput output) { Service service = new ServiceBuilder().withMetadata(new ObjectMetaBuilder() .withAnnotations(Map.of("aa", "bb", "cc", "dd")).withLabels(Map.of("a", "b")).build()).build(); - Map result = Fabric8KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, - List.of(), namespace); + Map result = Fabric8KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, + properties, List.of(), namespace); Assertions.assertEquals(result.size(), 3); Assertions.assertEquals(result, Map.of("prefix-aa", "bb", "prefix-cc", "dd", "k8s_namespace", "default")); // so that result is deterministic in assertion @@ -513,8 +519,8 @@ void testServiceMetadataAddLabelsAndAnnotationsWithPrefix(CapturedOutput output) .withAnnotations(Map.of("aa", "bb", "cc", "dd")).withLabels(Map.of("a", "b", "c", "d")).build()) .build(); - Map result = Fabric8KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, - List.of(), namespace); + Map result = Fabric8KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, + properties, List.of(), namespace); Assertions.assertEquals(result.size(), 5); Assertions.assertEquals(result, Map.of("annotation-aa", "bb", "annotation-cc", "dd", "label-a", "b", "label-c", "d", "k8s_namespace", "default")); @@ -558,8 +564,8 @@ void testServiceMetadataAddPortsWithoutPrefix(CapturedOutput output) { new EndpointSubsetBuilder() .withPorts(new EndpointPortBuilder().withPort(8080).withName("https").build()).build()); - Map result = Fabric8KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, - endpointSubsets, namespace); + Map result = Fabric8KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, + properties, endpointSubsets, namespace); Assertions.assertEquals(result.size(), 2); Assertions.assertEquals(result, Map.of("https", "8080", "k8s_namespace", "default")); Assertions @@ -595,8 +601,8 @@ void testServiceMetadataAddPortsWithPrefix(CapturedOutput output) { new EndpointSubsetBuilder() .withPorts(new EndpointPortBuilder().withPort(8080).withName("https").build()).build()); - Map result = Fabric8KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, - endpointSubsets, namespace); + Map result = Fabric8KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, + properties, endpointSubsets, namespace); Assertions.assertEquals(result.size(), 3); Assertions.assertEquals(result, Map.of("prefix-https", "8080", "prefix-http", "8081", "k8s_namespace", "default")); @@ -690,8 +696,8 @@ void testServiceInstance() { EndpointAddress address = new EndpointAddressBuilder().withNewTargetRef().withUid("123").endTargetRef() .withIp("127.0.0.1").build(); - ServiceInstance serviceInstance = Fabric8KubernetesDiscoveryClientUtils.serviceInstance(resolver, service, address, - 8080, "my-service", Map.of("a", "b"), "k8s"); + ServiceInstance serviceInstance = Fabric8KubernetesDiscoveryClientUtils.serviceInstance(resolver, service, + address, 8080, "my-service", Map.of("a", "b"), "k8s"); Assertions.assertTrue(serviceInstance instanceof DefaultKubernetesServiceInstance); DefaultKubernetesServiceInstance defaultInstance = (DefaultKubernetesServiceInstance) serviceInstance; Assertions.assertEquals(defaultInstance.getInstanceId(), "123"); diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientAutoConfigurationApplicationContextTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientAutoConfigurationApplicationContextTests.java index 089683a75f..7db6f91244 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientAutoConfigurationApplicationContextTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientAutoConfigurationApplicationContextTests.java @@ -43,22 +43,24 @@ class Fabric8KubernetesReactiveDiscoveryClientAutoConfigurationApplicationContex @Test void discoveryEnabledDefault() { setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false"); - applicationContextRunner.withConfiguration(AutoConfigurations.of(Fabric8DiscoveryClientPredicateAutoConfiguration.class)) - .run(context -> { - assertThat(context).hasSingleBean(Fabric8KubernetesReactiveDiscoveryClient.class); - assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class); - }); + applicationContextRunner + .withConfiguration(AutoConfigurations.of(Fabric8DiscoveryClientPredicateAutoConfiguration.class)) + .run(context -> { + assertThat(context).hasSingleBean(Fabric8KubernetesReactiveDiscoveryClient.class); + assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class); + }); } @Test void discoveryEnabled() { setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", "spring.cloud.discovery.enabled=true"); - applicationContextRunner.withConfiguration(AutoConfigurations.of(Fabric8DiscoveryClientPredicateAutoConfiguration.class)) - .run(context -> { - assertThat(context).hasSingleBean(Fabric8KubernetesReactiveDiscoveryClient.class); - assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class); - }); + applicationContextRunner + .withConfiguration(AutoConfigurations.of(Fabric8DiscoveryClientPredicateAutoConfiguration.class)) + .run(context -> { + assertThat(context).hasSingleBean(Fabric8KubernetesReactiveDiscoveryClient.class); + assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class); + }); } @Test @@ -75,11 +77,12 @@ void discoveryDisabled() { void kubernetesDiscoveryEnabled() { setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", "spring.cloud.kubernetes.discovery.enabled=true"); - applicationContextRunner.withConfiguration(AutoConfigurations.of(Fabric8DiscoveryClientPredicateAutoConfiguration.class)) - .run(context -> { - assertThat(context).hasSingleBean(Fabric8KubernetesReactiveDiscoveryClient.class); - assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class); - }); + applicationContextRunner + .withConfiguration(AutoConfigurations.of(Fabric8DiscoveryClientPredicateAutoConfiguration.class)) + .run(context -> { + assertThat(context).hasSingleBean(Fabric8KubernetesReactiveDiscoveryClient.class); + assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class); + }); } @Test @@ -96,10 +99,12 @@ void kubernetesDiscoveryDisabled() { void kubernetesReactiveDiscoveryEnabled() { setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", "spring.cloud.discovery.reactive.enabled=true"); - applicationContextRunner.withConfiguration(AutoConfigurations.of(Fabric8DiscoveryClientPredicateAutoConfiguration.class)).run(context -> { - assertThat(context).hasSingleBean(Fabric8KubernetesReactiveDiscoveryClient.class); - assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class); - }); + applicationContextRunner + .withConfiguration(AutoConfigurations.of(Fabric8DiscoveryClientPredicateAutoConfiguration.class)) + .run(context -> { + assertThat(context).hasSingleBean(Fabric8KubernetesReactiveDiscoveryClient.class); + assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class); + }); } @Test @@ -119,22 +124,24 @@ void kubernetesReactiveDiscoveryDisabled() { void blockingDisabled() { setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", "spring.cloud.discovery.blocking.enabled=false"); - applicationContextRunner.withConfiguration(AutoConfigurations.of(Fabric8DiscoveryClientPredicateAutoConfiguration.class)) - .run(context -> { - assertThat(context).hasSingleBean(Fabric8KubernetesReactiveDiscoveryClient.class); - assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class); - }); + applicationContextRunner + .withConfiguration(AutoConfigurations.of(Fabric8DiscoveryClientPredicateAutoConfiguration.class)) + .run(context -> { + assertThat(context).hasSingleBean(Fabric8KubernetesReactiveDiscoveryClient.class); + assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class); + }); } @Test void healthDisabled() { setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", "spring.cloud.discovery.client.health-indicator.enabled=false"); - applicationContextRunner.withConfiguration(AutoConfigurations.of(Fabric8DiscoveryClientPredicateAutoConfiguration.class)) - .run(context -> { - assertThat(context).hasSingleBean(Fabric8KubernetesReactiveDiscoveryClient.class); - assertThat(context).doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class); - }); + applicationContextRunner + .withConfiguration(AutoConfigurations.of(Fabric8DiscoveryClientPredicateAutoConfiguration.class)) + .run(context -> { + assertThat(context).hasSingleBean(Fabric8KubernetesReactiveDiscoveryClient.class); + assertThat(context).doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class); + }); } @Test @@ -142,11 +149,12 @@ void healthEnabledClassNotPresent() { setupWithFilteredClassLoader("org.springframework.boot.actuate.health.ReactiveHealthIndicator", "spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", "spring.cloud.discovery.client.health-indicator.enabled=false"); - applicationContextRunner.withConfiguration(AutoConfigurations.of(Fabric8DiscoveryClientPredicateAutoConfiguration.class)) - .run(context -> { - assertThat(context).hasSingleBean(Fabric8KubernetesReactiveDiscoveryClient.class); - assertThat(context).doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class); - }); + applicationContextRunner + .withConfiguration(AutoConfigurations.of(Fabric8DiscoveryClientPredicateAutoConfiguration.class)) + .run(context -> { + assertThat(context).hasSingleBean(Fabric8KubernetesReactiveDiscoveryClient.class); + assertThat(context).doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class); + }); } private void setup(String... properties) { diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientAutoConfigurationTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientAutoConfigurationTests.java index 46e520b1b6..eb2a9cd170 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientAutoConfigurationTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientAutoConfigurationTests.java @@ -46,10 +46,11 @@ class Fabric8KubernetesReactiveDiscoveryClientAutoConfigurationTests { @Test void shouldWorkWithDefaults() { contextRunner.withPropertyValues("spring.main.cloud-platform=KUBERNETES") - .withConfiguration(AutoConfigurations.of(Fabric8DiscoveryClientPredicateAutoConfiguration.class)).run(context -> { - assertThat(context).hasSingleBean(ReactiveDiscoveryClient.class); - assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class); - }); + .withConfiguration(AutoConfigurations.of(Fabric8DiscoveryClientPredicateAutoConfiguration.class)) + .run(context -> { + assertThat(context).hasSingleBean(ReactiveDiscoveryClient.class); + assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class); + }); } @Test diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientTests.java index afd4d8cddf..690f4f885c 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientTests.java @@ -34,15 +34,15 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider; -import org.springframework.core.env.Environment; -import org.springframework.mock.env.MockEnvironment; import reactor.core.publisher.Flux; import reactor.test.StepVerifier; import org.springframework.cloud.client.ServiceInstance; import org.springframework.cloud.client.discovery.ReactiveDiscoveryClient; +import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider; import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; +import org.springframework.core.env.Environment; +import org.springframework.mock.env.MockEnvironment; import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.assertThat; @@ -54,10 +54,11 @@ @EnableKubernetesMockClient(crud = true, https = false) class Fabric8KubernetesReactiveDiscoveryClientTests { - private static final ServicePortSecureResolver SERVICE_PORT_SECURE_RESOLVER = - new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT); + private static final ServicePortSecureResolver SERVICE_PORT_SECURE_RESOLVER = new ServicePortSecureResolver( + KubernetesDiscoveryProperties.DEFAULT); - private static final KubernetesNamespaceProvider NAMESPACE_PROVIDER = new KubernetesNamespaceProvider(mockEnvironment()); + private static final KubernetesNamespaceProvider NAMESPACE_PROVIDER = new KubernetesNamespaceProvider( + mockEnvironment()); private static KubernetesMockServer kubernetesServer; @@ -82,9 +83,8 @@ void afterEach() { @Test void verifyDefaults() { Fabric8KubernetesDiscoveryClient fabric8KubernetesDiscoveryClient = new Fabric8KubernetesDiscoveryClient( - kubernetesClient, KubernetesDiscoveryProperties.DEFAULT, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, - x -> true - ); + kubernetesClient, KubernetesDiscoveryProperties.DEFAULT, SERVICE_PORT_SECURE_RESOLVER, + NAMESPACE_PROVIDER, x -> true); ReactiveDiscoveryClient client = new Fabric8KubernetesReactiveDiscoveryClient(fabric8KubernetesDiscoveryClient); assertThat(client.description()).isEqualTo("Kubernetes Reactive Discovery Client"); assertThat(client.getOrder()).isEqualTo(ReactiveDiscoveryClient.DEFAULT_ORDER); @@ -99,9 +99,8 @@ void shouldReturnFluxOfServices() { .addNewItem().withNewMetadata().withName("s3").endMetadata().endItem().build()) .once(); Fabric8KubernetesDiscoveryClient fabric8KubernetesDiscoveryClient = new Fabric8KubernetesDiscoveryClient( - kubernetesClient, KubernetesDiscoveryProperties.DEFAULT, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, - x -> true - ); + kubernetesClient, KubernetesDiscoveryProperties.DEFAULT, SERVICE_PORT_SECURE_RESOLVER, + NAMESPACE_PROVIDER, x -> true); ReactiveDiscoveryClient client = new Fabric8KubernetesReactiveDiscoveryClient(fabric8KubernetesDiscoveryClient); Flux services = client.getServices(); StepVerifier.create(services).expectNext("s1", "s2", "s3").expectComplete().verify(); @@ -113,9 +112,8 @@ void shouldReturnEmptyFluxOfServicesWhenNoInstancesFound() { .andReturn(200, new ServiceListBuilder().build()).once(); Fabric8KubernetesDiscoveryClient fabric8KubernetesDiscoveryClient = new Fabric8KubernetesDiscoveryClient( - kubernetesClient, KubernetesDiscoveryProperties.DEFAULT, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, - x -> true - ); + kubernetesClient, KubernetesDiscoveryProperties.DEFAULT, SERVICE_PORT_SECURE_RESOLVER, + NAMESPACE_PROVIDER, x -> true); ReactiveDiscoveryClient client = new Fabric8KubernetesReactiveDiscoveryClient(fabric8KubernetesDiscoveryClient); Flux services = client.getServices(); StepVerifier.create(services).expectNextCount(0).expectComplete().verify(); @@ -128,9 +126,8 @@ void shouldReturnEmptyFluxForNonExistingService() { .andReturn(200, new EndpointsBuilder().build()).once(); Fabric8KubernetesDiscoveryClient fabric8KubernetesDiscoveryClient = new Fabric8KubernetesDiscoveryClient( - kubernetesClient, KubernetesDiscoveryProperties.DEFAULT, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, - x -> true - ); + kubernetesClient, KubernetesDiscoveryProperties.DEFAULT, SERVICE_PORT_SECURE_RESOLVER, + NAMESPACE_PROVIDER, x -> true); ReactiveDiscoveryClient client = new Fabric8KubernetesReactiveDiscoveryClient(fabric8KubernetesDiscoveryClient); Flux instances = client.getInstances("nonexistent-service"); @@ -149,9 +146,8 @@ void shouldReturnEmptyFluxWhenServiceHasNoSubsets() { .andReturn(200, new EndpointsBuilder().build()).once(); Fabric8KubernetesDiscoveryClient fabric8KubernetesDiscoveryClient = new Fabric8KubernetesDiscoveryClient( - kubernetesClient, KubernetesDiscoveryProperties.DEFAULT, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, - x -> true - ); + kubernetesClient, KubernetesDiscoveryProperties.DEFAULT, SERVICE_PORT_SECURE_RESOLVER, + NAMESPACE_PROVIDER, x -> true); ReactiveDiscoveryClient client = new Fabric8KubernetesReactiveDiscoveryClient(fabric8KubernetesDiscoveryClient); Flux instances = client.getInstances("existing-service"); @@ -182,11 +178,10 @@ void shouldReturnFlux() { .andReturn(200, services.getItems().get(0)).once(); Fabric8KubernetesDiscoveryClient fabric8KubernetesDiscoveryClient = new Fabric8KubernetesDiscoveryClient( - kubernetesClient, KubernetesDiscoveryProperties.DEFAULT, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, - x -> true - ); + kubernetesClient, KubernetesDiscoveryProperties.DEFAULT, SERVICE_PORT_SECURE_RESOLVER, + NAMESPACE_PROVIDER, x -> true); - //Metadata metadata = new Metadata(false, null, false, null, true, "port."); + // Metadata metadata = new Metadata(false, null, false, null, true, "port."); ReactiveDiscoveryClient client = new Fabric8KubernetesReactiveDiscoveryClient(fabric8KubernetesDiscoveryClient); Flux instances = client.getInstances("existing-service"); StepVerifier.create(instances).expectNextCount(1).expectComplete().verify(); @@ -219,9 +214,8 @@ void shouldReturnFluxWithPrefixedMetadata() { .once(); Fabric8KubernetesDiscoveryClient fabric8KubernetesDiscoveryClient = new Fabric8KubernetesDiscoveryClient( - kubernetesClient, KubernetesDiscoveryProperties.DEFAULT, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, - x -> true - ); + kubernetesClient, KubernetesDiscoveryProperties.DEFAULT, SERVICE_PORT_SECURE_RESOLVER, + NAMESPACE_PROVIDER, x -> true); ReactiveDiscoveryClient client = new Fabric8KubernetesReactiveDiscoveryClient(fabric8KubernetesDiscoveryClient); Flux instances = client.getInstances("existing-service"); @@ -256,9 +250,8 @@ void shouldReturnFluxWhenServiceHasMultiplePortsAndPrimaryPortNameIsSet() { .once(); Fabric8KubernetesDiscoveryClient fabric8KubernetesDiscoveryClient = new Fabric8KubernetesDiscoveryClient( - kubernetesClient, KubernetesDiscoveryProperties.DEFAULT, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, - x -> true - ); + kubernetesClient, KubernetesDiscoveryProperties.DEFAULT, SERVICE_PORT_SECURE_RESOLVER, + NAMESPACE_PROVIDER, x -> true); ReactiveDiscoveryClient client = new Fabric8KubernetesReactiveDiscoveryClient(fabric8KubernetesDiscoveryClient); Flux instances = client.getInstances("existing-service"); @@ -289,11 +282,9 @@ void shouldReturnFluxOfServicesAcrossAllNamespaces() { .once(); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, - false, null, Set.of(), Map.of(), "https_tcp", Metadata.DEFAULT, 0, true); + false, null, Set.of(), Map.of(), "https_tcp", Metadata.DEFAULT, 0, true); Fabric8KubernetesDiscoveryClient fabric8KubernetesDiscoveryClient = new Fabric8KubernetesDiscoveryClient( - kubernetesClient, properties, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, - x -> true - ); + kubernetesClient, properties, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true); ReactiveDiscoveryClient client = new Fabric8KubernetesReactiveDiscoveryClient(fabric8KubernetesDiscoveryClient); Flux instances = client.getInstances("existing-service"); diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/ServicePortSecureResolverTest.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/ServicePortSecureResolverTest.java index f3363afd7c..30f54a0314 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/ServicePortSecureResolverTest.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/ServicePortSecureResolverTest.java @@ -57,18 +57,18 @@ void testPortNumbersOnly() { ServicePortSecureResolver secureResolver = new ServicePortSecureResolver(properties); assertThat(secureResolver.resolve(new ServicePortSecureResolver.Input(null, "dummy", Map.of(), Map.of()))) - .isFalse(); + .isFalse(); assertThat(secureResolver.resolve(new ServicePortSecureResolver.Input(8080, "dummy", Map.of(), Map.of()))) - .isFalse(); + .isFalse(); assertThat(secureResolver.resolve(new ServicePortSecureResolver.Input(1234, "dummy", Map.of(), Map.of()))) - .isFalse(); + .isFalse(); assertThat(secureResolver.resolve(new ServicePortSecureResolver.Input(443, "dummy", Map.of(), Map.of()))) - .isTrue(); + .isTrue(); assertThat(secureResolver.resolve(new ServicePortSecureResolver.Input(8443, "dummy", Map.of(), Map.of()))) - .isTrue(); + .isTrue(); assertThat(secureResolver.resolve(new ServicePortSecureResolver.Input(12345, "dummy", Map.of(), Map.of()))) - .isTrue(); + .isTrue(); } @Test From 1c7a7e6d8b9993622279eedd41c75a9bf90543c8 Mon Sep 17 00:00:00 2001 From: wind57 Date: Sun, 26 Feb 2023 18:26:04 +0200 Subject: [PATCH 029/151] first draft --- .../fabric8/discovery/Fabric8KubernetesDiscoveryClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClient.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClient.java index b2587b78bb..9dba056e4e 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClient.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClient.java @@ -48,7 +48,7 @@ * @author Ioannis Canellos * @author Tim Ysewyn */ -final class Fabric8KubernetesDiscoveryClient implements DiscoveryClient { +public final class Fabric8KubernetesDiscoveryClient implements DiscoveryClient { private static final LogAccessor LOG = new LogAccessor(LogFactory.getLog(Fabric8KubernetesDiscoveryClient.class)); From fe9885ee8f5e582dd897f38a95d999052bc3d0d9 Mon Sep 17 00:00:00 2001 From: wind57 Date: Mon, 27 Feb 2023 13:46:51 +0200 Subject: [PATCH 030/151] dirty --- .../Fabric8DiscoveryServicesAdapter.java | 92 ------ .../Fabric8ExternalNameServiceProvider.java | 75 ----- .../KubernetesClientServicesFunction.java | 3 + .../discovery/KubernetesDiscoveryClient.java | 40 ++- .../KubernetesDiscoveryClientUtils.java | 50 ++++ .../Fabric8DiscoveryServicesAdapterTests.java | 20 +- ...abric8EndpointsAndEndpointSlicesTests.java | 8 +- ...atalogWatchEndpointSlicesSupportTests.java | 8 +- ...c8KubernetesDiscoveryClientUtilsTests.java | 275 ++++++++++++++++++ .../discovery/KubernetesCatalogWatchTest.java | 4 +- ...etesDiscoveryClientFilterMetadataTest.java | 16 +- .../KubernetesDiscoveryClientFilterTest.java | 6 +- .../KubernetesDiscoveryClientTest.java | 22 +- .../KubernetesDiscoveryClientTests.java | 32 +- .../KubernetesDiscoveryClientUtilsTests.java | 38 +-- .../ServicePortSecureResolverTest.java | 2 +- ...ubernetesReactiveDiscoveryClientTests.java | 2 +- 17 files changed, 437 insertions(+), 256 deletions(-) delete mode 100644 spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryServicesAdapter.java delete mode 100644 spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8ExternalNameServiceProvider.java create mode 100644 spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtilsTests.java diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryServicesAdapter.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryServicesAdapter.java deleted file mode 100644 index 5cc5420b2a..0000000000 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryServicesAdapter.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2012-2022 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.discovery; - -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.function.Function; -import java.util.function.Predicate; - -import io.fabric8.kubernetes.api.model.Service; -import io.fabric8.kubernetes.client.KubernetesClient; - -import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; -import org.springframework.expression.Expression; -import org.springframework.expression.spel.standard.SpelExpressionParser; -import org.springframework.expression.spel.support.SimpleEvaluationContext; - -/** - * Adapts a {@link KubernetesClientServicesFunction} to a Function that takes a - * KubernetesClient as input and returns a List of Services(s), plus adds functionality - * not supported by it. - * - * @author wind57 - */ -final class Fabric8DiscoveryServicesAdapter implements Function> { - - private static final SpelExpressionParser PARSER = new SpelExpressionParser(); - - private static final SimpleEvaluationContext EVALUATION_CONTEXT = SimpleEvaluationContext.forReadOnlyDataBinding() - .withInstanceMethods().build(); - - private final KubernetesClientServicesFunction function; - - private final KubernetesDiscoveryProperties properties; - - private final Predicate filter; - - Fabric8DiscoveryServicesAdapter(KubernetesClientServicesFunction function, KubernetesDiscoveryProperties properties, - Predicate filter) { - this.function = function; - this.properties = properties; - if (filter == null) { - this.filter = filter(); - } - else { - this.filter = filter; - } - } - - @Override - public List apply(KubernetesClient client) { - if (!properties.namespaces().isEmpty()) { - List services = new ArrayList<>(); - properties.namespaces().forEach(namespace -> services.addAll(client.services().inNamespace(namespace) - .withLabels(properties.serviceLabels()).list().getItems().stream().filter(filter).toList())); - return services; - } - return function.apply(client).list().getItems().stream().filter(filter).toList(); - } - - Predicate filter() { - String spelExpression = properties.filter(); - Predicate predicate; - if (spelExpression == null || spelExpression.isEmpty()) { - predicate = service -> true; - } - else { - Expression filterExpr = PARSER.parseExpression(spelExpression); - predicate = service -> { - Boolean include = filterExpr.getValue(EVALUATION_CONTEXT, service, Boolean.class); - return Optional.ofNullable(include).orElse(false); - }; - } - return predicate; - } - -} diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8ExternalNameServiceProvider.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8ExternalNameServiceProvider.java deleted file mode 100644 index 69af9fcbfa..0000000000 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8ExternalNameServiceProvider.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2012-2023 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.discovery; - -import io.fabric8.kubernetes.api.model.Endpoints; -import io.fabric8.kubernetes.client.KubernetesClient; -import org.apache.commons.logging.LogFactory; -import org.springframework.cloud.client.ServiceInstance; -import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; -import org.springframework.core.log.LogAccessor; - -import java.util.ArrayList; -import java.util.List; - -import static org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientUtils.endpoints; - -/** - * Provides instances of services that have "spec.type: ExternalName". - * - * @author wind57 - */ -final class Fabric8ExternalNameServiceProvider { - - private static final LogAccessor LOG = new LogAccessor(LogFactory.getLog(Fabric8ExternalNameServiceProvider.class)); - - private final KubernetesDiscoveryProperties properties; - - private final KubernetesClient client; - - Fabric8ExternalNameServiceProvider(KubernetesDiscoveryProperties properties, KubernetesClient client) { - this.properties = properties; - this.client = client; - } - - List externalServiceInstances() { - if (!properties.includeExternalNameServices()) { - LOG.debug(() -> "skipping external name services look-up"); - return List.of(); - } - - if (properties.allNamespaces()) { - LOG.debug(() -> "searching for endpoints in all namespaces"); - return client.services().inAnyNamespace().withNewFilter(), properties; - } -// else if (properties.namespaces().isEmpty()) { -// LOG.debug(() -> "searching for endpoints in namespace : " + client.getNamespace()); -// return endpoints(client.endpoints().withNewFilter(), properties, serviceId); -// } -// else { -// LOG.debug(() -> "searching for endpoints in namespaces : " + properties.namespaces()); -// List endpoints = new ArrayList<>(); -// for (String namespace : properties.namespaces()) { -// endpoints.addAll( -// endpoints(client.endpoints().inNamespace(namespace).withNewFilter(), properties, serviceId)); -// } -// return endpoints; -// } - } - -} - - diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesClientServicesFunction.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesClientServicesFunction.java index e06aa948df..8d2fb66e49 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesClientServicesFunction.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesClientServicesFunction.java @@ -40,8 +40,11 @@ * * See KubernetesDiscoveryClientAutoConfiguration.servicesFunction * + * @deprecated this is not used internally anymore and will be removed in a future release. + * * @author Georgios Andrianakis */ +@Deprecated(forRemoval = true) public interface KubernetesClientServicesFunction extends Function>> { diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java index 4dc7e0f622..be65fec285 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java @@ -20,6 +20,7 @@ import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Optional; import java.util.function.Predicate; import io.fabric8.kubernetes.api.model.EndpointAddress; @@ -36,12 +37,16 @@ import org.springframework.context.EnvironmentAware; import org.springframework.core.env.Environment; import org.springframework.core.log.LogAccessor; +import org.springframework.expression.Expression; +import org.springframework.expression.spel.standard.SpelExpressionParser; +import org.springframework.expression.spel.support.SimpleEvaluationContext; import static org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientUtils.addresses; import static org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientUtils.endpoints; import static org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientUtils.endpointsPort; import static org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientUtils.serviceInstance; import static org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientUtils.serviceMetadata; +import static org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientUtils.services; /** * Kubernetes implementation of {@link DiscoveryClient}. @@ -51,16 +56,17 @@ */ public class KubernetesDiscoveryClient implements DiscoveryClient, EnvironmentAware { + private static final SpelExpressionParser PARSER = new SpelExpressionParser(); + + private static final SimpleEvaluationContext EVALUATION_CONTEXT = SimpleEvaluationContext.forReadOnlyDataBinding() + .withInstanceMethods().build(); + private static final LogAccessor LOG = new LogAccessor(LogFactory.getLog(KubernetesDiscoveryClient.class)); private final KubernetesDiscoveryProperties properties; - private final KubernetesClientServicesFunction kubernetesClientServicesFunction; - private final ServicePortSecureResolver servicePortSecureResolver; - private final Fabric8DiscoveryServicesAdapter adapter; - private KubernetesClient client; private KubernetesNamespaceProvider namespaceProvider; @@ -80,9 +86,6 @@ public KubernetesDiscoveryClient(KubernetesClient client, this.client = client; this.properties = kubernetesDiscoveryProperties; this.servicePortSecureResolver = servicePortSecureResolver; - this.kubernetesClientServicesFunction = kubernetesClientServicesFunction; - this.adapter = new Fabric8DiscoveryServicesAdapter(kubernetesClientServicesFunction, - kubernetesDiscoveryProperties, filter); } public KubernetesClient getClient() { @@ -150,13 +153,14 @@ private List getNamespaceServiceInstances(EndpointSubsetNS es, @Override public List getServices() { - return adapter.apply(client).stream().map(s -> s.getMetadata().getName()).toList(); + return services(properties, client, namespaceProvider, filter(), null, "fabric8-discovery") + .stream().map(s -> s.getMetadata().getName()).toList(); } @Deprecated(forRemoval = true) public List getServices(Predicate filter) { - return new Fabric8DiscoveryServicesAdapter(kubernetesClientServicesFunction, properties, filter).apply(client) - .stream().map(s -> s.getMetadata().getName()).toList(); + return services(properties, client, namespaceProvider, filter, null, "fabric8-discovery") + .stream().map(s -> s.getMetadata().getName()).toList(); } @Override @@ -170,4 +174,20 @@ public final void setEnvironment(Environment environment) { namespaceProvider = new KubernetesNamespaceProvider(environment); } + private Predicate filter() { + String spelExpression = properties.filter(); + Predicate predicate; + if (spelExpression == null || spelExpression.isEmpty()) { + predicate = service -> true; + } + else { + Expression filterExpr = PARSER.parseExpression(spelExpression); + predicate = service -> { + Boolean include = filterExpr.getValue(EVALUATION_CONTEXT, service, Boolean.class); + return Optional.ofNullable(include).orElse(false); + }; + } + return predicate; + } + } diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtils.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtils.java index d84b1cf324..c2e50456e0 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtils.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtils.java @@ -21,6 +21,7 @@ import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.function.Predicate; import java.util.stream.Collectors; import io.fabric8.kubernetes.api.model.EndpointAddress; @@ -30,10 +31,12 @@ import io.fabric8.kubernetes.api.model.EndpointsList; import io.fabric8.kubernetes.api.model.ObjectReference; import io.fabric8.kubernetes.api.model.Service; +import io.fabric8.kubernetes.api.model.ServiceList; import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.kubernetes.client.dsl.FilterNested; import io.fabric8.kubernetes.client.dsl.FilterWatchListDeletable; import io.fabric8.kubernetes.client.dsl.Resource; +import io.fabric8.kubernetes.client.dsl.ServiceResource; import jakarta.annotation.Nullable; import org.apache.commons.logging.LogFactory; @@ -242,6 +245,53 @@ static ServiceInstance serviceInstance(ServicePortSecureResolver servicePortSecu serviceMetadata, secured, namespace, null); } + static List services(KubernetesDiscoveryProperties properties, KubernetesClient client, + KubernetesNamespaceProvider namespaceProvider, Predicate predicate, String serviceName, + String target) { + + List services; + + if (properties.allNamespaces()) { + LOG.debug(() -> "discovering services in all namespaces"); + services = filteredServices(client.services().inAnyNamespace().withNewFilter(), properties, predicate, + serviceName); + } + else if (!properties.namespaces().isEmpty()) { + LOG.debug(() -> "discovering services in namespaces : " + properties.namespaces()); + List inner = new ArrayList<>(properties.namespaces().size()); + properties.namespaces().forEach( + namespace -> inner.addAll(filteredServices(client.services().inNamespace(namespace).withNewFilter(), + properties, predicate, serviceName))); + services = inner; + } + else { + String namespace = Fabric8Utils.getApplicationNamespace(client, null, target, namespaceProvider); + LOG.debug(() -> "discovering services in namespace : " + namespace); + services = filteredServices(client.services().inNamespace(namespace).withNewFilter(), properties, predicate, + serviceName); + } + + return services; + } + + /** + * serviceName can be null, in which case, such a filter will not be applied. + */ + private static List filteredServices( + FilterNested>> filterNested, + KubernetesDiscoveryProperties properties, Predicate predicate, @Nullable String serviceName) { + + FilterNested>> partial = filterNested + .withLabels(properties.serviceLabels()); + + if (serviceName != null) { + partial = partial.withField("metadata.name", serviceName); + } + + return partial.endFilter().list().getItems().stream().filter(predicate).toList(); + + } + private static Optional fromMap(Map existingPorts, String key, String message) { Integer fromPrimaryPortName = existingPorts.get(key); if (fromPrimaryPortName == null) { diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryServicesAdapterTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryServicesAdapterTests.java index df45b1edc6..0d378fb207 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryServicesAdapterTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryServicesAdapterTests.java @@ -79,7 +79,7 @@ void testAllNamespacesWithoutLabelsWithoutFilter() { MockEnvironment environment = new MockEnvironment(); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), - true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false); + true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, @@ -117,7 +117,7 @@ void testAllNamespacesWithLabelsWithoutFilter() { MockEnvironment environment = new MockEnvironment(); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), - true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false); + true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, @@ -156,7 +156,7 @@ void testAllNamespacesWithoutLabelsWithNamespaceFilter() { MockEnvironment environment = new MockEnvironment(); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), - true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false); + true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, @@ -196,7 +196,7 @@ void testAllNamespacesWithoutLabelsWithNamespacesFilter() { MockEnvironment environment = new MockEnvironment(); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), - true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false); + true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, @@ -235,7 +235,7 @@ void testSpecificNamespaceWithoutLabelsWithoutFilter() { MockEnvironment environment = new MockEnvironment(); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), - true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false); + true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, @@ -277,7 +277,7 @@ void testSpecificNamespaceWithLabelsWithoutFilter() { MockEnvironment environment = new MockEnvironment(); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), - true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false); + true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, @@ -324,7 +324,7 @@ void testSpecificNamespaceWithoutLabelsWithFilter() { MockEnvironment environment = new MockEnvironment(); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), - true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false); + true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, @@ -369,7 +369,7 @@ void testSomeNamespacesWithoutLabelsWithoutFilter() { MockEnvironment environment = new MockEnvironment(); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, - someNamespaces, true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false); + someNamespaces, true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, @@ -412,7 +412,7 @@ void testSomeNamespacesWithLabelsWithoutFilter() { MockEnvironment environment = new MockEnvironment(); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, - someNamespaces, true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false); + someNamespaces, true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, @@ -454,7 +454,7 @@ void testSomeNamespacesWithLabelsWithFilter() { MockEnvironment environment = new MockEnvironment(); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, - someNamespaces, true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false); + someNamespaces, true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8EndpointsAndEndpointSlicesTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8EndpointsAndEndpointSlicesTests.java index a289b42c5c..593d06b359 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8EndpointsAndEndpointSlicesTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8EndpointsAndEndpointSlicesTests.java @@ -238,7 +238,7 @@ KubernetesCatalogWatch createWatcherInAllNamespacesWithLabels(Map n // all-namespaces = false KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, namespaces, true, 60, - false, "", Set.of(), labels, "", null, 0, false); + false, "", Set.of(), labels, "", null, 0, false, false); KubernetesCatalogWatch watch = new KubernetesCatalogWatch(mockClient(), properties, NAMESPACE_PROVIDER); if (endpointSlices) { @@ -302,7 +302,7 @@ void endpoints(String namespace, Map labels, String podName) { Endpoints endpoints = new EndpointsBuilder() .withMetadata(new ObjectMetaBuilder().withLabels(labels).withName("endpoints-" + podName).build()) .withSubsets(List.of(endpointSubset)).build(); - mockClient().endpoints().inNamespace(namespace).create(endpoints); + mockClient().endpoints().inNamespace(namespace).resource(endpoints).create(); } static void endpointSlice(String namespace, Map labels, String podName) { diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchEndpointSlicesSupportTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchEndpointSlicesSupportTests.java index 54cfbc8d69..40e05f4666 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchEndpointSlicesSupportTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchEndpointSlicesSupportTests.java @@ -63,7 +63,7 @@ void beforeEach() { @Test void testEndpointSlicesEnabledButNotSupportedViaApiGroups() { KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, - false, "", Set.of(), Map.of(), "", null, 0, true); + false, "", Set.of(), Map.of(), "", null, 0, true, false); APIGroupList groupList = new APIGroupListBuilder().build(); mockServer.expect().withPath("/apis").andReturn(200, groupList).always(); @@ -83,7 +83,7 @@ void testEndpointSlicesEnabledButNotSupportedViaApiGroups() { @Test void testEndpointSlicesEnabledButNotSupportedViaApiVersions() { KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, - false, "", Set.of(), Map.of(), "", null, 0, true); + false, "", Set.of(), Map.of(), "", null, 0, true, false); GroupVersionForDiscovery forDiscovery = new GroupVersionForDiscoveryBuilder() .withGroupVersion("discovery.k8s.io/v1").build(); @@ -106,7 +106,7 @@ void testEndpointSlicesEnabledButNotSupportedViaApiVersions() { @Test void testEndpointsSupport() { KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, - false, "", Set.of(), Map.of(), "", null, 0, false); + false, "", Set.of(), Map.of(), "", null, 0, false, false); KubernetesCatalogWatch watch = new KubernetesCatalogWatch(mockClient, properties, NAMESPACE_PROVIDER); Assertions.assertEquals(Fabric8EndpointsCatalogWatch.class, watch.stateGenerator().getClass()); @@ -119,7 +119,7 @@ void testEndpointsSupport() { @Test void testEndpointSlicesSupport() { KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, - false, "", Set.of(), Map.of(), "", null, 0, true); + false, "", Set.of(), Map.of(), "", null, 0, true, false); KubernetesCatalogWatch watch = new KubernetesCatalogWatch(mockClient, properties, NAMESPACE_PROVIDER); GroupVersionForDiscovery forDiscovery = new GroupVersionForDiscoveryBuilder() diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtilsTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtilsTests.java new file mode 100644 index 0000000000..3289f0ce2c --- /dev/null +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtilsTests.java @@ -0,0 +1,275 @@ +/* + * Copyright 2013-2023 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.discovery; + +import java.util.List; +import java.util.Map; +import java.util.Set; + +import io.fabric8.kubernetes.api.model.Service; +import io.fabric8.kubernetes.api.model.ServiceBuilder; +import io.fabric8.kubernetes.client.KubernetesClient; +import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider; +import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; +import org.springframework.mock.env.MockEnvironment; + +import static org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientUtils.services; + +/** + * @author wind57 + */ +@EnableKubernetesMockClient(crud = true, https = false) +class Fabric8KubernetesDiscoveryClientUtilsTests { + + private static KubernetesClient client; + + @AfterEach + void afterEach() { + client.services().inAnyNamespace().delete(); + } + + /** + *
+	 *     - all-namespaces = true
+	 *     - serviceA present in namespace "A"
+	 *     - serviceB present in namespace "B"
+	 *     - no filters are applied, so both are present
+	 * 
+ */ + @Test + void testServicesAllNamespacesNoFilters() { + boolean allNamespaces = true; + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, Set.of(), + true, 60L, false, "", Set.of(), Map.of(), "", null, 0, false, false); + service("serviceA", "A", Map.of()); + service("serviceB", "B", Map.of()); + + List result = services(properties, client, null, x -> true, null, "fabric8-discovery"); + Assertions.assertEquals(result.size(), 2); + Assertions.assertEquals(result.stream().map(s -> s.getMetadata().getName()).sorted().toList(), + List.of("serviceA", "serviceB")); + } + + /** + *
+	 *     - all-namespaces = true
+	 *     - serviceA present in namespace "A"
+	 *     - serviceB present in namespace "B"
+	 *     - we search only for "serviceA" filter, so only one is returned
+	 * 
+ */ + @Test + void testServicesAllNamespacesNameFilter() { + boolean allNamespaces = true; + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, Set.of(), + true, 60L, false, "", Set.of(), Map.of(), "", null, 0, false, false); + service("serviceA", "A", Map.of()); + service("serviceB", "B", Map.of()); + + List result = services(properties, client, null, x -> true, "serviceA", "fabric8-discovery"); + Assertions.assertEquals(result.size(), 1); + Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); + } + + /** + *
+	 *     - all-namespaces = true
+	 *     - serviceA present in namespace "A"
+	 *     - serviceB present in namespace "B"
+	 *     - we search with a filter where a label with name "letter" and value "b" is present
+	 * 
+ */ + @Test + void testServicesAllNamespacesPredicateFilter() { + boolean allNamespaces = true; + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, Set.of(), + true, 60L, false, "", Set.of(), Map.of(), "", null, 0, false, false); + service("serviceA", "A", Map.of("letter", "a")); + service("serviceB", "B", Map.of("letter", "b")); + + List result = services(properties, client, null, + x -> x.getMetadata().getLabels().equals(Map.of("letter", "b")), null, "fabric8-discovery"); + Assertions.assertEquals(result.size(), 1); + Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceB"); + } + + /** + *
+	 *     - all-namespaces = false
+	 *     - selective namespaces : [A, B]
+	 *     - serviceA present in namespace "A"
+	 *     - serviceB present in namespace "B"
+	 *     - serviceC present in namespace "C"
+	 *     - we search in namespaces [A, B], as such two services are returned
+	 * 
+ */ + @Test + void testServicesSelectiveNamespacesNoFilters() { + boolean allNamespaces = false; + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, + Set.of("A", "B"), true, 60L, false, "", Set.of(), Map.of(), "", null, 0, false, false); + service("serviceA", "A", Map.of()); + service("serviceB", "B", Map.of()); + service("serviceC", "C", Map.of()); + + List result = services(properties, client, null, x -> true, null, "fabric8-discovery"); + Assertions.assertEquals(result.size(), 2); + Assertions.assertEquals(result.stream().map(x -> x.getMetadata().getName()).sorted().toList(), + List.of("serviceA", "serviceB")); + } + + /** + *
+	 *     - all-namespaces = false
+	 *     - selective namespaces : [A, B]
+	 *     - serviceA present in namespace "A"
+	 *     - serviceB present in namespace "B"
+	 *     - serviceC present in namespace "C"
+	 *     - we search in namespaces [A, B] with name filter = "serviceA", so we get a single result
+	 * 
+ */ + @Test + void testServicesSelectiveNamespacesNameFilter() { + boolean allNamespaces = false; + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, + Set.of("A", "B"), true, 60L, false, "", Set.of(), Map.of(), "", null, 0, false, false); + service("serviceA", "A", Map.of()); + service("serviceB", "B", Map.of()); + service("serviceC", "C", Map.of()); + + List result = services(properties, client, null, x -> true, "serviceA", "fabric8-discovery"); + Assertions.assertEquals(result.size(), 1); + Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); + } + + /** + *
+	 *     - all-namespaces = false
+	 *     - selective namespaces : [A, B]
+	 *     - serviceA present in namespace "A" with labels [letter, a]
+	 *     - serviceB present in namespace "B" with labels [letter, b]
+	 *     - serviceC present in namespace "C" with labels [letter, c]
+	 *     - we search in namespaces [A, B] with predicate filter = [letter, b], so we get a single result
+	 * 
+ */ + @Test + void testServicesSelectiveNamespacesPredicateFilter() { + boolean allNamespaces = false; + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, + Set.of("A", "B"), true, 60L, false, "", Set.of(), Map.of(), "", null, 0, false, false); + service("serviceA", "A", Map.of("letter", "a")); + service("serviceB", "B", Map.of("letter", "b")); + service("serviceC", "C", Map.of("letter", "c")); + + List result = services(properties, client, null, + x -> x.getMetadata().getLabels().equals(Map.of("letter", "b")), null, "fabric8-discovery"); + Assertions.assertEquals(result.size(), 1); + Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceB"); + } + + /** + *
+	 *     - all-namespaces = false
+	 *     - selective namespaces : []
+	 *     - namespace from kubernetes namespace provider = [A]
+	 *     - serviceA present in namespace "A"
+	 *     - serviceB present in namespace "B"
+	 *     - serviceC present in namespace "C"
+	 *     - we search in namespaces [A], as such we get one service
+	 * 
+ */ + @Test + void testServicesNamespaceProviderNoFilters() { + boolean allNamespaces = false; + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, Set.of(), + true, 60L, false, "", Set.of(), Map.of(), "", null, 0, false, false); + service("serviceA", "A", Map.of()); + service("serviceB", "B", Map.of()); + service("serviceC", "C", Map.of()); + + List result = services(properties, client, namespaceProvider("A"), x -> true, null, + "fabric8-discovery"); + Assertions.assertEquals(result.size(), 1); + Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); + } + + /** + *
+	 *     - all-namespaces = false
+	 *     - selective namespaces : []
+	 *     - namespace from kubernetes namespace provider = [A]
+	 *     - serviceA present in namespace "A"
+	 *     - serviceB present in namespace "A"
+	 *     - we search in namespaces [A] with name filter = "serviceA", so we get a single result
+	 * 
+ */ + @Test + void testServicesNamespaceProviderNameFilter() { + boolean allNamespaces = false; + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, Set.of(), + true, 60L, false, "", Set.of(), Map.of(), "", null, 0, false, false); + service("serviceA", "A", Map.of()); + service("serviceB", "A", Map.of()); + + List result = services(properties, client, namespaceProvider("A"), x -> true, "serviceA", + "fabric8-discovery"); + Assertions.assertEquals(result.size(), 1); + Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); + } + + /** + *
+	 *     - all-namespaces = false
+	 *     - selective namespaces : []
+	 *     - namespace from kubernetes namespace provider = [A]
+	 *     - serviceA present in namespace "A"
+	 *     - serviceB present in namespace "A"
+	 *     - we search in namespaces [A] with predicate filter = [letter, b], so we get a single result
+	 * 
+ */ + @Test + void testServicesNamespaceProviderPredicateFilter() { + boolean allNamespaces = false; + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, Set.of(), + true, 60L, false, "", Set.of(), Map.of(), "", null, 0, false, false); + service("serviceA", "A", Map.of("letter", "a")); + service("serviceB", "A", Map.of("letter", "b")); + + List result = services(properties, client, namespaceProvider("A"), + x -> x.getMetadata().getLabels().equals(Map.of("letter", "b")), null, "fabric8-discovery"); + Assertions.assertEquals(result.size(), 1); + Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceB"); + } + + private void service(String name, String namespace, Map labels) { + Service service = new ServiceBuilder().withNewMetadata().withName(name).withLabels(labels) + .withNamespace(namespace).and().build(); + client.services().inNamespace(namespace).resource(service).create(); + } + + private KubernetesNamespaceProvider namespaceProvider(String namespace) { + MockEnvironment mockEnvironment = new MockEnvironment(); + mockEnvironment.setProperty("spring.cloud.kubernetes.client.namespace", namespace); + return new KubernetesNamespaceProvider(mockEnvironment); + } + +} diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesCatalogWatchTest.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesCatalogWatchTest.java index 5f3f7b9fca..db362231da 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesCatalogWatchTest.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesCatalogWatchTest.java @@ -368,7 +368,7 @@ private void createInAllNamespaceWatcher() { // all-namespaces = true KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, - false, "", Set.of(), Map.of(), "", null, 0, false); + false, "", Set.of(), Map.of(), "", null, 0, false, false); kubernetesCatalogWatch = new KubernetesCatalogWatch(CLIENT, properties, namespaceProvider); kubernetesCatalogWatch.setApplicationEventPublisher(APPLICATION_EVENT_PUBLISHER); @@ -387,7 +387,7 @@ private void createInSpecificNamespaceWatcher() { // all-namespaces = false KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, - false, "", Set.of(), Map.of(), "", null, 0, false); + false, "", Set.of(), Map.of(), "", null, 0, false, false); kubernetesCatalogWatch = new KubernetesCatalogWatch(CLIENT, properties, namespaceProvider); kubernetesCatalogWatch.setApplicationEventPublisher(APPLICATION_EVENT_PUBLISHER); diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientFilterMetadataTest.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientFilterMetadataTest.java index 0e1390e611..431627e5d8 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientFilterMetadataTest.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientFilterMetadataTest.java @@ -81,7 +81,7 @@ void testAllExtraMetadataDisabled() { Metadata metadata = new Metadata(false, null, false, null, false, null); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, - false, null, Set.of(), Map.of(), null, metadata, 0, true); + false, null, Set.of(), Map.of(), null, metadata, 0, true, false); KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(CLIENT, properties, a -> null); discoveryClient.setEnvironment(withClientNamespace()); @@ -100,7 +100,7 @@ void testLabelsEnabled() { Metadata metadata = new Metadata(true, null, false, null, false, null); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, - false, null, Set.of(), Map.of(), null, metadata, 0, true); + false, null, Set.of(), Map.of(), null, metadata, 0, true, false); KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(CLIENT, properties, a -> null); discoveryClient.setEnvironment(withClientNamespace()); @@ -120,7 +120,7 @@ void testLabelsEnabledWithPrefix() { Metadata metadata = new Metadata(true, "l_", false, null, false, null); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, - false, null, Set.of(), Map.of(), null, metadata, 0, true); + false, null, Set.of(), Map.of(), null, metadata, 0, true, false); KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(CLIENT, properties, a -> null); discoveryClient.setEnvironment(withClientNamespace()); @@ -140,7 +140,7 @@ void testAnnotationsEnabled() { Metadata metadata = new Metadata(false, null, true, null, false, null); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, - false, null, Set.of(), Map.of(), null, metadata, 0, true); + false, null, Set.of(), Map.of(), null, metadata, 0, true, false); KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(CLIENT, properties, a -> null); discoveryClient.setEnvironment(withClientNamespace()); @@ -160,7 +160,7 @@ void testAnnotationsEnabledWithPrefix() { Metadata metadata = new Metadata(false, null, true, "a_", false, null); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, - false, null, Set.of(), Map.of(), null, metadata, 0, true); + false, null, Set.of(), Map.of(), null, metadata, 0, true, false); KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(CLIENT, properties, a -> null); discoveryClient.setEnvironment(withClientNamespace()); @@ -180,7 +180,7 @@ void testPortsEnabled() { Metadata metadata = new Metadata(false, null, false, null, true, null); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, - false, null, Set.of(), Map.of(), null, metadata, 0, true); + false, null, Set.of(), Map.of(), null, metadata, 0, true, false); KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(CLIENT, properties, a -> null); discoveryClient.setEnvironment(withClientNamespace()); @@ -199,7 +199,7 @@ void testPortsEnabledWithPrefix() { Metadata metadata = new Metadata(false, null, false, null, true, "p_"); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, - false, null, Set.of(), Map.of(), null, metadata, 0, true); + false, null, Set.of(), Map.of(), null, metadata, 0, true, false); KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(CLIENT, properties, a -> null); discoveryClient.setEnvironment(withClientNamespace()); @@ -218,7 +218,7 @@ void testLabelsAndAnnotationsAndPortsEnabledWithPrefix() { Metadata metadata = new Metadata(true, "l_", true, "a_", true, "p_"); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, - false, null, Set.of(), Map.of(), null, metadata, 0, true); + false, null, Set.of(), Map.of(), null, metadata, 0, true, false); KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(CLIENT, properties, a -> null); discoveryClient.setEnvironment(withClientNamespace()); diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientFilterTest.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientFilterTest.java index 6399457f21..d4d5111bef 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientFilterTest.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientFilterTest.java @@ -64,7 +64,7 @@ void testFilteredServices() { KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, false, "metadata.additionalProperties['spring-boot']", Set.of(), Map.of(), null, - KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, true); + KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, true, false); KubernetesDiscoveryClient client = new KubernetesDiscoveryClient(this.kubernetesClient, properties, this.kubernetesClientServicesFunction); @@ -92,7 +92,7 @@ void testFilteredServicesByPrefix() { KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, false, "metadata.name.startsWith('service')", Set.of(), Map.of(), null, - KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, true); + KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, true, false); KubernetesDiscoveryClient client = new KubernetesDiscoveryClient(this.kubernetesClient, properties, this.kubernetesClientServicesFunction); @@ -112,7 +112,7 @@ void testNoExpression() { when(this.kubernetesClient.services()).thenReturn(this.serviceOperation); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, - false, "", Set.of(), Map.of(), null, KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, true); + false, "", Set.of(), Map.of(), null, KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, true, false); KubernetesDiscoveryClient client = new KubernetesDiscoveryClient(this.kubernetesClient, properties, this.kubernetesClientServicesFunction); diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientTest.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientTest.java index 404cdcbc83..d993462fd4 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientTest.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientTest.java @@ -105,7 +105,7 @@ void getInstancesShouldBeAbleToHandleEndpointsSingleAddressAndMultiplePorts() { mockClient.services().inNamespace("test").resource(service).create(); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, - false, null, Set.of(), labels, "http_tcp", Metadata.DEFAULT, 0, true); + false, null, Set.of(), labels, "http_tcp", Metadata.DEFAULT, 0, true, false); DiscoveryClient discoveryClient = new KubernetesDiscoveryClient(mockClient, properties, KubernetesClient::services, null, new ServicePortSecureResolver(properties)); @@ -153,7 +153,7 @@ void getEndPointsListTestAllNamespaces() { mockClient.endpoints().inNamespace(namespace2).resource(endPoint2).create(); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, - false, null, Set.of(), Map.of(), null, KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, false); + false, null, Set.of(), Map.of(), null, KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, false, false); KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(mockClient, properties, KubernetesClient::services, null, new ServicePortSecureResolver(properties)); @@ -183,7 +183,7 @@ void getEndPointsListShouldHandleNamespaces() { KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(namespace1, namespace3), true, 60, false, null, Set.of(), Map.of(), null, - KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, false); + KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, false, false); KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(mockClient, properties, KubernetesClient::services, null, new ServicePortSecureResolver(properties)); @@ -214,7 +214,7 @@ void getInstancesShouldBeAbleToHandleEndpointsMultipleAddresses() { Metadata metadata = new Metadata(false, null, false, null, true, "port."); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, - false, null, Set.of(443, 8443), labels, null, metadata, 0, true); + false, null, Set.of(443, 8443), labels, null, metadata, 0, true, false); DiscoveryClient discoveryClient = new KubernetesDiscoveryClient(mockClient, properties, KubernetesClient::services, null, new ServicePortSecureResolver(properties)); @@ -297,7 +297,7 @@ void getServicesShouldReturnServicesInNamespaces() { KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(nameSpace1, nameSpace2), true, 60, false, null, Set.of(), Map.of(), null, - KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, false); + KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, false, false); DiscoveryClient discoveryClient = new KubernetesDiscoveryClient(mockClient, properties, KubernetesClient::services, null, new ServicePortSecureResolver(properties)); @@ -330,7 +330,7 @@ void getInstancesShouldBeAbleToHandleEndpointsFromMultipleNamespaces() { mockClient.services().inNamespace("test2").resource(service2).create(); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, - false, null, Set.of(), Map.of(), null, Metadata.DEFAULT, 0, true); + false, null, Set.of(), Map.of(), null, Metadata.DEFAULT, 0, true, false); DiscoveryClient discoveryClient = new KubernetesDiscoveryClient(mockClient, properties, KubernetesClient::services, null, new ServicePortSecureResolver(properties)); @@ -381,7 +381,7 @@ void getInstancesShouldBeAbleToHandleEndpointsSingleAddressAndMultiplePortsUsing mockClient.services().inNamespace("test").resource(service).create(); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, - false, null, Set.of(443, 8443), Map.of(), null, Metadata.DEFAULT, 0, true); + false, null, Set.of(443, 8443), Map.of(), null, Metadata.DEFAULT, 0, true, false); DiscoveryClient discoveryClient = new KubernetesDiscoveryClient(mockClient, properties, KubernetesClient::services, null, new ServicePortSecureResolver(properties)); @@ -411,7 +411,7 @@ void instanceWithMultiplePortsAndMisconfiguredPrimaryPortNameInLabelWithoutFallb mockClient.services().inNamespace("test").resource(service).create(); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, - false, null, Set.of(443, 8443), Map.of(), null, Metadata.DEFAULT, 0, true); + false, null, Set.of(443, 8443), Map.of(), null, Metadata.DEFAULT, 0, true, false); DiscoveryClient discoveryClient = new KubernetesDiscoveryClient(mockClient, properties, KubernetesClient::services, null, new ServicePortSecureResolver(properties)); @@ -441,7 +441,7 @@ void instanceWithMultiplePortsAndMisconfiguredGenericPrimaryPortNameWithoutFallb mockClient.services().inNamespace("test").resource(service).create(); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, - false, null, Set.of(443, 8443), Map.of(), "oops", Metadata.DEFAULT, 0, true); + false, null, Set.of(443, 8443), Map.of(), "oops", Metadata.DEFAULT, 0, true, false); DiscoveryClient discoveryClient = new KubernetesDiscoveryClient(mockClient, properties, KubernetesClient::services, null, new ServicePortSecureResolver(properties)); @@ -470,7 +470,7 @@ void instanceWithMultiplePortsAndWithoutPrimaryPortNameSpecifiedShouldFallBackTo mockClient.services().inNamespace("test").resource(service).create(); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, - false, null, Set.of(443, 8443), Map.of(), null, Metadata.DEFAULT, 0, true); + false, null, Set.of(443, 8443), Map.of(), null, Metadata.DEFAULT, 0, true, false); DiscoveryClient discoveryClient = new KubernetesDiscoveryClient(mockClient, properties, KubernetesClient::services, null, new ServicePortSecureResolver(properties)); @@ -526,7 +526,7 @@ void instanceWithMultiplePortsAndWithoutPrimaryPortNameSpecifiedShouldLogWarning mockClient.services().inNamespace("test").resource(service).create(); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, - true, null, Set.of(443, 8443), Map.of(), null, Metadata.DEFAULT, 0, true); + true, null, Set.of(443, 8443), Map.of(), null, Metadata.DEFAULT, 0, true, false); DiscoveryClient discoveryClient = new KubernetesDiscoveryClient(mockClient, properties, KubernetesClient::services, null, new ServicePortSecureResolver(properties)); diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientTests.java index 1252746f98..898d98a739 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientTests.java @@ -75,7 +75,7 @@ void testAllNamespacesEmpty(CapturedOutput output) { Set namespaces = Set.of(); Map serviceLabels = Map.of(); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, - true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); + true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false, false); KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null); List result = discoveryClient.getEndPointsList("serviceId"); @@ -100,7 +100,7 @@ void testAllNamespacesSingleEndpointsMatchExactLabels(CapturedOutput output) { Set namespaces = Set.of(); Map serviceLabels = Map.of("color", "blue"); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, - true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); + true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false, false); KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null); List result = discoveryClient.getEndPointsList("blue-service"); @@ -125,7 +125,7 @@ void testAllNamespacesSingleEndpointsMatchPartialLabels(CapturedOutput output) { Set namespaces = Set.of(); Map serviceLabels = Map.of("color", "blue"); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, - true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); + true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false, false); KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null); List result = discoveryClient.getEndPointsList("blue-service"); @@ -150,7 +150,7 @@ void testAllNamespacesSingleEndpointsNameMatchesLabelsDont(CapturedOutput output Set namespaces = Set.of(); Map serviceLabels = Map.of("color", "blue"); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, - true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); + true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false, false); KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null); List result = discoveryClient.getEndPointsList("blue-service"); @@ -176,7 +176,7 @@ void testAllNamespacesTwoEndpointsOneMatches(CapturedOutput output) { Set namespaces = Set.of(); Map serviceLabels = Map.of("color", "blue"); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, - true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); + true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false, false); KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null); List result = discoveryClient.getEndPointsList("service-one"); @@ -202,7 +202,7 @@ void testAllNamespacesTwoEndpointsInDifferentNamespaces(CapturedOutput output) { Set namespaces = Set.of(); Map serviceLabels = Map.of("color", "blue"); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, - true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); + true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false, false); KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null); List result = discoveryClient.getEndPointsList("service-one"); @@ -226,7 +226,7 @@ void testClientNamespaceEmpty(CapturedOutput output) { Set namespaces = Set.of(); Map serviceLabels = Map.of(); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, - true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); + true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false, false); KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null); List result = discoveryClient.getEndPointsList("serviceId"); @@ -251,7 +251,7 @@ void testClientNamespaceSingleEndpointsMatchExactLabels(CapturedOutput output) { Set namespaces = Set.of(); Map serviceLabels = Map.of("color", "blue"); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, - true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); + true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false, false); KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null); List result = discoveryClient.getEndPointsList("blue-service"); @@ -276,7 +276,7 @@ void testClientNamespaceSingleEndpointsMatchPartialLabels(CapturedOutput output) Set namespaces = Set.of(); Map serviceLabels = Map.of("color", "blue"); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, - true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); + true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false, false); KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null); List result = discoveryClient.getEndPointsList("blue-service"); @@ -301,7 +301,7 @@ void testClientNamespaceSingleEndpointsNameMatchesLabelsDont(CapturedOutput outp Set namespaces = Set.of(); Map serviceLabels = Map.of("color", "blue"); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, - true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); + true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false, false); KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null); List result = discoveryClient.getEndPointsList("blue-service"); @@ -327,7 +327,7 @@ void testClientNamespaceTwoEndpointsOneMatches(CapturedOutput output) { Set namespaces = Set.of(); Map serviceLabels = Map.of("color", "blue"); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, - true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); + true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false, false); KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null); List result = discoveryClient.getEndPointsList("service-one"); @@ -353,7 +353,7 @@ void testClientNamespaceTwoEndpointsInDifferentNamespaces(CapturedOutput output) Set namespaces = Set.of(); Map serviceLabels = Map.of("color", "blue"); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, - true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); + true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false, false); KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null); List result = discoveryClient.getEndPointsList("service-one"); @@ -377,7 +377,7 @@ void testSelectiveNamespacesEmpty(CapturedOutput output) { Set namespaces = Set.of("test"); Map serviceLabels = Map.of(); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, - true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); + true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false, false); KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null); List result = discoveryClient.getEndPointsList("serviceId"); @@ -402,7 +402,7 @@ void testSelectiveNamespacesSingleEndpointsMatchExactLabels(CapturedOutput outpu Set namespaces = Set.of("test"); Map serviceLabels = Map.of("color", "blue"); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, - true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); + true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false, false); KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null); List result = discoveryClient.getEndPointsList("blue-service"); @@ -429,7 +429,7 @@ void testSelectiveNamespacesMultipleNamespacesSingleMatch(CapturedOutput output) Set namespaces = Set.of("a"); Map serviceLabels = Map.of("color", "blue"); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, - true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); + true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false, false); KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null); List result = discoveryClient.getEndPointsList("blue-service"); @@ -459,7 +459,7 @@ void testSelectiveNamespacesMultipleNamespacesAllMatch(CapturedOutput output) { String namespacesAsString = namespaces.toString(); Map serviceLabels = Map.of("color", "blue"); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, - true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false); + true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false, false); KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null); List result = discoveryClient.getEndPointsList("blue-service"); diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java index 9d41b95f8c..a37f3ee412 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java @@ -105,7 +105,7 @@ void testPrimaryPortNameNotFound(CapturedOutput output) { void testPrimaryPortNameFoundInProperties(CapturedOutput output) { String primaryPortName = "https"; KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - true, "", Set.of(), Map.of(), primaryPortName, null, 0, false); + true, "", Set.of(), Map.of(), primaryPortName, null, 0, false, false); Service service = new ServiceBuilder().withMetadata(new ObjectMeta()).build(); String result = KubernetesDiscoveryClientUtils.primaryPortName(properties, service, "abc"); @@ -147,7 +147,7 @@ void testPrimaryPortNameFoundInBothPropertiesAndLabels(CapturedOutput output) { String primaryPortName = "https"; Map labels = Map.of(PRIMARY_PORT_NAME_LABEL_KEY, "http"); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - true, "", Set.of(), Map.of(), primaryPortName, null, 0, false); + true, "", Set.of(), Map.of(), primaryPortName, null, 0, false, false); Service service = new ServiceBuilder().withMetadata(new ObjectMetaBuilder().withLabels(labels).build()).build(); String result = KubernetesDiscoveryClientUtils.primaryPortName(properties, service, "abc"); @@ -219,7 +219,7 @@ void testEndpointsPortPrimaryPortNameIsPresentButNotFound(CapturedOutput output) String primaryPortName = "three"; KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - true, "", Set.of(), Map.of(), primaryPortName, null, 0, false); + true, "", Set.of(), Map.of(), primaryPortName, null, 0, false, false); Service service = new ServiceBuilder().withMetadata(new ObjectMeta()).build(); @@ -253,7 +253,7 @@ void testEndpointsPortPrimaryPortNameFound(CapturedOutput output) { String primaryPortName = "two"; KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - true, "", Set.of(), Map.of(), primaryPortName, null, 0, false); + true, "", Set.of(), Map.of(), primaryPortName, null, 0, false, false); Service service = new ServiceBuilder().withMetadata(new ObjectMeta()).build(); @@ -282,7 +282,7 @@ void testEndpointsPortPrimaryPortHttps(CapturedOutput output) { String primaryPortName = "three"; KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - true, "", Set.of(), Map.of(), primaryPortName, null, 0, false); + true, "", Set.of(), Map.of(), primaryPortName, null, 0, false, false); Service service = new ServiceBuilder().withMetadata(new ObjectMeta()).build(); @@ -312,7 +312,7 @@ void testEndpointsPortPrimaryPortHttp(CapturedOutput output) { String primaryPortName = "three"; KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - true, "", Set.of(), Map.of(), primaryPortName, null, 0, false); + true, "", Set.of(), Map.of(), primaryPortName, null, 0, false, false); Service service = new ServiceBuilder().withMetadata(new ObjectMeta()).build(); @@ -345,7 +345,7 @@ void testServiceMetadataEmpty() { KubernetesDiscoveryProperties.Metadata metadata = new KubernetesDiscoveryProperties.Metadata(addLabels, labelsPrefix, addAnnotations, annotationsPrefix, addPorts, portsPrefix); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - true, "", Set.of(), Map.of(), "", metadata, 0, false); + true, "", Set.of(), Map.of(), "", metadata, 0, false, false); Service service = new ServiceBuilder().build(); Map result = KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, properties, @@ -374,7 +374,7 @@ void testServiceMetadataAddLabelsNoPrefix(CapturedOutput output) { KubernetesDiscoveryProperties.Metadata metadata = new KubernetesDiscoveryProperties.Metadata(addLabels, labelsPrefix, addAnnotations, annotationsPrefix, addPorts, portsPrefix); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - true, "", Set.of(), Map.of(), "", metadata, 0, false); + true, "", Set.of(), Map.of(), "", metadata, 0, false, false); Service service = new ServiceBuilder() .withMetadata(new ObjectMetaBuilder().withLabels(Map.of("a", "b")).build()).build(); @@ -407,7 +407,7 @@ void testServiceMetadataAddLabelsWithPrefix(CapturedOutput output) { KubernetesDiscoveryProperties.Metadata metadata = new KubernetesDiscoveryProperties.Metadata(addLabels, labelsPrefix, addAnnotations, annotationsPrefix, addPorts, portsPrefix); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - true, "", Set.of(), Map.of(), "", metadata, 0, false); + true, "", Set.of(), Map.of(), "", metadata, 0, false, false); Service service = new ServiceBuilder() .withMetadata(new ObjectMetaBuilder().withLabels(Map.of("a", "b", "c", "d")).build()).build(); @@ -441,7 +441,7 @@ void testServiceMetadataAddAnnotationsNoPrefix(CapturedOutput output) { KubernetesDiscoveryProperties.Metadata metadata = new KubernetesDiscoveryProperties.Metadata(addLabels, labelsPrefix, addAnnotations, annotationsPrefix, addPorts, portsPrefix); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - true, "", Set.of(), Map.of(), "", metadata, 0, false); + true, "", Set.of(), Map.of(), "", metadata, 0, false, false); Service service = new ServiceBuilder().withMetadata( new ObjectMetaBuilder().withAnnotations(Map.of("aa", "bb")).withLabels(Map.of("a", "b")).build()) .build(); @@ -474,7 +474,7 @@ void testServiceMetadataAddAnnotationsWithPrefix(CapturedOutput output) { KubernetesDiscoveryProperties.Metadata metadata = new KubernetesDiscoveryProperties.Metadata(addLabels, labelsPrefix, addAnnotations, annotationsPrefix, addPorts, portsPrefix); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - true, "", Set.of(), Map.of(), "", metadata, 0, false); + true, "", Set.of(), Map.of(), "", metadata, 0, false, false); Service service = new ServiceBuilder().withMetadata(new ObjectMetaBuilder() .withAnnotations(Map.of("aa", "bb", "cc", "dd")).withLabels(Map.of("a", "b")).build()).build(); @@ -508,7 +508,7 @@ void testServiceMetadataAddLabelsAndAnnotationsWithPrefix(CapturedOutput output) KubernetesDiscoveryProperties.Metadata metadata = new KubernetesDiscoveryProperties.Metadata(addLabels, labelsPrefix, addAnnotations, annotationsPrefix, addPorts, portsPrefix); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - true, "", Set.of(), Map.of(), "", metadata, 0, false); + true, "", Set.of(), Map.of(), "", metadata, 0, false, false); Service service = new ServiceBuilder().withMetadata(new ObjectMetaBuilder() .withAnnotations(Map.of("aa", "bb", "cc", "dd")).withLabels(Map.of("a", "b", "c", "d")).build()) .build(); @@ -548,7 +548,7 @@ void testServiceMetadataAddPortsWithoutPrefix(CapturedOutput output) { KubernetesDiscoveryProperties.Metadata metadata = new KubernetesDiscoveryProperties.Metadata(addLabels, labelsPrefix, addAnnotations, annotationsPrefix, addPorts, portsPrefix); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - true, "", Set.of(), Map.of(), "", metadata, 0, false); + true, "", Set.of(), Map.of(), "", metadata, 0, false, false); Service service = new ServiceBuilder().withMetadata(new ObjectMetaBuilder() .withAnnotations(Map.of("aa", "bb", "cc", "dd")).withLabels(Map.of("a", "b")).build()).build(); @@ -585,7 +585,7 @@ void testServiceMetadataAddPortsWithPrefix(CapturedOutput output) { KubernetesDiscoveryProperties.Metadata metadata = new KubernetesDiscoveryProperties.Metadata(addLabels, labelsPrefix, addAnnotations, annotationsPrefix, addPorts, portsPrefix); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - true, "", Set.of(), Map.of(), "", metadata, 0, false); + true, "", Set.of(), Map.of(), "", metadata, 0, false, false); Service service = new ServiceBuilder().withMetadata(new ObjectMetaBuilder() .withAnnotations(Map.of("aa", "bb", "cc", "dd")).withLabels(Map.of("a", "b")).build()).build(); @@ -614,7 +614,7 @@ void testServiceMetadataAddPortsWithPrefix(CapturedOutput output) { void testEmptyAddresses() { boolean includeNotReadyAddresses = false; KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - includeNotReadyAddresses, "", Set.of(), Map.of(), "", null, 0, false); + includeNotReadyAddresses, "", Set.of(), Map.of(), "", null, 0, false, false); EndpointSubset endpointSubset = new EndpointSubsetBuilder().build(); List addresses = KubernetesDiscoveryClientUtils.addresses(endpointSubset, properties); Assertions.assertEquals(addresses.size(), 0); @@ -630,7 +630,7 @@ void testEmptyAddresses() { void testReadyAddressesOnly() { boolean includeNotReadyAddresses = false; KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - includeNotReadyAddresses, "", Set.of(), Map.of(), "", null, 0, false); + includeNotReadyAddresses, "", Set.of(), Map.of(), "", null, 0, false, false); EndpointSubset endpointSubset = new EndpointSubsetBuilder() .withAddresses(new EndpointAddressBuilder().withHostname("one").build(), new EndpointAddressBuilder().withHostname("two").build()) @@ -649,7 +649,7 @@ void testReadyAddressesOnly() { void testReadyAddressesTakenNotReadyAddressesNotTaken() { boolean includeNotReadyAddresses = false; KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - includeNotReadyAddresses, "", Set.of(), Map.of(), "", null, 0, false); + includeNotReadyAddresses, "", Set.of(), Map.of(), "", null, 0, false, false); EndpointSubset endpointSubset = new EndpointSubsetBuilder() .withAddresses(new EndpointAddressBuilder().withHostname("one").build(), new EndpointAddressBuilder().withHostname("two").build()) @@ -670,7 +670,7 @@ void testReadyAddressesTakenNotReadyAddressesNotTaken() { void testBothAddressesTaken() { boolean includeNotReadyAddresses = true; KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - includeNotReadyAddresses, "", Set.of(), Map.of(), "", null, 0, false); + includeNotReadyAddresses, "", Set.of(), Map.of(), "", null, 0, false, false); EndpointSubset endpointSubset = new EndpointSubsetBuilder() .withAddresses(new EndpointAddressBuilder().withHostname("one").build(), new EndpointAddressBuilder().withHostname("two").build()) @@ -684,7 +684,7 @@ void testBothAddressesTaken() { @Test void testServiceInstance() { KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - false, "", Set.of(), Map.of(), "", null, 0, false); + false, "", Set.of(), Map.of(), "", null, 0, false, false); ServicePortSecureResolver resolver = new ServicePortSecureResolver(properties); Service service = new ServiceBuilder().withMetadata(new ObjectMeta()).build(); EndpointAddress address = new EndpointAddressBuilder().withNewTargetRef().withUid("123").endTargetRef() diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/ServicePortSecureResolverTest.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/ServicePortSecureResolverTest.java index d390195ba2..bf4c56d4b9 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/ServicePortSecureResolverTest.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/ServicePortSecureResolverTest.java @@ -52,7 +52,7 @@ class ServicePortSecureResolverTest { void testPortNumbersOnly() { KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, false, null, Set.of(443, 8443, 12345), Map.of(), null, KubernetesDiscoveryProperties.Metadata.DEFAULT, - 0, true); + 0, true, false); ServicePortSecureResolver secureResolver = new ServicePortSecureResolver(properties); diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/reactive/KubernetesReactiveDiscoveryClientTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/reactive/KubernetesReactiveDiscoveryClientTests.java index aa7cbd8bda..694452ec0b 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/reactive/KubernetesReactiveDiscoveryClientTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/reactive/KubernetesReactiveDiscoveryClientTests.java @@ -253,7 +253,7 @@ void shouldReturnFluxOfServicesAcrossAllNamespaces() { .once(); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, - false, null, Set.of(), Map.of(), "https_tcp", Metadata.DEFAULT, 0, true); + false, null, Set.of(), Map.of(), "https_tcp", Metadata.DEFAULT, 0, true, false); ReactiveDiscoveryClient client = new KubernetesReactiveDiscoveryClient(kubernetesClient, properties, KubernetesClient::services); Flux instances = client.getInstances("existing-service"); From ca4c503ed40ccd7f373a78b7c7a1a3120e03a57f Mon Sep 17 00:00:00 2001 From: wind57 Date: Mon, 27 Feb 2023 13:59:27 +0200 Subject: [PATCH 031/151] dirty --- .../discovery/KubernetesDiscoveryClient.java | 2 +- ....java => Fabric8DiscoveryFilterTests.java} | 140 ++++++------------ 2 files changed, 50 insertions(+), 92 deletions(-) rename spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/{Fabric8DiscoveryServicesAdapterTests.java => Fabric8DiscoveryFilterTests.java} (77%) diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java index be65fec285..26826c35f1 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java @@ -174,7 +174,7 @@ public final void setEnvironment(Environment environment) { namespaceProvider = new KubernetesNamespaceProvider(environment); } - private Predicate filter() { + Predicate filter() { String spelExpression = properties.filter(); Predicate predicate; if (spelExpression == null || spelExpression.isEmpty()) { diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryServicesAdapterTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryFilterTests.java similarity index 77% rename from spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryServicesAdapterTests.java rename to spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryFilterTests.java index 0d378fb207..15ed933efe 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryServicesAdapterTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryFilterTests.java @@ -35,13 +35,19 @@ import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider; import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; import org.springframework.cloud.kubernetes.fabric8.Fabric8Utils; +import org.springframework.core.env.Environment; import org.springframework.mock.env.MockEnvironment; +import static org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientUtils.services; + /** * @author wind57 */ @EnableKubernetesMockClient(crud = true, https = false) -class Fabric8DiscoveryServicesAdapterTests { +class Fabric8DiscoveryFilterTests { + + private static final KubernetesNamespaceProvider NAMESPACE_PROVIDER = new KubernetesNamespaceProvider( + mockEnvironment()); private static KubernetesClient client; @@ -74,21 +80,16 @@ void afterEach() { void testAllNamespacesWithoutLabelsWithoutFilter() { boolean allNamespaces = true; Map labels = Map.of(); - String spelFilter = null; - - MockEnvironment environment = new MockEnvironment(); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), - true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); - - Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( - new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, - null); + true, 60L, false, null, Set.of(), labels, null, null, 0, false, false); service("namespaceA", "serviceA", Map.of("color", "red")); service("namespaceB", "serviceB", Map.of("color", "blue")); - List result = adapter.apply(client); + List result = services(properties, client, NAMESPACE_PROVIDER, + new KubernetesDiscoveryClient(null, properties, null, null, null).filter(), null, "dummy-target"); + Assertions.assertEquals(result.size(), 2); Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); @@ -112,21 +113,15 @@ void testAllNamespacesWithoutLabelsWithoutFilter() { void testAllNamespacesWithLabelsWithoutFilter() { boolean allNamespaces = true; Map labels = Map.of("color", "red"); - String spelFilter = null; - - MockEnvironment environment = new MockEnvironment(); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), - true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); - - Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( - new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, - null); + true, 60L, false, null, Set.of(), labels, null, null, 0, false, false); service("namespaceA", "serviceA", Map.of("color", "red")); service("namespaceB", "serviceB", Map.of("color", "blue")); - List result = adapter.apply(client); + List result = services(properties, client, NAMESPACE_PROVIDER, + new KubernetesDiscoveryClient(null, properties, null, null, null).filter(), null, "dummy-target"); Assertions.assertEquals(result.size(), 1); Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); @@ -153,19 +148,14 @@ void testAllNamespacesWithoutLabelsWithNamespaceFilter() { #root.metadata.namespace matches "^.+A$" """; - MockEnvironment environment = new MockEnvironment(); - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), - true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); - - Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( - new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, - null); + true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); service("namespaceA", "serviceA", Map.of("color", "red")); service("namespaceB", "serviceB", Map.of("color", "blue")); - List result = adapter.apply(client); + List result = services(properties, client, NAMESPACE_PROVIDER, + new KubernetesDiscoveryClient(null, properties, null, null, null).filter(), null, "dummy-target"); Assertions.assertEquals(result.size(), 1); Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); @@ -193,20 +183,15 @@ void testAllNamespacesWithoutLabelsWithNamespacesFilter() { #root.metadata.namespace matches "^namespace[A|B]$" """; - MockEnvironment environment = new MockEnvironment(); - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), - true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); - - Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( - new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, - null); + true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); service("namespaceA", "serviceA", Map.of("color", "red")); service("namespaceB", "serviceB", Map.of("color", "blue")); service("namespaceC", "serviceC", Map.of("color", "purple")); - List result = adapter.apply(client); + List result = services(properties, client, NAMESPACE_PROVIDER, + new KubernetesDiscoveryClient(null, properties, null, null, null).filter(), null, "dummy-target"); Assertions.assertEquals(result.size(), 2); Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); @@ -230,25 +215,19 @@ void testAllNamespacesWithoutLabelsWithNamespacesFilter() { void testSpecificNamespaceWithoutLabelsWithoutFilter() { boolean allNamespaces = false; Map labels = Map.of(); - String spelFilter = null; - - MockEnvironment environment = new MockEnvironment(); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), - true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); - - Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( - new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, - null); + true, 60L, false, null, Set.of(), labels, null, null, 0, false, false); utils.when(() -> Fabric8Utils.getApplicationNamespace(Mockito.any(KubernetesClient.class), Mockito.nullable(String.class), Mockito.anyString(), Mockito.any(KubernetesNamespaceProvider.class))) - .thenReturn("namespaceA"); + .thenReturn("namespaceA"); service("namespaceA", "serviceA", Map.of("color", "red")); service("namespaceB", "serviceB", Map.of("color", "blue")); - List result = adapter.apply(client); + List result = services(properties, client, NAMESPACE_PROVIDER, + new KubernetesDiscoveryClient(null, properties, null, null, null).filter(), null, "dummy-target"); Assertions.assertEquals(result.size(), 1); Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); @@ -272,26 +251,20 @@ void testSpecificNamespaceWithoutLabelsWithoutFilter() { void testSpecificNamespaceWithLabelsWithoutFilter() { boolean allNamespaces = false; Map labels = Map.of("color", "purple"); - String spelFilter = null; - - MockEnvironment environment = new MockEnvironment(); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), - true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); - - Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( - new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, - null); + true, 60L, false, null, Set.of(), labels, null, null, 0, false, false); utils.when(() -> Fabric8Utils.getApplicationNamespace(Mockito.any(KubernetesClient.class), Mockito.nullable(String.class), Mockito.anyString(), Mockito.any(KubernetesNamespaceProvider.class))) - .thenReturn("namespaceA"); + .thenReturn("namespaceA"); service("namespaceA", "serviceA", Map.of("color", "red")); service("namespaceA", "serviceB", Map.of("color", "purple")); service("namespaceC", "serviceC", Map.of("color", "purple")); - List result = adapter.apply(client); + List result = services(properties, client, NAMESPACE_PROVIDER, + new KubernetesDiscoveryClient(null, properties, null, null, null).filter(), null, "dummy-target"); Assertions.assertEquals(result.size(), 1); Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceB"); Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); @@ -321,24 +294,19 @@ void testSpecificNamespaceWithoutLabelsWithFilter() { #root.metadata.labels.containsKey("number") """.stripLeading(); - MockEnvironment environment = new MockEnvironment(); - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), - true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); - - Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( - new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, - null); + true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); utils.when(() -> Fabric8Utils.getApplicationNamespace(Mockito.any(KubernetesClient.class), Mockito.nullable(String.class), Mockito.anyString(), Mockito.any(KubernetesNamespaceProvider.class))) - .thenReturn("namespaceA"); + .thenReturn("namespaceA"); service("namespaceA", "serviceA", Map.of("color", "red", "number", "1")); service("namespaceA", "serviceB", Map.of("color", "purple", "cycle", "create")); service("namespaceC", "serviceC", Map.of("color", "purple", "number", "1")); - List result = adapter.apply(client); + List result = services(properties, client, NAMESPACE_PROVIDER, + new KubernetesDiscoveryClient(null, properties, null, null, null).filter(), null, "dummy-target"); Assertions.assertEquals(result.size(), 1); Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); @@ -364,22 +332,16 @@ void testSomeNamespacesWithoutLabelsWithoutFilter() { boolean allNamespaces = false; Set someNamespaces = Set.of("namespaceA", "namespaceB"); Map labels = Map.of(); - String spelFilter = null; - - MockEnvironment environment = new MockEnvironment(); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, - someNamespaces, true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); - - Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( - new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, - null); + someNamespaces, true, 60L, false, null, Set.of(), labels, null, null, 0, false, false); service("namespaceA", "serviceA", Map.of()); service("namespaceB", "serviceB", Map.of()); service("namespaceC", "serviceC", Map.of()); - List result = adapter.apply(client); + List result = services(properties, client, NAMESPACE_PROVIDER, + new KubernetesDiscoveryClient(null, properties, null, null, null).filter(), null, "dummy-target"); Assertions.assertEquals(result.size(), 2); result = result.stream().sorted(Comparator.comparing(x -> x.getMetadata().getName())).toList(); Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); @@ -409,20 +371,15 @@ void testSomeNamespacesWithLabelsWithoutFilter() { Map labels = Map.of("color", "purple"); String spelFilter = null; - MockEnvironment environment = new MockEnvironment(); - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, - someNamespaces, true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); - - Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( - new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, - null); + someNamespaces, true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); service("namespaceA", "serviceA", Map.of("color", "purple")); service("namespaceB", "serviceB", Map.of("color", "red")); service("namespaceC", "serviceC", Map.of("color", "purple")); - List result = adapter.apply(client); + List result = services(properties, client, NAMESPACE_PROVIDER, + new KubernetesDiscoveryClient(null, properties, null, null, null).filter(), null, "dummy-target"); Assertions.assertEquals(result.size(), 1); Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); @@ -451,20 +408,15 @@ void testSomeNamespacesWithLabelsWithFilter() { #root.metadata.labels.containsKey("number") """.stripLeading(); - MockEnvironment environment = new MockEnvironment(); - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, - someNamespaces, true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); - - Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( - new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, - null); + someNamespaces, true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); service("namespaceA", "serviceA", Map.of("color", "purple", "number", "1")); service("namespaceB", "serviceB", Map.of("color", "purple", "cycle", "create")); service("namespaceC", "serviceC", Map.of("color", "purple", "number", "1")); - List result = adapter.apply(client); + List result = services(properties, client, NAMESPACE_PROVIDER, + new KubernetesDiscoveryClient(null, properties, null, null, null).filter(), null, "dummy-target"); Assertions.assertEquals(result.size(), 1); Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); @@ -472,8 +424,14 @@ void testSomeNamespacesWithLabelsWithFilter() { private void service(String namespace, String name, Map labels) { client.services().inNamespace(namespace) - .resource(new ServiceBuilder().withNewMetadata().withName(name).withLabels(labels).and().build()) - .create(); + .resource(new ServiceBuilder().withNewMetadata().withName(name).withLabels(labels).and().build()) + .create(); + } + + private static Environment mockEnvironment() { + MockEnvironment environment = new MockEnvironment(); + environment.setProperty("spring.cloud.kubernetes.client.namespace", "test"); + return environment; } } From 1c81d6ae5441be2efbe5d5f78d1aa47ac2a17fd8 Mon Sep 17 00:00:00 2001 From: wind57 Date: Mon, 27 Feb 2023 14:07:33 +0200 Subject: [PATCH 032/151] start work --- .../KubernetesClientServicesFunction.java | 2 +- .../discovery/KubernetesDiscoveryClient.java | 14 ++--- .../Fabric8DiscoveryFilterTests.java | 52 ++++++++-------- .../KubernetesDiscoveryClientFilterTest.java | 59 ++++++++++++++----- 4 files changed, 77 insertions(+), 50 deletions(-) diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesClientServicesFunction.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesClientServicesFunction.java index 8d2fb66e49..b8fc29670a 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesClientServicesFunction.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesClientServicesFunction.java @@ -40,7 +40,7 @@ * * See KubernetesDiscoveryClientAutoConfiguration.servicesFunction * - * @deprecated this is not used internally anymore and will be removed in a future release. + * This is not used internally anymore and will be removed in a future release. * * @author Georgios Andrianakis */ diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java index 26826c35f1..ef4f7409bc 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java @@ -59,7 +59,7 @@ public class KubernetesDiscoveryClient implements DiscoveryClient, EnvironmentAw private static final SpelExpressionParser PARSER = new SpelExpressionParser(); private static final SimpleEvaluationContext EVALUATION_CONTEXT = SimpleEvaluationContext.forReadOnlyDataBinding() - .withInstanceMethods().build(); + .withInstanceMethods().build(); private static final LogAccessor LOG = new LogAccessor(LogFactory.getLog(KubernetesDiscoveryClient.class)); @@ -113,10 +113,6 @@ public List getInstances(String serviceId) { instances.addAll(getNamespaceServiceInstances(es, serviceId)); } - if (properties.includeExternalNameServices()) { - LOG.debug(() -> "will search for 'ExternalName' type of services"); - } - return instances; } @@ -153,14 +149,14 @@ private List getNamespaceServiceInstances(EndpointSubsetNS es, @Override public List getServices() { - return services(properties, client, namespaceProvider, filter(), null, "fabric8-discovery") - .stream().map(s -> s.getMetadata().getName()).toList(); + return services(properties, client, namespaceProvider, filter(), null, "fabric8-discovery").stream() + .map(s -> s.getMetadata().getName()).toList(); } @Deprecated(forRemoval = true) public List getServices(Predicate filter) { - return services(properties, client, namespaceProvider, filter, null, "fabric8-discovery") - .stream().map(s -> s.getMetadata().getName()).toList(); + return services(properties, client, namespaceProvider, filter, null, "fabric8-discovery").stream() + .map(s -> s.getMetadata().getName()).toList(); } @Override diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryFilterTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryFilterTests.java index 15ed933efe..b4a8f26e39 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryFilterTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryFilterTests.java @@ -47,7 +47,7 @@ class Fabric8DiscoveryFilterTests { private static final KubernetesNamespaceProvider NAMESPACE_PROVIDER = new KubernetesNamespaceProvider( - mockEnvironment()); + mockEnvironment()); private static KubernetesClient client; @@ -82,13 +82,13 @@ void testAllNamespacesWithoutLabelsWithoutFilter() { Map labels = Map.of(); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), - true, 60L, false, null, Set.of(), labels, null, null, 0, false, false); + true, 60L, false, null, Set.of(), labels, null, null, 0, false, false); service("namespaceA", "serviceA", Map.of("color", "red")); service("namespaceB", "serviceB", Map.of("color", "blue")); List result = services(properties, client, NAMESPACE_PROVIDER, - new KubernetesDiscoveryClient(null, properties, null, null, null).filter(), null, "dummy-target"); + new KubernetesDiscoveryClient(null, properties, null, null, null).filter(), null, "dummy-target"); Assertions.assertEquals(result.size(), 2); Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); @@ -115,13 +115,13 @@ void testAllNamespacesWithLabelsWithoutFilter() { Map labels = Map.of("color", "red"); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), - true, 60L, false, null, Set.of(), labels, null, null, 0, false, false); + true, 60L, false, null, Set.of(), labels, null, null, 0, false, false); service("namespaceA", "serviceA", Map.of("color", "red")); service("namespaceB", "serviceB", Map.of("color", "blue")); List result = services(properties, client, NAMESPACE_PROVIDER, - new KubernetesDiscoveryClient(null, properties, null, null, null).filter(), null, "dummy-target"); + new KubernetesDiscoveryClient(null, properties, null, null, null).filter(), null, "dummy-target"); Assertions.assertEquals(result.size(), 1); Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); @@ -149,13 +149,13 @@ void testAllNamespacesWithoutLabelsWithNamespaceFilter() { """; KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), - true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); + true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); service("namespaceA", "serviceA", Map.of("color", "red")); service("namespaceB", "serviceB", Map.of("color", "blue")); List result = services(properties, client, NAMESPACE_PROVIDER, - new KubernetesDiscoveryClient(null, properties, null, null, null).filter(), null, "dummy-target"); + new KubernetesDiscoveryClient(null, properties, null, null, null).filter(), null, "dummy-target"); Assertions.assertEquals(result.size(), 1); Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); @@ -184,14 +184,14 @@ void testAllNamespacesWithoutLabelsWithNamespacesFilter() { """; KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), - true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); + true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); service("namespaceA", "serviceA", Map.of("color", "red")); service("namespaceB", "serviceB", Map.of("color", "blue")); service("namespaceC", "serviceC", Map.of("color", "purple")); List result = services(properties, client, NAMESPACE_PROVIDER, - new KubernetesDiscoveryClient(null, properties, null, null, null).filter(), null, "dummy-target"); + new KubernetesDiscoveryClient(null, properties, null, null, null).filter(), null, "dummy-target"); Assertions.assertEquals(result.size(), 2); Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); @@ -217,17 +217,17 @@ void testSpecificNamespaceWithoutLabelsWithoutFilter() { Map labels = Map.of(); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), - true, 60L, false, null, Set.of(), labels, null, null, 0, false, false); + true, 60L, false, null, Set.of(), labels, null, null, 0, false, false); utils.when(() -> Fabric8Utils.getApplicationNamespace(Mockito.any(KubernetesClient.class), Mockito.nullable(String.class), Mockito.anyString(), Mockito.any(KubernetesNamespaceProvider.class))) - .thenReturn("namespaceA"); + .thenReturn("namespaceA"); service("namespaceA", "serviceA", Map.of("color", "red")); service("namespaceB", "serviceB", Map.of("color", "blue")); List result = services(properties, client, NAMESPACE_PROVIDER, - new KubernetesDiscoveryClient(null, properties, null, null, null).filter(), null, "dummy-target"); + new KubernetesDiscoveryClient(null, properties, null, null, null).filter(), null, "dummy-target"); Assertions.assertEquals(result.size(), 1); Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); @@ -253,18 +253,18 @@ void testSpecificNamespaceWithLabelsWithoutFilter() { Map labels = Map.of("color", "purple"); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), - true, 60L, false, null, Set.of(), labels, null, null, 0, false, false); + true, 60L, false, null, Set.of(), labels, null, null, 0, false, false); utils.when(() -> Fabric8Utils.getApplicationNamespace(Mockito.any(KubernetesClient.class), Mockito.nullable(String.class), Mockito.anyString(), Mockito.any(KubernetesNamespaceProvider.class))) - .thenReturn("namespaceA"); + .thenReturn("namespaceA"); service("namespaceA", "serviceA", Map.of("color", "red")); service("namespaceA", "serviceB", Map.of("color", "purple")); service("namespaceC", "serviceC", Map.of("color", "purple")); List result = services(properties, client, NAMESPACE_PROVIDER, - new KubernetesDiscoveryClient(null, properties, null, null, null).filter(), null, "dummy-target"); + new KubernetesDiscoveryClient(null, properties, null, null, null).filter(), null, "dummy-target"); Assertions.assertEquals(result.size(), 1); Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceB"); Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); @@ -295,18 +295,18 @@ void testSpecificNamespaceWithoutLabelsWithFilter() { """.stripLeading(); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), - true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); + true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); utils.when(() -> Fabric8Utils.getApplicationNamespace(Mockito.any(KubernetesClient.class), Mockito.nullable(String.class), Mockito.anyString(), Mockito.any(KubernetesNamespaceProvider.class))) - .thenReturn("namespaceA"); + .thenReturn("namespaceA"); service("namespaceA", "serviceA", Map.of("color", "red", "number", "1")); service("namespaceA", "serviceB", Map.of("color", "purple", "cycle", "create")); service("namespaceC", "serviceC", Map.of("color", "purple", "number", "1")); List result = services(properties, client, NAMESPACE_PROVIDER, - new KubernetesDiscoveryClient(null, properties, null, null, null).filter(), null, "dummy-target"); + new KubernetesDiscoveryClient(null, properties, null, null, null).filter(), null, "dummy-target"); Assertions.assertEquals(result.size(), 1); Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); @@ -334,14 +334,14 @@ void testSomeNamespacesWithoutLabelsWithoutFilter() { Map labels = Map.of(); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, - someNamespaces, true, 60L, false, null, Set.of(), labels, null, null, 0, false, false); + someNamespaces, true, 60L, false, null, Set.of(), labels, null, null, 0, false, false); service("namespaceA", "serviceA", Map.of()); service("namespaceB", "serviceB", Map.of()); service("namespaceC", "serviceC", Map.of()); List result = services(properties, client, NAMESPACE_PROVIDER, - new KubernetesDiscoveryClient(null, properties, null, null, null).filter(), null, "dummy-target"); + new KubernetesDiscoveryClient(null, properties, null, null, null).filter(), null, "dummy-target"); Assertions.assertEquals(result.size(), 2); result = result.stream().sorted(Comparator.comparing(x -> x.getMetadata().getName())).toList(); Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); @@ -372,14 +372,14 @@ void testSomeNamespacesWithLabelsWithoutFilter() { String spelFilter = null; KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, - someNamespaces, true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); + someNamespaces, true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); service("namespaceA", "serviceA", Map.of("color", "purple")); service("namespaceB", "serviceB", Map.of("color", "red")); service("namespaceC", "serviceC", Map.of("color", "purple")); List result = services(properties, client, NAMESPACE_PROVIDER, - new KubernetesDiscoveryClient(null, properties, null, null, null).filter(), null, "dummy-target"); + new KubernetesDiscoveryClient(null, properties, null, null, null).filter(), null, "dummy-target"); Assertions.assertEquals(result.size(), 1); Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); @@ -409,14 +409,14 @@ void testSomeNamespacesWithLabelsWithFilter() { """.stripLeading(); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, - someNamespaces, true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); + someNamespaces, true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); service("namespaceA", "serviceA", Map.of("color", "purple", "number", "1")); service("namespaceB", "serviceB", Map.of("color", "purple", "cycle", "create")); service("namespaceC", "serviceC", Map.of("color", "purple", "number", "1")); List result = services(properties, client, NAMESPACE_PROVIDER, - new KubernetesDiscoveryClient(null, properties, null, null, null).filter(), null, "dummy-target"); + new KubernetesDiscoveryClient(null, properties, null, null, null).filter(), null, "dummy-target"); Assertions.assertEquals(result.size(), 1); Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); @@ -424,8 +424,8 @@ void testSomeNamespacesWithLabelsWithFilter() { private void service(String namespace, String name, Map labels) { client.services().inNamespace(namespace) - .resource(new ServiceBuilder().withNewMetadata().withName(name).withLabels(labels).and().build()) - .create(); + .resource(new ServiceBuilder().withNewMetadata().withName(name).withLabels(labels).and().build()) + .create(); } private static Environment mockEnvironment() { diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientFilterTest.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientFilterTest.java index d4d5111bef..6188f0c2f4 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientFilterTest.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientFilterTest.java @@ -26,25 +26,34 @@ import io.fabric8.kubernetes.api.model.Service; import io.fabric8.kubernetes.api.model.ServiceList; import io.fabric8.kubernetes.client.KubernetesClient; +import io.fabric8.kubernetes.client.dsl.FilterNested; +import io.fabric8.kubernetes.client.dsl.FilterWatchListDeletable; import io.fabric8.kubernetes.client.dsl.MixedOperation; import io.fabric8.kubernetes.client.dsl.ServiceResource; import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; +import org.springframework.core.env.Environment; +import org.springframework.mock.env.MockEnvironment; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.when; +@SuppressWarnings("unchecked") class KubernetesDiscoveryClientFilterTest { private final KubernetesClient kubernetesClient = Mockito.mock(KubernetesClient.class); - private final KubernetesClientServicesFunction kubernetesClientServicesFunction = KubernetesClient::services; - private final MixedOperation> serviceOperation = Mockito .mock(MixedOperation.class); + private final FilterNested>> filterNested = Mockito + .mock(FilterNested.class); + + private final FilterWatchListDeletable> filter = Mockito + .mock(FilterWatchListDeletable.class); + @Test void testFilteredServices() { List springBootServiceNames = Arrays.asList("serviceA", "serviceB"); @@ -59,14 +68,20 @@ void testFilteredServices() { ServiceList serviceList = new ServiceList(); serviceList.setItems(services); - when(this.serviceOperation.list()).thenReturn(serviceList); - when(this.kubernetesClient.services()).thenReturn(this.serviceOperation); + when(kubernetesClient.services()).thenReturn(serviceOperation); + when(serviceOperation.inNamespace(Mockito.anyString())).thenReturn(serviceOperation); + when(serviceOperation.withNewFilter()).thenReturn(filterNested); + when(filterNested.withLabels(Mockito.anyMap())).thenReturn(filterNested); + when(filterNested.endFilter()).thenReturn(filter); + when(filter.list()).thenReturn(serviceList); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, false, "metadata.additionalProperties['spring-boot']", Set.of(), Map.of(), null, KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, true, false); - KubernetesDiscoveryClient client = new KubernetesDiscoveryClient(this.kubernetesClient, properties, - this.kubernetesClientServicesFunction); + + KubernetesDiscoveryClient client = new KubernetesDiscoveryClient(kubernetesClient, properties, null, null, + null); + client.setEnvironment(mockEnvironment()); List filteredServices = client.getServices(); assertThat(filteredServices).isEqualTo(springBootServiceNames); @@ -87,14 +102,19 @@ void testFilteredServicesByPrefix() { ServiceList serviceList = new ServiceList(); serviceList.setItems(services); - when(this.serviceOperation.list()).thenReturn(serviceList); - when(this.kubernetesClient.services()).thenReturn(this.serviceOperation); + when(kubernetesClient.services()).thenReturn(serviceOperation); + when(serviceOperation.inNamespace(Mockito.anyString())).thenReturn(serviceOperation); + when(serviceOperation.withNewFilter()).thenReturn(filterNested); + when(filterNested.withLabels(Mockito.anyMap())).thenReturn(filterNested); + when(filterNested.endFilter()).thenReturn(filter); + when(filter.list()).thenReturn(serviceList); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, false, "metadata.name.startsWith('service')", Set.of(), Map.of(), null, KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, true, false); - KubernetesDiscoveryClient client = new KubernetesDiscoveryClient(this.kubernetesClient, properties, - this.kubernetesClientServicesFunction); + KubernetesDiscoveryClient client = new KubernetesDiscoveryClient(kubernetesClient, properties, null, null, + null); + client.setEnvironment(mockEnvironment()); List filteredServices = client.getServices(); assertThat(filteredServices).isEqualTo(springBootServiceNames); @@ -108,13 +128,18 @@ void testNoExpression() { ServiceList serviceList = new ServiceList(); serviceList.setItems(services); - when(this.serviceOperation.list()).thenReturn(serviceList); - when(this.kubernetesClient.services()).thenReturn(this.serviceOperation); + when(kubernetesClient.services()).thenReturn(serviceOperation); + when(serviceOperation.inNamespace(Mockito.anyString())).thenReturn(serviceOperation); + when(serviceOperation.withNewFilter()).thenReturn(filterNested); + when(filterNested.withLabels(Mockito.anyMap())).thenReturn(filterNested); + when(filterNested.endFilter()).thenReturn(filter); + when(filter.list()).thenReturn(serviceList); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, false, "", Set.of(), Map.of(), null, KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, true, false); - KubernetesDiscoveryClient client = new KubernetesDiscoveryClient(this.kubernetesClient, properties, - this.kubernetesClientServicesFunction); + KubernetesDiscoveryClient client = new KubernetesDiscoveryClient(kubernetesClient, properties, null, null, + null); + client.setEnvironment(mockEnvironment()); List filteredServices = client.getServices(); @@ -135,4 +160,10 @@ private List createSpringBootServiceByName(List serviceNames) { return serviceCollection; } + private static Environment mockEnvironment() { + MockEnvironment environment = new MockEnvironment(); + environment.setProperty("spring.cloud.kubernetes.client.namespace", "test"); + return environment; + } + } From c000e7e0de40f320bdbec36f118275beb836afe1 Mon Sep 17 00:00:00 2001 From: wind57 Date: Mon, 27 Feb 2023 14:23:32 +0200 Subject: [PATCH 033/151] fix tests --- .../discovery/KubernetesDiscoveryClientUtilsTests.java | 10 +++++----- .../KubernetesInformerDiscoveryClientTests.java | 4 ++-- ...esClientCatalogWatchEndpointSlicesSupportTests.java | 8 ++++---- .../KubernetesEndpointsAndEndpointSlicesTests.java | 6 +++--- ...KubernetesInformerReactiveDiscoveryClientTests.java | 4 ++-- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/spring-cloud-kubernetes-client-discovery/src/test/java/org/springframework/cloud/kubernetes/client/discovery/KubernetesDiscoveryClientUtilsTests.java b/spring-cloud-kubernetes-client-discovery/src/test/java/org/springframework/cloud/kubernetes/client/discovery/KubernetesDiscoveryClientUtilsTests.java index 4f3551e628..e360e20287 100644 --- a/spring-cloud-kubernetes-client-discovery/src/test/java/org/springframework/cloud/kubernetes/client/discovery/KubernetesDiscoveryClientUtilsTests.java +++ b/spring-cloud-kubernetes-client-discovery/src/test/java/org/springframework/cloud/kubernetes/client/discovery/KubernetesDiscoveryClientUtilsTests.java @@ -61,7 +61,7 @@ void testEmptyServiceLabelsFromProperties(CapturedOutput output) { void testEmptyServiceLabelsFromService(CapturedOutput output) { Map propertiesLabels = Map.of("key", "value"); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - true, "", Set.of(), propertiesLabels, "", null, 0, false); + true, "", Set.of(), propertiesLabels, "", null, 0, false, false); V1Service service = new V1ServiceBuilder().withMetadata(new V1ObjectMeta().name("my-service")).build(); boolean result = matchesServiceLabels(service, properties); @@ -82,7 +82,7 @@ void testOne(CapturedOutput output) { Map propertiesLabels = Map.of("a", "b"); Map serviceLabels = Map.of("a", "b"); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - true, "", Set.of(), propertiesLabels, "", null, 0, false); + true, "", Set.of(), propertiesLabels, "", null, 0, false, false); V1Service service = new V1ServiceBuilder() .withMetadata(new V1ObjectMeta().labels(serviceLabels).name("my-service")).build(); @@ -105,7 +105,7 @@ void testTwo(CapturedOutput output) { Map propertiesLabels = ordered(Map.of("a", "b", "c", "d")); Map serviceLabels = Map.of("a", "b"); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - true, "", Set.of(), propertiesLabels, "", null, 0, false); + true, "", Set.of(), propertiesLabels, "", null, 0, false, false); V1Service service = new V1ServiceBuilder() .withMetadata(new V1ObjectMeta().labels(serviceLabels).name("my-service")).build(); @@ -128,7 +128,7 @@ void testThree(CapturedOutput output) { Map propertiesLabels = ordered(Map.of("a", "b", "c", "d")); Map serviceLabels = ordered(Map.of("a", "b", "c", "d")); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - true, "", Set.of(), propertiesLabels, "", null, 0, false); + true, "", Set.of(), propertiesLabels, "", null, 0, false, false); V1Service service = new V1ServiceBuilder() .withMetadata(new V1ObjectMeta().labels(serviceLabels).name("my-service")).build(); @@ -151,7 +151,7 @@ void testFour(CapturedOutput output) { Map propertiesLabels = Map.of("a", "b"); Map serviceLabels = ordered(Map.of("a", "b", "c", "d")); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - true, "", Set.of(), propertiesLabels, "", null, 0, false); + true, "", Set.of(), propertiesLabels, "", null, 0, false, false); V1Service service = new V1ServiceBuilder() .withMetadata(new V1ObjectMeta().labels(serviceLabels).name("my-service")).build(); diff --git a/spring-cloud-kubernetes-client-discovery/src/test/java/org/springframework/cloud/kubernetes/client/discovery/KubernetesInformerDiscoveryClientTests.java b/spring-cloud-kubernetes-client-discovery/src/test/java/org/springframework/cloud/kubernetes/client/discovery/KubernetesInformerDiscoveryClientTests.java index 721dad408e..a6a12f83c2 100644 --- a/spring-cloud-kubernetes-client-discovery/src/test/java/org/springframework/cloud/kubernetes/client/discovery/KubernetesInformerDiscoveryClientTests.java +++ b/spring-cloud-kubernetes-client-discovery/src/test/java/org/springframework/cloud/kubernetes/client/discovery/KubernetesInformerDiscoveryClientTests.java @@ -209,7 +209,7 @@ void testDiscoveryGetInstanceWithNotReadyAddressesIncludedShouldWork() { Lister endpointsLister = setupEndpointsLister(ENDPOINTS_NOT_READY_ADDRESS); KubernetesDiscoveryProperties kubernetesDiscoveryProperties = new KubernetesDiscoveryProperties(true, false, - Set.of(), true, 60, true, null, Set.of(), Map.of(), null, null, 0, true); + Set.of(), true, 60, true, null, Set.of(), Map.of(), null, null, 0, true, false); KubernetesInformerDiscoveryClient discoveryClient = new KubernetesInformerDiscoveryClient("namespace1", SHARED_INFORMER_FACTORY, serviceLister, endpointsLister, null, null, kubernetesDiscoveryProperties); @@ -414,7 +414,7 @@ private static V1Endpoints endpointsMultiplePortsWithoutSupportedPortNames() { private static KubernetesDiscoveryProperties properties(boolean allNamespaces, Map labels) { return new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), true, 60, false, null, Set.of(), - labels, null, KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, true); + labels, null, KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, true, false); } } diff --git a/spring-cloud-kubernetes-client-discovery/src/test/java/org/springframework/cloud/kubernetes/client/discovery/catalog/KubernetesClientCatalogWatchEndpointSlicesSupportTests.java b/spring-cloud-kubernetes-client-discovery/src/test/java/org/springframework/cloud/kubernetes/client/discovery/catalog/KubernetesClientCatalogWatchEndpointSlicesSupportTests.java index 29d822f0fa..2629fe7005 100644 --- a/spring-cloud-kubernetes-client-discovery/src/test/java/org/springframework/cloud/kubernetes/client/discovery/catalog/KubernetesClientCatalogWatchEndpointSlicesSupportTests.java +++ b/spring-cloud-kubernetes-client-discovery/src/test/java/org/springframework/cloud/kubernetes/client/discovery/catalog/KubernetesClientCatalogWatchEndpointSlicesSupportTests.java @@ -88,7 +88,7 @@ public void afterEach() { void testEndpointSlicesEnabledButNotSupported() { boolean useEndpointSlices = true; KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, - false, "", Set.of(), Map.of(), "", null, 0, useEndpointSlices); + false, "", Set.of(), Map.of(), "", null, 0, useEndpointSlices, false); V1APIResourceList list = new V1APIResourceListBuilder().addToResources(new V1APIResource()).build(); stubFor(get("/apis/discovery.k8s.io/v1") @@ -110,7 +110,7 @@ void testEndpointSlicesEnabledButNotSupported() { void testEndpointSlicesEnabledButNotSupportedViaApiVersions() { boolean useEndpointSlices = true; KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, - false, "", Set.of(), Map.of(), "", null, 0, useEndpointSlices); + false, "", Set.of(), Map.of(), "", null, 0, useEndpointSlices, false); V1APIResourceList list = new V1APIResourceListBuilder() .addToResources(new V1APIResourceBuilder().withName("not-the-one").build()).build(); @@ -130,7 +130,7 @@ void testEndpointSlicesEnabledButNotSupportedViaApiVersions() { void testEndpointsSupport() { boolean useEndpointSlices = false; KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, - false, "", Set.of(), Map.of(), "", null, 0, useEndpointSlices); + false, "", Set.of(), Map.of(), "", null, 0, useEndpointSlices, false); KubernetesCatalogWatch watch = new KubernetesCatalogWatch(null, apiClient, properties, NAMESPACE_PROVIDER); Assertions.assertEquals(KubernetesEndpointsCatalogWatch.class, watch.stateGenerator().getClass()); @@ -144,7 +144,7 @@ void testEndpointsSupport() { void testEndpointSlicesSupport() { boolean useEndpointSlices = true; KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, - false, "", Set.of(), Map.of(), "", null, 0, useEndpointSlices); + false, "", Set.of(), Map.of(), "", null, 0, useEndpointSlices, false); V1APIResourceList list = new V1APIResourceListBuilder() .addToResources(new V1APIResourceBuilder().withName("endpointslices").withKind(ENDPOINT_SLICE).build()) diff --git a/spring-cloud-kubernetes-client-discovery/src/test/java/org/springframework/cloud/kubernetes/client/discovery/catalog/KubernetesEndpointsAndEndpointSlicesTests.java b/spring-cloud-kubernetes-client-discovery/src/test/java/org/springframework/cloud/kubernetes/client/discovery/catalog/KubernetesEndpointsAndEndpointSlicesTests.java index 1f8688e499..3fb392598b 100644 --- a/spring-cloud-kubernetes-client-discovery/src/test/java/org/springframework/cloud/kubernetes/client/discovery/catalog/KubernetesEndpointsAndEndpointSlicesTests.java +++ b/spring-cloud-kubernetes-client-discovery/src/test/java/org/springframework/cloud/kubernetes/client/discovery/catalog/KubernetesEndpointsAndEndpointSlicesTests.java @@ -109,7 +109,7 @@ KubernetesCatalogWatch createWatcherInAllNamespacesWithLabels(Map n boolean allNamespaces = false; KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, - true, 60, false, "", Set.of(), labels, "", null, 0, false); + true, 60, false, "", Set.of(), labels, "", null, 0, false, false); KubernetesCatalogWatch watch = new KubernetesCatalogWatch(coreV1Api, apiClient, properties, NAMESPACE_PROVIDER); if (endpointSlices) { @@ -149,7 +149,7 @@ KubernetesCatalogWatch createWatcherInSpecificNamespaceWithLabels(String namespa boolean allNamespaces = false; KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, Set.of(), - true, 60, false, "", Set.of(), labels, "", null, 0, endpointSlices); + true, 60, false, "", Set.of(), labels, "", null, 0, endpointSlices, false); KubernetesCatalogWatch watch = new KubernetesCatalogWatch(coreV1Api, apiClient, properties, NAMESPACE_PROVIDER); if (endpointSlices) { diff --git a/spring-cloud-kubernetes-client-discovery/src/test/java/org/springframework/cloud/kubernetes/client/discovery/reactive/KubernetesInformerReactiveDiscoveryClientTests.java b/spring-cloud-kubernetes-client-discovery/src/test/java/org/springframework/cloud/kubernetes/client/discovery/reactive/KubernetesInformerReactiveDiscoveryClientTests.java index 4f6a98ef50..c0ce7b2725 100644 --- a/spring-cloud-kubernetes-client-discovery/src/test/java/org/springframework/cloud/kubernetes/client/discovery/reactive/KubernetesInformerReactiveDiscoveryClientTests.java +++ b/spring-cloud-kubernetes-client-discovery/src/test/java/org/springframework/cloud/kubernetes/client/discovery/reactive/KubernetesInformerReactiveDiscoveryClientTests.java @@ -102,7 +102,7 @@ public void testDiscoveryGetInstanceAllNamespaceShouldWork() { Lister endpointsLister = setupEndpointsLister(testEndpoints1); KubernetesDiscoveryProperties kubernetesDiscoveryProperties = new KubernetesDiscoveryProperties(true, true, - Set.of(), true, 60, false, null, Set.of(), Map.of(), null, null, 0, false); + Set.of(), true, 60, false, null, Set.of(), Map.of(), null, null, 0, false, false); KubernetesInformerReactiveDiscoveryClient discoveryClient = new KubernetesInformerReactiveDiscoveryClient( new KubernetesNamespaceProvider(new MockEnvironment()), sharedInformerFactory, serviceLister, @@ -121,7 +121,7 @@ public void testDiscoveryGetInstanceOneNamespaceShouldWork() { Lister endpointsLister = setupEndpointsLister(testEndpoints1); KubernetesDiscoveryProperties kubernetesDiscoveryProperties = new KubernetesDiscoveryProperties(true, false, - Set.of(), true, 60, false, null, Set.of(), Map.of(), null, null, 0, false); + Set.of(), true, 60, false, null, Set.of(), Map.of(), null, null, 0, false, false); KubernetesNamespaceProvider kubernetesNamespaceProvider = mock(KubernetesNamespaceProvider.class); when(kubernetesNamespaceProvider.getNamespace()).thenReturn("namespace1"); From f27c0a19c6264f622972c39e3b833c1f2b638f19 Mon Sep 17 00:00:00 2001 From: wind57 Date: Mon, 27 Feb 2023 14:30:09 +0200 Subject: [PATCH 034/151] fix tests --- .../loadbalancer/KubernetesClientServicesListSupplierTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-cloud-kubernetes-client-loadbalancer/src/test/java/org/springframework/cloud/kubernetes/client/loadbalancer/KubernetesClientServicesListSupplierTests.java b/spring-cloud-kubernetes-client-loadbalancer/src/test/java/org/springframework/cloud/kubernetes/client/loadbalancer/KubernetesClientServicesListSupplierTests.java index b27e1386d2..12a428e1a3 100644 --- a/spring-cloud-kubernetes-client-loadbalancer/src/test/java/org/springframework/cloud/kubernetes/client/loadbalancer/KubernetesClientServicesListSupplierTests.java +++ b/spring-cloud-kubernetes-client-loadbalancer/src/test/java/org/springframework/cloud/kubernetes/client/loadbalancer/KubernetesClientServicesListSupplierTests.java @@ -147,7 +147,7 @@ void getListAllNamespaces() { when(kubernetesNamespaceProvider.getNamespace()).thenReturn("default"); KubernetesDiscoveryProperties kubernetesDiscoveryProperties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, false, null, Set.of(), Map.of(), null, - KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, false); + KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, false, false); CoreV1Api coreV1Api = new CoreV1Api(); KubernetesClientServiceInstanceMapper mapper = new KubernetesClientServiceInstanceMapper( new KubernetesLoadBalancerProperties(), kubernetesDiscoveryProperties); From a09cf9446e36eccea2125852b2afa152f114abb9 Mon Sep 17 00:00:00 2001 From: wind57 Date: Mon, 27 Feb 2023 15:01:18 +0200 Subject: [PATCH 035/151] dirty --- .../Fabric8DiscoveryServicesAdapter.java | 92 ++++ .../KubernetesClientServicesFunction.java | 3 - .../discovery/KubernetesDiscoveryClient.java | 44 +- .../Fabric8DiscoveryFilterTests.java | 437 ------------------ 4 files changed, 106 insertions(+), 470 deletions(-) create mode 100644 spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryServicesAdapter.java delete mode 100644 spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryFilterTests.java diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryServicesAdapter.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryServicesAdapter.java new file mode 100644 index 0000000000..e3e20eebe9 --- /dev/null +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryServicesAdapter.java @@ -0,0 +1,92 @@ +/* + * Copyright 2012-2022 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.discovery; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.function.Function; +import java.util.function.Predicate; + +import io.fabric8.kubernetes.api.model.Service; +import io.fabric8.kubernetes.client.KubernetesClient; + +import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; +import org.springframework.expression.Expression; +import org.springframework.expression.spel.standard.SpelExpressionParser; +import org.springframework.expression.spel.support.SimpleEvaluationContext; + +/** + * Adapts a {@link KubernetesClientServicesFunction} to a Function that takes a + * KubernetesClient as input and returns a List of Services(s), plus adds functionality + * not supported by it. + * + * @author wind57 + */ +final class Fabric8DiscoveryServicesAdapter implements Function> { + + private static final SpelExpressionParser PARSER = new SpelExpressionParser(); + + private static final SimpleEvaluationContext EVALUATION_CONTEXT = SimpleEvaluationContext.forReadOnlyDataBinding() + .withInstanceMethods().build(); + + private final KubernetesClientServicesFunction function; + + private final KubernetesDiscoveryProperties properties; + + private final Predicate filter; + + Fabric8DiscoveryServicesAdapter(KubernetesClientServicesFunction function, KubernetesDiscoveryProperties properties, + Predicate filter) { + this.function = function; + this.properties = properties; + if (filter == null) { + this.filter = filter(); + } + else { + this.filter = filter; + } + } + + @Override + public List apply(KubernetesClient client) { + if (!properties.namespaces().isEmpty()) { + List services = new ArrayList<>(); + properties.namespaces().forEach(namespace -> services.addAll(client.services().inNamespace(namespace) + .withLabels(properties.serviceLabels()).list().getItems().stream().filter(filter).toList())); + return services; + } + return function.apply(client).list().getItems().stream().filter(filter).toList(); + } + + Predicate filter() { + String spelExpression = properties.filter(); + Predicate predicate; + if (spelExpression == null || spelExpression.isEmpty()) { + predicate = service -> true; + } + else { + Expression filterExpr = PARSER.parseExpression(spelExpression); + predicate = service -> { + Boolean include = filterExpr.getValue(EVALUATION_CONTEXT, service, Boolean.class); + return Optional.ofNullable(include).orElse(false); + }; + } + return predicate; + } + +} diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesClientServicesFunction.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesClientServicesFunction.java index b8fc29670a..e06aa948df 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesClientServicesFunction.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesClientServicesFunction.java @@ -40,11 +40,8 @@ * * See KubernetesDiscoveryClientAutoConfiguration.servicesFunction * - * This is not used internally anymore and will be removed in a future release. - * * @author Georgios Andrianakis */ -@Deprecated(forRemoval = true) public interface KubernetesClientServicesFunction extends Function>> { diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java index ef4f7409bc..346ea4cd40 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java @@ -20,7 +20,6 @@ import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.Optional; import java.util.function.Predicate; import io.fabric8.kubernetes.api.model.EndpointAddress; @@ -37,16 +36,12 @@ import org.springframework.context.EnvironmentAware; import org.springframework.core.env.Environment; import org.springframework.core.log.LogAccessor; -import org.springframework.expression.Expression; -import org.springframework.expression.spel.standard.SpelExpressionParser; -import org.springframework.expression.spel.support.SimpleEvaluationContext; import static org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientUtils.addresses; import static org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientUtils.endpoints; import static org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientUtils.endpointsPort; import static org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientUtils.serviceInstance; import static org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientUtils.serviceMetadata; -import static org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientUtils.services; /** * Kubernetes implementation of {@link DiscoveryClient}. @@ -56,17 +51,16 @@ */ public class KubernetesDiscoveryClient implements DiscoveryClient, EnvironmentAware { - private static final SpelExpressionParser PARSER = new SpelExpressionParser(); - - private static final SimpleEvaluationContext EVALUATION_CONTEXT = SimpleEvaluationContext.forReadOnlyDataBinding() - .withInstanceMethods().build(); - private static final LogAccessor LOG = new LogAccessor(LogFactory.getLog(KubernetesDiscoveryClient.class)); private final KubernetesDiscoveryProperties properties; + private final KubernetesClientServicesFunction kubernetesClientServicesFunction; + private final ServicePortSecureResolver servicePortSecureResolver; + private final Fabric8DiscoveryServicesAdapter adapter; + private KubernetesClient client; private KubernetesNamespaceProvider namespaceProvider; @@ -86,6 +80,9 @@ public KubernetesDiscoveryClient(KubernetesClient client, this.client = client; this.properties = kubernetesDiscoveryProperties; this.servicePortSecureResolver = servicePortSecureResolver; + this.kubernetesClientServicesFunction = kubernetesClientServicesFunction; + this.adapter = new Fabric8DiscoveryServicesAdapter(kubernetesClientServicesFunction, + kubernetesDiscoveryProperties, filter); } public KubernetesClient getClient() { @@ -113,6 +110,10 @@ public List getInstances(String serviceId) { instances.addAll(getNamespaceServiceInstances(es, serviceId)); } + if (properties.includeExternalNameServices()) { + LOG.debug(() -> "will search for 'ExternalName' type of services"); + } + return instances; } @@ -149,14 +150,13 @@ private List getNamespaceServiceInstances(EndpointSubsetNS es, @Override public List getServices() { - return services(properties, client, namespaceProvider, filter(), null, "fabric8-discovery").stream() - .map(s -> s.getMetadata().getName()).toList(); + return adapter.apply(client).stream().map(s -> s.getMetadata().getName()).toList(); } @Deprecated(forRemoval = true) public List getServices(Predicate filter) { - return services(properties, client, namespaceProvider, filter, null, "fabric8-discovery").stream() - .map(s -> s.getMetadata().getName()).toList(); + return new Fabric8DiscoveryServicesAdapter(kubernetesClientServicesFunction, properties, filter).apply(client) + .stream().map(s -> s.getMetadata().getName()).toList(); } @Override @@ -170,20 +170,4 @@ public final void setEnvironment(Environment environment) { namespaceProvider = new KubernetesNamespaceProvider(environment); } - Predicate filter() { - String spelExpression = properties.filter(); - Predicate predicate; - if (spelExpression == null || spelExpression.isEmpty()) { - predicate = service -> true; - } - else { - Expression filterExpr = PARSER.parseExpression(spelExpression); - predicate = service -> { - Boolean include = filterExpr.getValue(EVALUATION_CONTEXT, service, Boolean.class); - return Optional.ofNullable(include).orElse(false); - }; - } - return predicate; - } - } diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryFilterTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryFilterTests.java deleted file mode 100644 index b4a8f26e39..0000000000 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryFilterTests.java +++ /dev/null @@ -1,437 +0,0 @@ -/* - * Copyright 2012-2022 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.discovery; - -import java.util.Comparator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import io.fabric8.kubernetes.api.model.Service; -import io.fabric8.kubernetes.api.model.ServiceBuilder; -import io.fabric8.kubernetes.client.KubernetesClient; -import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.mockito.MockedStatic; -import org.mockito.Mockito; - -import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider; -import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; -import org.springframework.cloud.kubernetes.fabric8.Fabric8Utils; -import org.springframework.core.env.Environment; -import org.springframework.mock.env.MockEnvironment; - -import static org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientUtils.services; - -/** - * @author wind57 - */ -@EnableKubernetesMockClient(crud = true, https = false) -class Fabric8DiscoveryFilterTests { - - private static final KubernetesNamespaceProvider NAMESPACE_PROVIDER = new KubernetesNamespaceProvider( - mockEnvironment()); - - private static KubernetesClient client; - - private static MockedStatic utils; - - @BeforeEach - void beforeEach() { - utils = Mockito.mockStatic(Fabric8Utils.class); - } - - @AfterEach - void afterEach() { - client.services().inAnyNamespace().delete(); - utils.close(); - } - - /** - *
-	 *     - all-namespaces = true
-	 *     - labels = {}
-	 *     - filter = null
-	 *
-	 *     - serviceA exists in namespaceA with labels = {color=red}
-	 *     - serviceB exists in namespaceB with labels = {color=blue}
-	 *
-	 *     - we get both services as a result.
-	 * 
- */ - @Test - void testAllNamespacesWithoutLabelsWithoutFilter() { - boolean allNamespaces = true; - Map labels = Map.of(); - - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), - true, 60L, false, null, Set.of(), labels, null, null, 0, false, false); - - service("namespaceA", "serviceA", Map.of("color", "red")); - service("namespaceB", "serviceB", Map.of("color", "blue")); - - List result = services(properties, client, NAMESPACE_PROVIDER, - new KubernetesDiscoveryClient(null, properties, null, null, null).filter(), null, "dummy-target"); - - Assertions.assertEquals(result.size(), 2); - Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); - Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); - Assertions.assertEquals(result.get(1).getMetadata().getName(), "serviceB"); - Assertions.assertEquals(result.get(1).getMetadata().getNamespace(), "namespaceB"); - } - - /** - *
-	 *     - all-namespaces = true
-	 *     - labels = {color=red}
-	 *     - filter = null
-	 *
-	 *     - serviceA exists in namespaceA with labels = {color=red}
-	 *     - serviceB exists in namespaceB with labels = {color=blue}
-	 *
-	 *     - we get only serviceA as a result.
-	 * 
- */ - @Test - void testAllNamespacesWithLabelsWithoutFilter() { - boolean allNamespaces = true; - Map labels = Map.of("color", "red"); - - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), - true, 60L, false, null, Set.of(), labels, null, null, 0, false, false); - - service("namespaceA", "serviceA", Map.of("color", "red")); - service("namespaceB", "serviceB", Map.of("color", "blue")); - - List result = services(properties, client, NAMESPACE_PROVIDER, - new KubernetesDiscoveryClient(null, properties, null, null, null).filter(), null, "dummy-target"); - Assertions.assertEquals(result.size(), 1); - Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); - Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); - } - - /** - *
-	 *     - all-namespaces = true
-	 *     - labels = {}
-	 *     - filter = "#root.metadata.namespace matches '^.+A$'"
-	 *       (ends in A)
-	 *
-	 *     - serviceA exists in namespaceA with labels = {color=red}
-	 *     - serviceB exists in namespaceB with labels = {color=blue}
-	 *
-	 *     - we get only serviceA as a result.
-	 * 
- */ - @Test - void testAllNamespacesWithoutLabelsWithNamespaceFilter() { - boolean allNamespaces = true; - Map labels = Map.of(); - String spelFilter = """ - #root.metadata.namespace matches "^.+A$" - """; - - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), - true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); - - service("namespaceA", "serviceA", Map.of("color", "red")); - service("namespaceB", "serviceB", Map.of("color", "blue")); - - List result = services(properties, client, NAMESPACE_PROVIDER, - new KubernetesDiscoveryClient(null, properties, null, null, null).filter(), null, "dummy-target"); - Assertions.assertEquals(result.size(), 1); - Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); - Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); - } - - /** - *
-	 *     - all-namespaces = true
-	 *     - labels = {}
-	 *     - filter = "#root.metadata.namespace matches '^namespace[A|B]$'"
-	 *       (namespaceA or namespaceB)
-	 *
-	 *     - serviceA exists in namespaceA with labels = {color=red}
-	 *     - serviceB exists in namespaceB with labels = {color=blue}
-	 *     - serviceC exists in namespaceC with labels = {color=purple}
-	 *
-	 *     - we get only serviceA and serviceB as a result.
-	 * 
- */ - @Test - void testAllNamespacesWithoutLabelsWithNamespacesFilter() { - boolean allNamespaces = true; - Map labels = Map.of(); - String spelFilter = """ - #root.metadata.namespace matches "^namespace[A|B]$" - """; - - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), - true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); - - service("namespaceA", "serviceA", Map.of("color", "red")); - service("namespaceB", "serviceB", Map.of("color", "blue")); - service("namespaceC", "serviceC", Map.of("color", "purple")); - - List result = services(properties, client, NAMESPACE_PROVIDER, - new KubernetesDiscoveryClient(null, properties, null, null, null).filter(), null, "dummy-target"); - Assertions.assertEquals(result.size(), 2); - Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); - Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); - Assertions.assertEquals(result.get(1).getMetadata().getName(), "serviceB"); - Assertions.assertEquals(result.get(1).getMetadata().getNamespace(), "namespaceB"); - } - - /** - *
-	 *     - all-namespaces = false
-	 *     - specific namespace = namespaceA
-	 *     - labels = {}
-	 *
-	 *     - serviceA exists in namespaceA with labels = {color=red}
-	 *     - serviceB exists in namespaceB with labels = {color=blue}
-	 *
-	 *     - we get only serviceA as a result.
-	 * 
- */ - @Test - void testSpecificNamespaceWithoutLabelsWithoutFilter() { - boolean allNamespaces = false; - Map labels = Map.of(); - - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), - true, 60L, false, null, Set.of(), labels, null, null, 0, false, false); - - utils.when(() -> Fabric8Utils.getApplicationNamespace(Mockito.any(KubernetesClient.class), - Mockito.nullable(String.class), Mockito.anyString(), Mockito.any(KubernetesNamespaceProvider.class))) - .thenReturn("namespaceA"); - - service("namespaceA", "serviceA", Map.of("color", "red")); - service("namespaceB", "serviceB", Map.of("color", "blue")); - - List result = services(properties, client, NAMESPACE_PROVIDER, - new KubernetesDiscoveryClient(null, properties, null, null, null).filter(), null, "dummy-target"); - Assertions.assertEquals(result.size(), 1); - Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); - Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); - } - - /** - *
-	 *     - all-namespaces = false
-	 *     - specific namespace = namespaceA
-	 *     - labels = {color = purple}
-	 *
-	 *     - serviceA exists in namespaceA with labels = {color=red}
-	 *     - serviceB exists in namespaceA with labels = {color=purple}
-	 *     - serviceC exists in namespaceC with labels = {color=purple}
-	 *
-	 *     - we get only serviceB as a result, even if such labels are also
-	 *       present on a different service (but it's in a different namespace).
-	 * 
- */ - @Test - void testSpecificNamespaceWithLabelsWithoutFilter() { - boolean allNamespaces = false; - Map labels = Map.of("color", "purple"); - - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), - true, 60L, false, null, Set.of(), labels, null, null, 0, false, false); - - utils.when(() -> Fabric8Utils.getApplicationNamespace(Mockito.any(KubernetesClient.class), - Mockito.nullable(String.class), Mockito.anyString(), Mockito.any(KubernetesNamespaceProvider.class))) - .thenReturn("namespaceA"); - - service("namespaceA", "serviceA", Map.of("color", "red")); - service("namespaceA", "serviceB", Map.of("color", "purple")); - service("namespaceC", "serviceC", Map.of("color", "purple")); - - List result = services(properties, client, NAMESPACE_PROVIDER, - new KubernetesDiscoveryClient(null, properties, null, null, null).filter(), null, "dummy-target"); - Assertions.assertEquals(result.size(), 1); - Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceB"); - Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); - } - - /** - *
-	 *     - all-namespaces = false
-	 *     - specific namespace = namespaceA
-	 *     - labels = {}
-	 *     - filter = "#root.metadata.labels.containsKey("number")"
-	 *       (namespaceA or namespaceB)
-	 *
-	 *     - serviceA exists in namespaceA with labels = {color=red, number=1}
-	 *     - serviceB exists in namespaceA with labels = {color=purple, cycle=create}
-	 *     - serviceC exists in namespaceC with labels = {color=purple, number=1}
-	 *
-	 *     - we get only serviceB as a result (because of the filter) even if such labels are also
-	 *       present on a different service (but it's in a different namespace).
-	 * 
- */ - @Test - void testSpecificNamespaceWithoutLabelsWithFilter() { - boolean allNamespaces = false; - Map labels = Map.of(); - String spelFilter = """ - #root.metadata.labels.containsKey("number") - """.stripLeading(); - - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), - true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); - - utils.when(() -> Fabric8Utils.getApplicationNamespace(Mockito.any(KubernetesClient.class), - Mockito.nullable(String.class), Mockito.anyString(), Mockito.any(KubernetesNamespaceProvider.class))) - .thenReturn("namespaceA"); - - service("namespaceA", "serviceA", Map.of("color", "red", "number", "1")); - service("namespaceA", "serviceB", Map.of("color", "purple", "cycle", "create")); - service("namespaceC", "serviceC", Map.of("color", "purple", "number", "1")); - - List result = services(properties, client, NAMESPACE_PROVIDER, - new KubernetesDiscoveryClient(null, properties, null, null, null).filter(), null, "dummy-target"); - Assertions.assertEquals(result.size(), 1); - Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); - Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); - Assertions.assertEquals(result.get(0).getMetadata().getLabels(), Map.of("color", "red", "number", "1")); - } - - /** - *
-	 *     - all-namespaces = false
-	 *     - some namespaces = [namespaceA, namespaceB]
-	 *     - labels = {}
-	 *     - filter = null
-	 *
-	 *     - serviceA exists in namespaceA with labels = {}
-	 *     - serviceB exists in namespaceB with labels = {}
-	 *     - serviceC exists in namespaceC with labels = {}
-	 *
-	 *     - we get serviceA and serviceB as a result, because their namespaces match.
-	 * 
- */ - @Test - void testSomeNamespacesWithoutLabelsWithoutFilter() { - boolean allNamespaces = false; - Set someNamespaces = Set.of("namespaceA", "namespaceB"); - Map labels = Map.of(); - - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, - someNamespaces, true, 60L, false, null, Set.of(), labels, null, null, 0, false, false); - - service("namespaceA", "serviceA", Map.of()); - service("namespaceB", "serviceB", Map.of()); - service("namespaceC", "serviceC", Map.of()); - - List result = services(properties, client, NAMESPACE_PROVIDER, - new KubernetesDiscoveryClient(null, properties, null, null, null).filter(), null, "dummy-target"); - Assertions.assertEquals(result.size(), 2); - result = result.stream().sorted(Comparator.comparing(x -> x.getMetadata().getName())).toList(); - Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); - Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); - Assertions.assertEquals(result.get(1).getMetadata().getName(), "serviceB"); - Assertions.assertEquals(result.get(1).getMetadata().getNamespace(), "namespaceB"); - } - - /** - *
-	 *     - all-namespaces = false
-	 *     - some namespaces = [namespaceA, namespaceB]
-	 *     - labels = {color=purple}
-	 *     - filter = null
-	 *
-	 *     - serviceA exists in namespaceA with labels = {color=purple}
-	 *     - serviceB exists in namespaceB with labels = {color=red}
-	 *     - serviceC exists in namespaceC with labels = {color=purple}
-	 *
-	 *     - we get serviceA as a result
-	 * 
- */ - @Test - void testSomeNamespacesWithLabelsWithoutFilter() { - boolean allNamespaces = false; - Set someNamespaces = Set.of("namespaceA", "namespaceB"); - Map labels = Map.of("color", "purple"); - String spelFilter = null; - - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, - someNamespaces, true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); - - service("namespaceA", "serviceA", Map.of("color", "purple")); - service("namespaceB", "serviceB", Map.of("color", "red")); - service("namespaceC", "serviceC", Map.of("color", "purple")); - - List result = services(properties, client, NAMESPACE_PROVIDER, - new KubernetesDiscoveryClient(null, properties, null, null, null).filter(), null, "dummy-target"); - Assertions.assertEquals(result.size(), 1); - Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); - Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); - } - - /** - *
-	 *     - all-namespaces = false
-	 *     - some namespaces = [namespaceA, namespaceB]
-	 *     - labels = {color=purple}
-	 *     - filter = #root.metadata.labels.containsKey("number")
-	 *
-	 *     - serviceA exists in namespaceA with labels = {color=purple}
-	 *     - serviceB exists in namespaceB with labels = {color=red}
-	 *     - serviceC exists in namespaceC with labels = {color=purple}
-	 *
-	 *     - we get serviceA as a result
-	 * 
- */ - @Test - void testSomeNamespacesWithLabelsWithFilter() { - boolean allNamespaces = false; - Set someNamespaces = Set.of("namespaceA", "namespaceB"); - Map labels = Map.of("color", "purple"); - String spelFilter = """ - #root.metadata.labels.containsKey("number") - """.stripLeading(); - - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, - someNamespaces, true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); - - service("namespaceA", "serviceA", Map.of("color", "purple", "number", "1")); - service("namespaceB", "serviceB", Map.of("color", "purple", "cycle", "create")); - service("namespaceC", "serviceC", Map.of("color", "purple", "number", "1")); - - List result = services(properties, client, NAMESPACE_PROVIDER, - new KubernetesDiscoveryClient(null, properties, null, null, null).filter(), null, "dummy-target"); - Assertions.assertEquals(result.size(), 1); - Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); - Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); - } - - private void service(String namespace, String name, Map labels) { - client.services().inNamespace(namespace) - .resource(new ServiceBuilder().withNewMetadata().withName(name).withLabels(labels).and().build()) - .create(); - } - - private static Environment mockEnvironment() { - MockEnvironment environment = new MockEnvironment(); - environment.setProperty("spring.cloud.kubernetes.client.namespace", "test"); - return environment; - } - -} From f516f80f49a6fa140fc47583cd11ea6015faec5e Mon Sep 17 00:00:00 2001 From: wind57 Date: Mon, 27 Feb 2023 15:09:04 +0200 Subject: [PATCH 036/151] dirty --- .../Fabric8DiscoveryServicesAdapterTests.java | 479 ++++++++++++++++++ 1 file changed, 479 insertions(+) create mode 100644 spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryServicesAdapterTests.java diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryServicesAdapterTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryServicesAdapterTests.java new file mode 100644 index 0000000000..384538f7ce --- /dev/null +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryServicesAdapterTests.java @@ -0,0 +1,479 @@ +/* + * Copyright 2012-2022 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.discovery; + +import java.util.Comparator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import io.fabric8.kubernetes.api.model.Service; +import io.fabric8.kubernetes.api.model.ServiceBuilder; +import io.fabric8.kubernetes.client.KubernetesClient; +import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.MockedStatic; +import org.mockito.Mockito; + +import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider; +import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; +import org.springframework.cloud.kubernetes.fabric8.Fabric8Utils; +import org.springframework.mock.env.MockEnvironment; + +/** + * @author wind57 + */ +@EnableKubernetesMockClient(crud = true, https = false) +class Fabric8DiscoveryServicesAdapterTests { + + private static KubernetesClient client; + + private static MockedStatic utils; + + @BeforeEach + void beforeEach() { + utils = Mockito.mockStatic(Fabric8Utils.class); + } + + @AfterEach + void afterEach() { + client.services().inAnyNamespace().delete(); + utils.close(); + } + + /** + *
+	 *     - all-namespaces = true
+	 *     - labels = {}
+	 *     - filter = null
+	 *
+	 *     - serviceA exists in namespaceA with labels = {color=red}
+	 *     - serviceB exists in namespaceB with labels = {color=blue}
+	 *
+	 *     - we get both services as a result.
+	 * 
+ */ + @Test + void testAllNamespacesWithoutLabelsWithoutFilter() { + boolean allNamespaces = true; + Map labels = Map.of(); + String spelFilter = null; + + MockEnvironment environment = new MockEnvironment(); + + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), + true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); + + Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( + new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, + null); + + service("namespaceA", "serviceA", Map.of("color", "red")); + service("namespaceB", "serviceB", Map.of("color", "blue")); + + List result = adapter.apply(client); + Assertions.assertEquals(result.size(), 2); + Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); + Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); + Assertions.assertEquals(result.get(1).getMetadata().getName(), "serviceB"); + Assertions.assertEquals(result.get(1).getMetadata().getNamespace(), "namespaceB"); + } + + /** + *
+	 *     - all-namespaces = true
+	 *     - labels = {color=red}
+	 *     - filter = null
+	 *
+	 *     - serviceA exists in namespaceA with labels = {color=red}
+	 *     - serviceB exists in namespaceB with labels = {color=blue}
+	 *
+	 *     - we get only serviceA as a result.
+	 * 
+ */ + @Test + void testAllNamespacesWithLabelsWithoutFilter() { + boolean allNamespaces = true; + Map labels = Map.of("color", "red"); + String spelFilter = null; + + MockEnvironment environment = new MockEnvironment(); + + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), + true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); + + Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( + new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, + null); + + service("namespaceA", "serviceA", Map.of("color", "red")); + service("namespaceB", "serviceB", Map.of("color", "blue")); + + List result = adapter.apply(client); + Assertions.assertEquals(result.size(), 1); + Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); + Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); + } + + /** + *
+	 *     - all-namespaces = true
+	 *     - labels = {}
+	 *     - filter = "#root.metadata.namespace matches '^.+A$'"
+	 *       (ends in A)
+	 *
+	 *     - serviceA exists in namespaceA with labels = {color=red}
+	 *     - serviceB exists in namespaceB with labels = {color=blue}
+	 *
+	 *     - we get only serviceA as a result.
+	 * 
+ */ + @Test + void testAllNamespacesWithoutLabelsWithNamespaceFilter() { + boolean allNamespaces = true; + Map labels = Map.of(); + String spelFilter = """ + #root.metadata.namespace matches "^.+A$" + """; + + MockEnvironment environment = new MockEnvironment(); + + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), + true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); + + Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( + new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, + null); + + service("namespaceA", "serviceA", Map.of("color", "red")); + service("namespaceB", "serviceB", Map.of("color", "blue")); + + List result = adapter.apply(client); + Assertions.assertEquals(result.size(), 1); + Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); + Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); + } + + /** + *
+	 *     - all-namespaces = true
+	 *     - labels = {}
+	 *     - filter = "#root.metadata.namespace matches '^namespace[A|B]$'"
+	 *       (namespaceA or namespaceB)
+	 *
+	 *     - serviceA exists in namespaceA with labels = {color=red}
+	 *     - serviceB exists in namespaceB with labels = {color=blue}
+	 *     - serviceC exists in namespaceC with labels = {color=purple}
+	 *
+	 *     - we get only serviceA and serviceB as a result.
+	 * 
+ */ + @Test + void testAllNamespacesWithoutLabelsWithNamespacesFilter() { + boolean allNamespaces = true; + Map labels = Map.of(); + String spelFilter = """ + #root.metadata.namespace matches "^namespace[A|B]$" + """; + + MockEnvironment environment = new MockEnvironment(); + + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), + true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); + + Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( + new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, + null); + + service("namespaceA", "serviceA", Map.of("color", "red")); + service("namespaceB", "serviceB", Map.of("color", "blue")); + service("namespaceC", "serviceC", Map.of("color", "purple")); + + List result = adapter.apply(client); + Assertions.assertEquals(result.size(), 2); + Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); + Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); + Assertions.assertEquals(result.get(1).getMetadata().getName(), "serviceB"); + Assertions.assertEquals(result.get(1).getMetadata().getNamespace(), "namespaceB"); + } + + /** + *
+	 *     - all-namespaces = false
+	 *     - specific namespace = namespaceA
+	 *     - labels = {}
+	 *
+	 *     - serviceA exists in namespaceA with labels = {color=red}
+	 *     - serviceB exists in namespaceB with labels = {color=blue}
+	 *
+	 *     - we get only serviceA as a result.
+	 * 
+ */ + @Test + void testSpecificNamespaceWithoutLabelsWithoutFilter() { + boolean allNamespaces = false; + Map labels = Map.of(); + String spelFilter = null; + + MockEnvironment environment = new MockEnvironment(); + + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), + true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); + + Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( + new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, + null); + + utils.when(() -> Fabric8Utils.getApplicationNamespace(Mockito.any(KubernetesClient.class), + Mockito.nullable(String.class), Mockito.anyString(), Mockito.any(KubernetesNamespaceProvider.class))) + .thenReturn("namespaceA"); + + service("namespaceA", "serviceA", Map.of("color", "red")); + service("namespaceB", "serviceB", Map.of("color", "blue")); + + List result = adapter.apply(client); + Assertions.assertEquals(result.size(), 1); + Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); + Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); + } + + /** + *
+	 *     - all-namespaces = false
+	 *     - specific namespace = namespaceA
+	 *     - labels = {color = purple}
+	 *
+	 *     - serviceA exists in namespaceA with labels = {color=red}
+	 *     - serviceB exists in namespaceA with labels = {color=purple}
+	 *     - serviceC exists in namespaceC with labels = {color=purple}
+	 *
+	 *     - we get only serviceB as a result, even if such labels are also
+	 *       present on a different service (but it's in a different namespace).
+	 * 
+ */ + @Test + void testSpecificNamespaceWithLabelsWithoutFilter() { + boolean allNamespaces = false; + Map labels = Map.of("color", "purple"); + String spelFilter = null; + + MockEnvironment environment = new MockEnvironment(); + + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), + true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); + + Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( + new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, + null); + + utils.when(() -> Fabric8Utils.getApplicationNamespace(Mockito.any(KubernetesClient.class), + Mockito.nullable(String.class), Mockito.anyString(), Mockito.any(KubernetesNamespaceProvider.class))) + .thenReturn("namespaceA"); + + service("namespaceA", "serviceA", Map.of("color", "red")); + service("namespaceA", "serviceB", Map.of("color", "purple")); + service("namespaceC", "serviceC", Map.of("color", "purple")); + + List result = adapter.apply(client); + Assertions.assertEquals(result.size(), 1); + Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceB"); + Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); + } + + /** + *
+	 *     - all-namespaces = false
+	 *     - specific namespace = namespaceA
+	 *     - labels = {}
+	 *     - filter = "#root.metadata.labels.containsKey("number")"
+	 *       (namespaceA or namespaceB)
+	 *
+	 *     - serviceA exists in namespaceA with labels = {color=red, number=1}
+	 *     - serviceB exists in namespaceA with labels = {color=purple, cycle=create}
+	 *     - serviceC exists in namespaceC with labels = {color=purple, number=1}
+	 *
+	 *     - we get only serviceB as a result (because of the filter) even if such labels are also
+	 *       present on a different service (but it's in a different namespace).
+	 * 
+ */ + @Test + void testSpecificNamespaceWithoutLabelsWithFilter() { + boolean allNamespaces = false; + Map labels = Map.of(); + String spelFilter = """ + #root.metadata.labels.containsKey("number") + """.stripLeading(); + + MockEnvironment environment = new MockEnvironment(); + + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), + true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); + + Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( + new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, + null); + + utils.when(() -> Fabric8Utils.getApplicationNamespace(Mockito.any(KubernetesClient.class), + Mockito.nullable(String.class), Mockito.anyString(), Mockito.any(KubernetesNamespaceProvider.class))) + .thenReturn("namespaceA"); + + service("namespaceA", "serviceA", Map.of("color", "red", "number", "1")); + service("namespaceA", "serviceB", Map.of("color", "purple", "cycle", "create")); + service("namespaceC", "serviceC", Map.of("color", "purple", "number", "1")); + + List result = adapter.apply(client); + Assertions.assertEquals(result.size(), 1); + Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); + Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); + Assertions.assertEquals(result.get(0).getMetadata().getLabels(), Map.of("color", "red", "number", "1")); + } + + /** + *
+	 *     - all-namespaces = false
+	 *     - some namespaces = [namespaceA, namespaceB]
+	 *     - labels = {}
+	 *     - filter = null
+	 *
+	 *     - serviceA exists in namespaceA with labels = {}
+	 *     - serviceB exists in namespaceB with labels = {}
+	 *     - serviceC exists in namespaceC with labels = {}
+	 *
+	 *     - we get serviceA and serviceB as a result, because their namespaces match.
+	 * 
+ */ + @Test + void testSomeNamespacesWithoutLabelsWithoutFilter() { + boolean allNamespaces = false; + Set someNamespaces = Set.of("namespaceA", "namespaceB"); + Map labels = Map.of(); + String spelFilter = null; + + MockEnvironment environment = new MockEnvironment(); + + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, + someNamespaces, true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); + + Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( + new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, + null); + + service("namespaceA", "serviceA", Map.of()); + service("namespaceB", "serviceB", Map.of()); + service("namespaceC", "serviceC", Map.of()); + + List result = adapter.apply(client); + Assertions.assertEquals(result.size(), 2); + result = result.stream().sorted(Comparator.comparing(x -> x.getMetadata().getName())).toList(); + Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); + Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); + Assertions.assertEquals(result.get(1).getMetadata().getName(), "serviceB"); + Assertions.assertEquals(result.get(1).getMetadata().getNamespace(), "namespaceB"); + } + + /** + *
+	 *     - all-namespaces = false
+	 *     - some namespaces = [namespaceA, namespaceB]
+	 *     - labels = {color=purple}
+	 *     - filter = null
+	 *
+	 *     - serviceA exists in namespaceA with labels = {color=purple}
+	 *     - serviceB exists in namespaceB with labels = {color=red}
+	 *     - serviceC exists in namespaceC with labels = {color=purple}
+	 *
+	 *     - we get serviceA as a result
+	 * 
+ */ + @Test + void testSomeNamespacesWithLabelsWithoutFilter() { + boolean allNamespaces = false; + Set someNamespaces = Set.of("namespaceA", "namespaceB"); + Map labels = Map.of("color", "purple"); + String spelFilter = null; + + MockEnvironment environment = new MockEnvironment(); + + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, + someNamespaces, true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); + + Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( + new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, + null); + + service("namespaceA", "serviceA", Map.of("color", "purple")); + service("namespaceB", "serviceB", Map.of("color", "red")); + service("namespaceC", "serviceC", Map.of("color", "purple")); + + List result = adapter.apply(client); + Assertions.assertEquals(result.size(), 1); + Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); + Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); + } + + /** + *
+	 *     - all-namespaces = false
+	 *     - some namespaces = [namespaceA, namespaceB]
+	 *     - labels = {color=purple}
+	 *     - filter = #root.metadata.labels.containsKey("number")
+	 *
+	 *     - serviceA exists in namespaceA with labels = {color=purple}
+	 *     - serviceB exists in namespaceB with labels = {color=red}
+	 *     - serviceC exists in namespaceC with labels = {color=purple}
+	 *
+	 *     - we get serviceA as a result
+	 * 
+ */ + @Test + void testSomeNamespacesWithLabelsWithFilter() { + boolean allNamespaces = false; + Set someNamespaces = Set.of("namespaceA", "namespaceB"); + Map labels = Map.of("color", "purple"); + String spelFilter = """ + #root.metadata.labels.containsKey("number") + """.stripLeading(); + + MockEnvironment environment = new MockEnvironment(); + + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, + someNamespaces, true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); + + Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( + new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, + null); + + service("namespaceA", "serviceA", Map.of("color", "purple", "number", "1")); + service("namespaceB", "serviceB", Map.of("color", "purple", "cycle", "create")); + service("namespaceC", "serviceC", Map.of("color", "purple", "number", "1")); + + List result = adapter.apply(client); + Assertions.assertEquals(result.size(), 1); + Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); + Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); + } + + private void service(String namespace, String name, Map labels) { + client.services().inNamespace(namespace) + .resource(new ServiceBuilder().withNewMetadata().withName(name).withLabels(labels).and().build()) + .create(); + } + +} From c3185dcfbffddf048ac95dde7da7c2a768917fc3 Mon Sep 17 00:00:00 2001 From: wind57 Date: Mon, 27 Feb 2023 15:50:40 +0200 Subject: [PATCH 037/151] dirty --- .../Fabric8DiscoveryServicesAdapter.java | 4 +- .../discovery/KubernetesDiscoveryClient.java | 8 ++- .../KubernetesDiscoveryClientUtils.java | 17 ++--- .../Fabric8DiscoveryServicesAdapterTests.java | 70 +++++++++---------- ...c8KubernetesDiscoveryClientUtilsTests.java | 28 ++++++-- .../KubernetesDiscoveryClientFilterTest.java | 59 ++++------------ 6 files changed, 90 insertions(+), 96 deletions(-) diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryServicesAdapter.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryServicesAdapter.java index e3e20eebe9..5cc5420b2a 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryServicesAdapter.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryServicesAdapter.java @@ -42,7 +42,7 @@ final class Fabric8DiscoveryServicesAdapter implements Function apply(KubernetesClient client) { if (!properties.namespaces().isEmpty()) { List services = new ArrayList<>(); properties.namespaces().forEach(namespace -> services.addAll(client.services().inNamespace(namespace) - .withLabels(properties.serviceLabels()).list().getItems().stream().filter(filter).toList())); + .withLabels(properties.serviceLabels()).list().getItems().stream().filter(filter).toList())); return services; } return function.apply(client).list().getItems().stream().filter(filter).toList(); diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java index 346ea4cd40..2de04d3fbb 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java @@ -82,7 +82,7 @@ public KubernetesDiscoveryClient(KubernetesClient client, this.servicePortSecureResolver = servicePortSecureResolver; this.kubernetesClientServicesFunction = kubernetesClientServicesFunction; this.adapter = new Fabric8DiscoveryServicesAdapter(kubernetesClientServicesFunction, - kubernetesDiscoveryProperties, filter); + kubernetesDiscoveryProperties, filter); } public KubernetesClient getClient() { @@ -114,6 +114,10 @@ public List getInstances(String serviceId) { LOG.debug(() -> "will search for 'ExternalName' type of services"); } + if (properties.includeExternalNameServices()) { + LOG.debug(() -> "Searching for 'ExternalName' type of services"); + } + return instances; } @@ -156,7 +160,7 @@ public List getServices() { @Deprecated(forRemoval = true) public List getServices(Predicate filter) { return new Fabric8DiscoveryServicesAdapter(kubernetesClientServicesFunction, properties, filter).apply(client) - .stream().map(s -> s.getMetadata().getName()).toList(); + .stream().map(s -> s.getMetadata().getName()).toList(); } @Override diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtils.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtils.java index c2e50456e0..f860830147 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtils.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtils.java @@ -246,29 +246,29 @@ static ServiceInstance serviceInstance(ServicePortSecureResolver servicePortSecu } static List services(KubernetesDiscoveryProperties properties, KubernetesClient client, - KubernetesNamespaceProvider namespaceProvider, Predicate predicate, String serviceName, - String target) { + KubernetesNamespaceProvider namespaceProvider, Predicate predicate, + Map fieldFilters, String target) { List services; if (properties.allNamespaces()) { LOG.debug(() -> "discovering services in all namespaces"); services = filteredServices(client.services().inAnyNamespace().withNewFilter(), properties, predicate, - serviceName); + fieldFilters); } else if (!properties.namespaces().isEmpty()) { LOG.debug(() -> "discovering services in namespaces : " + properties.namespaces()); List inner = new ArrayList<>(properties.namespaces().size()); properties.namespaces().forEach( namespace -> inner.addAll(filteredServices(client.services().inNamespace(namespace).withNewFilter(), - properties, predicate, serviceName))); + properties, predicate, fieldFilters))); services = inner; } else { String namespace = Fabric8Utils.getApplicationNamespace(client, null, target, namespaceProvider); LOG.debug(() -> "discovering services in namespace : " + namespace); services = filteredServices(client.services().inNamespace(namespace).withNewFilter(), properties, predicate, - serviceName); + fieldFilters); } return services; @@ -279,13 +279,14 @@ else if (!properties.namespaces().isEmpty()) { */ private static List filteredServices( FilterNested>> filterNested, - KubernetesDiscoveryProperties properties, Predicate predicate, @Nullable String serviceName) { + KubernetesDiscoveryProperties properties, Predicate predicate, + @Nullable Map fieldFilters) { FilterNested>> partial = filterNested .withLabels(properties.serviceLabels()); - if (serviceName != null) { - partial = partial.withField("metadata.name", serviceName); + if (fieldFilters != null) { + partial = partial.withFields(fieldFilters); } return partial.endFilter().list().getItems().stream().filter(predicate).toList(); diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryServicesAdapterTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryServicesAdapterTests.java index 384538f7ce..0d378fb207 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryServicesAdapterTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryServicesAdapterTests.java @@ -79,11 +79,11 @@ void testAllNamespacesWithoutLabelsWithoutFilter() { MockEnvironment environment = new MockEnvironment(); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), - true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); + true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( - new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, - null); + new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, + null); service("namespaceA", "serviceA", Map.of("color", "red")); service("namespaceB", "serviceB", Map.of("color", "blue")); @@ -117,11 +117,11 @@ void testAllNamespacesWithLabelsWithoutFilter() { MockEnvironment environment = new MockEnvironment(); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), - true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); + true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( - new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, - null); + new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, + null); service("namespaceA", "serviceA", Map.of("color", "red")); service("namespaceB", "serviceB", Map.of("color", "blue")); @@ -156,11 +156,11 @@ void testAllNamespacesWithoutLabelsWithNamespaceFilter() { MockEnvironment environment = new MockEnvironment(); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), - true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); + true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( - new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, - null); + new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, + null); service("namespaceA", "serviceA", Map.of("color", "red")); service("namespaceB", "serviceB", Map.of("color", "blue")); @@ -196,11 +196,11 @@ void testAllNamespacesWithoutLabelsWithNamespacesFilter() { MockEnvironment environment = new MockEnvironment(); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), - true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); + true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( - new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, - null); + new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, + null); service("namespaceA", "serviceA", Map.of("color", "red")); service("namespaceB", "serviceB", Map.of("color", "blue")); @@ -235,15 +235,15 @@ void testSpecificNamespaceWithoutLabelsWithoutFilter() { MockEnvironment environment = new MockEnvironment(); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), - true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); + true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( - new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, - null); + new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, + null); utils.when(() -> Fabric8Utils.getApplicationNamespace(Mockito.any(KubernetesClient.class), Mockito.nullable(String.class), Mockito.anyString(), Mockito.any(KubernetesNamespaceProvider.class))) - .thenReturn("namespaceA"); + .thenReturn("namespaceA"); service("namespaceA", "serviceA", Map.of("color", "red")); service("namespaceB", "serviceB", Map.of("color", "blue")); @@ -277,15 +277,15 @@ void testSpecificNamespaceWithLabelsWithoutFilter() { MockEnvironment environment = new MockEnvironment(); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), - true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); + true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( - new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, - null); + new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, + null); utils.when(() -> Fabric8Utils.getApplicationNamespace(Mockito.any(KubernetesClient.class), Mockito.nullable(String.class), Mockito.anyString(), Mockito.any(KubernetesNamespaceProvider.class))) - .thenReturn("namespaceA"); + .thenReturn("namespaceA"); service("namespaceA", "serviceA", Map.of("color", "red")); service("namespaceA", "serviceB", Map.of("color", "purple")); @@ -324,15 +324,15 @@ void testSpecificNamespaceWithoutLabelsWithFilter() { MockEnvironment environment = new MockEnvironment(); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, Set.of(), - true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); + true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( - new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, - null); + new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, + null); utils.when(() -> Fabric8Utils.getApplicationNamespace(Mockito.any(KubernetesClient.class), Mockito.nullable(String.class), Mockito.anyString(), Mockito.any(KubernetesNamespaceProvider.class))) - .thenReturn("namespaceA"); + .thenReturn("namespaceA"); service("namespaceA", "serviceA", Map.of("color", "red", "number", "1")); service("namespaceA", "serviceB", Map.of("color", "purple", "cycle", "create")); @@ -369,11 +369,11 @@ void testSomeNamespacesWithoutLabelsWithoutFilter() { MockEnvironment environment = new MockEnvironment(); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, - someNamespaces, true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); + someNamespaces, true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( - new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, - null); + new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, + null); service("namespaceA", "serviceA", Map.of()); service("namespaceB", "serviceB", Map.of()); @@ -412,11 +412,11 @@ void testSomeNamespacesWithLabelsWithoutFilter() { MockEnvironment environment = new MockEnvironment(); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, - someNamespaces, true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); + someNamespaces, true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( - new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, - null); + new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, + null); service("namespaceA", "serviceA", Map.of("color", "purple")); service("namespaceB", "serviceB", Map.of("color", "red")); @@ -454,11 +454,11 @@ void testSomeNamespacesWithLabelsWithFilter() { MockEnvironment environment = new MockEnvironment(); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(false, allNamespaces, - someNamespaces, true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); + someNamespaces, true, 60L, false, spelFilter, Set.of(), labels, null, null, 0, false, false); Fabric8DiscoveryServicesAdapter adapter = new Fabric8DiscoveryServicesAdapter( - new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, - null); + new KubernetesDiscoveryClientAutoConfiguration().servicesFunction(properties, environment), properties, + null); service("namespaceA", "serviceA", Map.of("color", "purple", "number", "1")); service("namespaceB", "serviceB", Map.of("color", "purple", "cycle", "create")); @@ -472,8 +472,8 @@ void testSomeNamespacesWithLabelsWithFilter() { private void service(String namespace, String name, Map labels) { client.services().inNamespace(namespace) - .resource(new ServiceBuilder().withNewMetadata().withName(name).withLabels(labels).and().build()) - .create(); + .resource(new ServiceBuilder().withNewMetadata().withName(name).withLabels(labels).and().build()) + .create(); } } diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtilsTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtilsTests.java index 3289f0ce2c..3069c2cc6e 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtilsTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtilsTests.java @@ -22,6 +22,7 @@ import io.fabric8.kubernetes.api.model.Service; import io.fabric8.kubernetes.api.model.ServiceBuilder; +import io.fabric8.kubernetes.api.model.ServiceSpecBuilder; import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient; import org.junit.jupiter.api.AfterEach; @@ -85,7 +86,8 @@ void testServicesAllNamespacesNameFilter() { service("serviceA", "A", Map.of()); service("serviceB", "B", Map.of()); - List result = services(properties, client, null, x -> true, "serviceA", "fabric8-discovery"); + List result = services(properties, client, null, x -> true, Map.of("metadata.name", "serviceA"), + "fabric8-discovery"); Assertions.assertEquals(result.size(), 1); Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); } @@ -156,7 +158,8 @@ void testServicesSelectiveNamespacesNameFilter() { service("serviceB", "B", Map.of()); service("serviceC", "C", Map.of()); - List result = services(properties, client, null, x -> true, "serviceA", "fabric8-discovery"); + List result = services(properties, client, null, x -> true, Map.of("metadata.name", "serviceA"), + "fabric8-discovery"); Assertions.assertEquals(result.size(), 1); Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); } @@ -230,8 +233,8 @@ void testServicesNamespaceProviderNameFilter() { service("serviceA", "A", Map.of()); service("serviceB", "A", Map.of()); - List result = services(properties, client, namespaceProvider("A"), x -> true, "serviceA", - "fabric8-discovery"); + List result = services(properties, client, namespaceProvider("A"), x -> true, + Map.of("metadata.name", "serviceA"), "fabric8-discovery"); Assertions.assertEquals(result.size(), 1); Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); } @@ -260,6 +263,23 @@ void testServicesNamespaceProviderPredicateFilter() { Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceB"); } + @Test + void testExternalName() { + Service service = new ServiceBuilder() + .withSpec(new ServiceSpecBuilder().withType("ExternalName").withExternalName("k8s-spring").build()) + .withNewMetadata().withName("external-name-service").and().build(); + client.services().inNamespace("test").resource(service).create(); + + boolean allNamespaces = false; + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, Set.of(), + true, 60L, false, "", Set.of(), Map.of(), "", null, 0, false, false); + + List result = services(properties, client, namespaceProvider("test"), + x -> x.getSpec().getType().equals("ExternalName"), Map.of(), "fabric8-discovery"); + Assertions.assertEquals(result.size(), 1); + Assertions.assertEquals(result.get(0).getMetadata().getName(), "external-name-service"); + } + private void service(String name, String namespace, Map labels) { Service service = new ServiceBuilder().withNewMetadata().withName(name).withLabels(labels) .withNamespace(namespace).and().build(); diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientFilterTest.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientFilterTest.java index 6188f0c2f4..d4d5111bef 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientFilterTest.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientFilterTest.java @@ -26,34 +26,25 @@ import io.fabric8.kubernetes.api.model.Service; import io.fabric8.kubernetes.api.model.ServiceList; import io.fabric8.kubernetes.client.KubernetesClient; -import io.fabric8.kubernetes.client.dsl.FilterNested; -import io.fabric8.kubernetes.client.dsl.FilterWatchListDeletable; import io.fabric8.kubernetes.client.dsl.MixedOperation; import io.fabric8.kubernetes.client.dsl.ServiceResource; import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; -import org.springframework.core.env.Environment; -import org.springframework.mock.env.MockEnvironment; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.when; -@SuppressWarnings("unchecked") class KubernetesDiscoveryClientFilterTest { private final KubernetesClient kubernetesClient = Mockito.mock(KubernetesClient.class); + private final KubernetesClientServicesFunction kubernetesClientServicesFunction = KubernetesClient::services; + private final MixedOperation> serviceOperation = Mockito .mock(MixedOperation.class); - private final FilterNested>> filterNested = Mockito - .mock(FilterNested.class); - - private final FilterWatchListDeletable> filter = Mockito - .mock(FilterWatchListDeletable.class); - @Test void testFilteredServices() { List springBootServiceNames = Arrays.asList("serviceA", "serviceB"); @@ -68,20 +59,14 @@ void testFilteredServices() { ServiceList serviceList = new ServiceList(); serviceList.setItems(services); - when(kubernetesClient.services()).thenReturn(serviceOperation); - when(serviceOperation.inNamespace(Mockito.anyString())).thenReturn(serviceOperation); - when(serviceOperation.withNewFilter()).thenReturn(filterNested); - when(filterNested.withLabels(Mockito.anyMap())).thenReturn(filterNested); - when(filterNested.endFilter()).thenReturn(filter); - when(filter.list()).thenReturn(serviceList); + when(this.serviceOperation.list()).thenReturn(serviceList); + when(this.kubernetesClient.services()).thenReturn(this.serviceOperation); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, false, "metadata.additionalProperties['spring-boot']", Set.of(), Map.of(), null, KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, true, false); - - KubernetesDiscoveryClient client = new KubernetesDiscoveryClient(kubernetesClient, properties, null, null, - null); - client.setEnvironment(mockEnvironment()); + KubernetesDiscoveryClient client = new KubernetesDiscoveryClient(this.kubernetesClient, properties, + this.kubernetesClientServicesFunction); List filteredServices = client.getServices(); assertThat(filteredServices).isEqualTo(springBootServiceNames); @@ -102,19 +87,14 @@ void testFilteredServicesByPrefix() { ServiceList serviceList = new ServiceList(); serviceList.setItems(services); - when(kubernetesClient.services()).thenReturn(serviceOperation); - when(serviceOperation.inNamespace(Mockito.anyString())).thenReturn(serviceOperation); - when(serviceOperation.withNewFilter()).thenReturn(filterNested); - when(filterNested.withLabels(Mockito.anyMap())).thenReturn(filterNested); - when(filterNested.endFilter()).thenReturn(filter); - when(filter.list()).thenReturn(serviceList); + when(this.serviceOperation.list()).thenReturn(serviceList); + when(this.kubernetesClient.services()).thenReturn(this.serviceOperation); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, false, "metadata.name.startsWith('service')", Set.of(), Map.of(), null, KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, true, false); - KubernetesDiscoveryClient client = new KubernetesDiscoveryClient(kubernetesClient, properties, null, null, - null); - client.setEnvironment(mockEnvironment()); + KubernetesDiscoveryClient client = new KubernetesDiscoveryClient(this.kubernetesClient, properties, + this.kubernetesClientServicesFunction); List filteredServices = client.getServices(); assertThat(filteredServices).isEqualTo(springBootServiceNames); @@ -128,18 +108,13 @@ void testNoExpression() { ServiceList serviceList = new ServiceList(); serviceList.setItems(services); - when(kubernetesClient.services()).thenReturn(serviceOperation); - when(serviceOperation.inNamespace(Mockito.anyString())).thenReturn(serviceOperation); - when(serviceOperation.withNewFilter()).thenReturn(filterNested); - when(filterNested.withLabels(Mockito.anyMap())).thenReturn(filterNested); - when(filterNested.endFilter()).thenReturn(filter); - when(filter.list()).thenReturn(serviceList); + when(this.serviceOperation.list()).thenReturn(serviceList); + when(this.kubernetesClient.services()).thenReturn(this.serviceOperation); KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(), true, 60, false, "", Set.of(), Map.of(), null, KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, true, false); - KubernetesDiscoveryClient client = new KubernetesDiscoveryClient(kubernetesClient, properties, null, null, - null); - client.setEnvironment(mockEnvironment()); + KubernetesDiscoveryClient client = new KubernetesDiscoveryClient(this.kubernetesClient, properties, + this.kubernetesClientServicesFunction); List filteredServices = client.getServices(); @@ -160,10 +135,4 @@ private List createSpringBootServiceByName(List serviceNames) { return serviceCollection; } - private static Environment mockEnvironment() { - MockEnvironment environment = new MockEnvironment(); - environment.setProperty("spring.cloud.kubernetes.client.namespace", "test"); - return environment; - } - } From 76b02032d48dc096eb3084641cef654d85e4e9fa Mon Sep 17 00:00:00 2001 From: wind57 Date: Mon, 27 Feb 2023 23:19:31 +0200 Subject: [PATCH 038/151] before integration tests --- .../ExternalNameServiceInstance.java | 65 +++++++++++++++++++ .../KubernetesDiscoveryConstants.java | 5 ++ .../discovery/KubernetesDiscoveryClient.java | 19 ++++-- .../KubernetesDiscoveryClientUtils.java | 13 +++- .../KubernetesDiscoveryClientTests.java | 62 ++++++++++++++++++ .../Fabric8ServiceInstanceMapperTests.java | 2 +- .../KubernetesServiceListSupplierTests.java | 2 +- 7 files changed, 160 insertions(+), 8 deletions(-) create mode 100644 spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/ExternalNameServiceInstance.java diff --git a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/ExternalNameServiceInstance.java b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/ExternalNameServiceInstance.java new file mode 100644 index 0000000000..93e7a03cef --- /dev/null +++ b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/ExternalNameServiceInstance.java @@ -0,0 +1,65 @@ +/* + * Copyright 2019-2023 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.commons.discovery; + +import java.net.URI; +import java.util.Map; + +import org.springframework.cloud.client.ServiceInstance; + +/** + * Type of {@link org.springframework.cloud.client.ServiceInstance} when + * "spec.type=ServiceInstance". + * + * @author wind57 + */ +public record ExternalNameServiceInstance(DefaultKubernetesServiceInstance defaultInstance) implements ServiceInstance { + + @Override + public String getServiceId() { + return defaultInstance().serviceId(); + } + + @Override + public String getHost() { + return defaultInstance.getHost(); + } + + @Override + public int getPort() { + return -1; + } + + @Override + public boolean isSecure() { + return false; + } + + @Override + public URI getUri() { + return URI.create(defaultInstance().getHost()); + } + + @Override + public Map getMetadata() { + return defaultInstance.metadata(); + } + + public String type() { + return "ExternalName"; + } +} diff --git a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/KubernetesDiscoveryConstants.java b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/KubernetesDiscoveryConstants.java index ba7258542c..6c97effc48 100644 --- a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/KubernetesDiscoveryConstants.java +++ b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/KubernetesDiscoveryConstants.java @@ -67,4 +67,9 @@ private KubernetesDiscoveryConstants() { */ public static final String ENDPOINT_SLICE = "EndpointSlice"; + /** + * ExternalName type of service. + */ + public static final String EXTERNAL_NAME = "ExternalName"; + } diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java index 2de04d3fbb..017b2aff94 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java @@ -37,11 +37,14 @@ import org.springframework.core.env.Environment; import org.springframework.core.log.LogAccessor; +import static org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryConstants.EXTERNAL_NAME; import static org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientUtils.addresses; import static org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientUtils.endpoints; import static org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientUtils.endpointsPort; +import static org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientUtils.externalNameServiceInstance; import static org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientUtils.serviceInstance; import static org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientUtils.serviceMetadata; +import static org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientUtils.services; /** * Kubernetes implementation of {@link DiscoveryClient}. @@ -111,11 +114,17 @@ public List getInstances(String serviceId) { } if (properties.includeExternalNameServices()) { - LOG.debug(() -> "will search for 'ExternalName' type of services"); - } - - if (properties.includeExternalNameServices()) { - LOG.debug(() -> "Searching for 'ExternalName' type of services"); + LOG.debug(() -> "Searching for 'ExternalName' type of services with serviceId : " + serviceId); + List services = services(properties, client, namespaceProvider, + s -> s.getSpec().getType().equals(EXTERNAL_NAME), Map.of("metadata.name", serviceId), + "fabric8-discovery"); + for (Service service : services) { + Map serviceMetadata = serviceMetadata(serviceId, service, properties, List.of(), + service.getMetadata().getNamespace()); + ServiceInstance externalNameServiceInstance = externalNameServiceInstance(service, serviceId, + serviceMetadata); + instances.add(externalNameServiceInstance); + } } return instances; diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtils.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtils.java index f860830147..113271eaff 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtils.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtils.java @@ -43,6 +43,7 @@ import org.springframework.cloud.client.ServiceInstance; import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider; import org.springframework.cloud.kubernetes.commons.discovery.DefaultKubernetesServiceInstance; +import org.springframework.cloud.kubernetes.commons.discovery.ExternalNameServiceInstance; import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; import org.springframework.cloud.kubernetes.fabric8.Fabric8Utils; import org.springframework.core.log.LogAccessor; @@ -162,7 +163,9 @@ static Map serviceMetadata(String serviceId, Service service, .filter(port -> StringUtils.hasText(port.getName())) .collect(toMap(EndpointPort::getName, port -> Integer.toString(port.getPort()))); Map portMetadata = keysWithPrefix(ports, properties.metadata().portsPrefix()); - LOG.debug(() -> "Adding port metadata: " + portMetadata + " for serviceId : " + serviceId); + if (!portMetadata.isEmpty()) { + LOG.debug(() -> "Adding port metadata: " + portMetadata + " for serviceId : " + serviceId); + } serviceMetadata.putAll(portMetadata); } @@ -230,6 +233,14 @@ static List addresses(EndpointSubset endpointSubset, Kubernetes return addresses; } + static ServiceInstance externalNameServiceInstance(Service service, String serviceId, + Map serviceMetadata) { + DefaultKubernetesServiceInstance defaultKubernetesServiceInstance = new DefaultKubernetesServiceInstance( + service.getMetadata().getUid(), serviceId, service.getSpec().getExternalName(), -1, serviceMetadata, + false, service.getMetadata().getNamespace(), null); + return new ExternalNameServiceInstance(defaultKubernetesServiceInstance); + } + static ServiceInstance serviceInstance(ServicePortSecureResolver servicePortSecureResolver, Service service, EndpointAddress endpointAddress, int endpointPort, String serviceId, Map serviceMetadata, String namespace) { diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientTests.java index 898d98a739..9ef62594c0 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientTests.java @@ -24,6 +24,9 @@ import io.fabric8.kubernetes.api.model.EndpointsBuilder; import io.fabric8.kubernetes.api.model.ObjectMeta; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; +import io.fabric8.kubernetes.api.model.Service; +import io.fabric8.kubernetes.api.model.ServiceBuilder; +import io.fabric8.kubernetes.api.model.ServiceSpecBuilder; import io.fabric8.kubernetes.client.Config; import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient; @@ -35,6 +38,8 @@ import org.springframework.boot.test.system.CapturedOutput; import org.springframework.boot.test.system.OutputCaptureExtension; +import org.springframework.cloud.client.ServiceInstance; +import org.springframework.cloud.kubernetes.commons.discovery.ExternalNameServiceInstance; import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; /** @@ -467,6 +472,63 @@ void testSelectiveNamespacesMultipleNamespacesAllMatch(CapturedOutput output) { Assertions.assertTrue(output.getOut().contains("discovering endpoints in namespaces : " + namespacesAsString)); } + /** + *
+	 *     - two services are present in two namespaces [a, b]
+	 *     - both are returned
+	 * 
+ */ + @Test + void testGetServicesWithExternalNameService() { + Service nonExternalNameService = new ServiceBuilder() + .withSpec(new ServiceSpecBuilder().withType("ClusterIP").build()).withNewMetadata() + .withName("blue-service").withNamespace("a").endMetadata().build(); + client.services().inNamespace("a").resource(nonExternalNameService).create(); + + Service externalNameService = new ServiceBuilder() + .withSpec(new ServiceSpecBuilder().withType("ExternalName").withExternalName("k8s-spring").build()) + .withNewMetadata().withName("blue-service").withNamespace("b").endMetadata().build(); + client.services().inNamespace("b").resource(externalNameService).create(); + + // last argument is irrelevant, as getServices does not care about that flag + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of("a", "b"), true, + 60L, false, "", Set.of(), Map.of(), "", KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, false, + false); + + KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null); + List result = discoveryClient.getServices(); + Assertions.assertEquals(result.size(), 2); + // this looks weird at the moment, but there is an issue that will fix this + Assertions.assertEquals(result.get(0), "blue-service"); + Assertions.assertEquals(result.get(1), "blue-service"); + } + + @Test + void testExternalNameService() { + Service externalNameService = new ServiceBuilder() + .withSpec(new ServiceSpecBuilder().withType("ExternalName").withExternalName("k8s-spring-b").build()) + .withNewMetadata().withLabels(Map.of("label-key", "label-value")).withAnnotations(Map.of("abc", "def")) + .withName("blue-service").withNamespace("b").endMetadata().build(); + client.services().inNamespace("b").resource(externalNameService).create(); + + KubernetesDiscoveryProperties.Metadata metadata = new KubernetesDiscoveryProperties.Metadata(true, + "labels-prefix-", true, "annotations-prefix-", true, "ports-prefix"); + KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of("a", "b"), true, + 60L, false, "", Set.of(), Map.of(), "", metadata, 0, false, true); + + KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null); + List result = discoveryClient.getInstances("blue-service"); + Assertions.assertEquals(result.size(), 1); + ExternalNameServiceInstance externalNameServiceInstance = (ExternalNameServiceInstance) result.get(0); + Assertions.assertEquals(externalNameServiceInstance.getServiceId(), "blue-service"); + Assertions.assertEquals(externalNameServiceInstance.getHost(), "k8s-spring-b"); + Assertions.assertEquals(externalNameServiceInstance.getPort(), -1); + Assertions.assertFalse(externalNameServiceInstance.isSecure()); + Assertions.assertEquals(externalNameServiceInstance.getUri().toASCIIString(), "k8s-spring-b"); + Assertions.assertEquals(externalNameServiceInstance.getMetadata(), Map.of("k8s_namespace", "b", + "labels-prefix-label-key", "label-value", "annotations-prefix-abc", "def")); + } + private void createEndpoints(String namespace, String name, Map labels) { client.endpoints().inNamespace(namespace) .resource(new EndpointsBuilder() diff --git a/spring-cloud-kubernetes-fabric8-loadbalancer/src/test/java/org/springframework/cloud/kubernetes/fabric8/loadbalancer/Fabric8ServiceInstanceMapperTests.java b/spring-cloud-kubernetes-fabric8-loadbalancer/src/test/java/org/springframework/cloud/kubernetes/fabric8/loadbalancer/Fabric8ServiceInstanceMapperTests.java index e8b18dce43..3a2d60fe88 100644 --- a/spring-cloud-kubernetes-fabric8-loadbalancer/src/test/java/org/springframework/cloud/kubernetes/fabric8/loadbalancer/Fabric8ServiceInstanceMapperTests.java +++ b/spring-cloud-kubernetes-fabric8-loadbalancer/src/test/java/org/springframework/cloud/kubernetes/fabric8/loadbalancer/Fabric8ServiceInstanceMapperTests.java @@ -80,7 +80,7 @@ void testMapperSecureNullLabelsAndAnnotations() { KubernetesLoadBalancerProperties properties = new KubernetesLoadBalancerProperties(); KubernetesDiscoveryProperties discoveryProperties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, false, null, Set.of(), Map.of(), null, KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, - false); + false, false); List ports = new ArrayList<>(); ports.add(new ServicePortBuilder().withPort(443).build()); Service service = buildService("test", "abc", ports, null, null); diff --git a/spring-cloud-kubernetes-fabric8-loadbalancer/src/test/java/org/springframework/cloud/kubernetes/fabric8/loadbalancer/KubernetesServiceListSupplierTests.java b/spring-cloud-kubernetes-fabric8-loadbalancer/src/test/java/org/springframework/cloud/kubernetes/fabric8/loadbalancer/KubernetesServiceListSupplierTests.java index 9e46346688..f50f935416 100644 --- a/spring-cloud-kubernetes-fabric8-loadbalancer/src/test/java/org/springframework/cloud/kubernetes/fabric8/loadbalancer/KubernetesServiceListSupplierTests.java +++ b/spring-cloud-kubernetes-fabric8-loadbalancer/src/test/java/org/springframework/cloud/kubernetes/fabric8/loadbalancer/KubernetesServiceListSupplierTests.java @@ -97,7 +97,7 @@ void testPositiveMatchAllNamespaces() { when(this.multiDeletable.list()).thenReturn(serviceList); KubernetesDiscoveryProperties discoveryProperties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, false, null, Set.of(), Map.of(), null, KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, - false); + false, false); KubernetesServicesListSupplier supplier = new Fabric8ServicesListSupplier(environment, client, mapper, discoveryProperties); List instances = supplier.get().blockFirst(); From c54896ca7720e1691b5aaf2c921318a324207003 Mon Sep 17 00:00:00 2001 From: wind57 Date: Mon, 27 Feb 2023 23:34:10 +0200 Subject: [PATCH 039/151] trigger build From f179e7063557bdfe2e56e6006dd60169bd4a3360 Mon Sep 17 00:00:00 2001 From: wind57 Date: Tue, 28 Feb 2023 09:46:04 +0200 Subject: [PATCH 040/151] trigger build From f963d58acef89585cca864a228c1756e1962e539 Mon Sep 17 00:00:00 2001 From: wind57 Date: Tue, 28 Feb 2023 16:01:58 +0200 Subject: [PATCH 041/151] add-integration-tests --- ...ubernetesExternalNameServiceInstance.java} | 16 ++++-- ...netesExternalNameServiceInstanceTests.java | 42 ++++++++++++++ .../discovery/KubernetesDiscoveryClient.java | 2 +- .../KubernetesDiscoveryClientUtils.java | 8 +-- .../KubernetesDiscoveryClientTests.java | 6 +- .../configmap/Fabric8DiscoveryController.java | 6 ++ .../fabric8/configmap/Fabric8DiscoveryIT.java | 57 +++++++++++++++++-- .../test/resources/external-name-service.yaml | 7 +++ .../tests/commons/fabric8_client/Util.java | 40 ++++++++----- 9 files changed, 151 insertions(+), 33 deletions(-) rename spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/{ExternalNameServiceInstance.java => KubernetesExternalNameServiceInstance.java} (80%) create mode 100644 spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/discovery/KubernetesExternalNameServiceInstanceTests.java create mode 100644 spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/test/resources/external-name-service.yaml diff --git a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/ExternalNameServiceInstance.java b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/KubernetesExternalNameServiceInstance.java similarity index 80% rename from spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/ExternalNameServiceInstance.java rename to spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/KubernetesExternalNameServiceInstance.java index 93e7a03cef..9db93b5d7f 100644 --- a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/ExternalNameServiceInstance.java +++ b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/KubernetesExternalNameServiceInstance.java @@ -27,16 +27,17 @@ * * @author wind57 */ -public record ExternalNameServiceInstance(DefaultKubernetesServiceInstance defaultInstance) implements ServiceInstance { +public record KubernetesExternalNameServiceInstance(String serviceId, String host, String instanceId, + Map metadata) implements ServiceInstance { @Override public String getServiceId() { - return defaultInstance().serviceId(); + return serviceId; } @Override public String getHost() { - return defaultInstance.getHost(); + return host; } @Override @@ -51,15 +52,20 @@ public boolean isSecure() { @Override public URI getUri() { - return URI.create(defaultInstance().getHost()); + return URI.create(host); } @Override public Map getMetadata() { - return defaultInstance.metadata(); + return metadata; + } + + public String getInstanceId() { + return instanceId; } public String type() { return "ExternalName"; } + } diff --git a/spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/discovery/KubernetesExternalNameServiceInstanceTests.java b/spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/discovery/KubernetesExternalNameServiceInstanceTests.java new file mode 100644 index 0000000000..a4f2d60c6d --- /dev/null +++ b/spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/discovery/KubernetesExternalNameServiceInstanceTests.java @@ -0,0 +1,42 @@ +/* + * Copyright 2013-2023 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.commons.discovery; + +import java.util.Map; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +/** + * @author wind57 + */ +class KubernetesExternalNameServiceInstanceTests { + + @Test + void testFields() { + KubernetesExternalNameServiceInstance instance = new KubernetesExternalNameServiceInstance("123", "spring.io", + "456", Map.of("a", "b")); + Assertions.assertEquals(instance.getInstanceId(), "456"); + Assertions.assertEquals(instance.getServiceId(), "123"); + Assertions.assertEquals(instance.getHost(), "spring.io"); + Assertions.assertEquals(instance.getPort(), -1); + Assertions.assertEquals(instance.getMetadata(), Map.of("a", "b")); + Assertions.assertNull(instance.getScheme()); + Assertions.assertEquals(instance.getUri().toASCIIString(), "spring.io"); + } + +} diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java index 017b2aff94..70f5ee848c 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClient.java @@ -47,7 +47,7 @@ import static org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientUtils.services; /** - * Kubernetes implementation of {@link DiscoveryClient}. + * Fabric8 Kubernetes implementation of {@link DiscoveryClient}. * * @author Ioannis Canellos * @author Tim Ysewyn diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtils.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtils.java index 113271eaff..25b14a3f68 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtils.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtils.java @@ -43,8 +43,8 @@ import org.springframework.cloud.client.ServiceInstance; import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider; import org.springframework.cloud.kubernetes.commons.discovery.DefaultKubernetesServiceInstance; -import org.springframework.cloud.kubernetes.commons.discovery.ExternalNameServiceInstance; import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; +import org.springframework.cloud.kubernetes.commons.discovery.KubernetesExternalNameServiceInstance; import org.springframework.cloud.kubernetes.fabric8.Fabric8Utils; import org.springframework.core.log.LogAccessor; import org.springframework.util.CollectionUtils; @@ -235,10 +235,8 @@ static List addresses(EndpointSubset endpointSubset, Kubernetes static ServiceInstance externalNameServiceInstance(Service service, String serviceId, Map serviceMetadata) { - DefaultKubernetesServiceInstance defaultKubernetesServiceInstance = new DefaultKubernetesServiceInstance( - service.getMetadata().getUid(), serviceId, service.getSpec().getExternalName(), -1, serviceMetadata, - false, service.getMetadata().getNamespace(), null); - return new ExternalNameServiceInstance(defaultKubernetesServiceInstance); + return new KubernetesExternalNameServiceInstance(serviceId, service.getSpec().getExternalName(), + service.getMetadata().getUid(), serviceMetadata); } static ServiceInstance serviceInstance(ServicePortSecureResolver servicePortSecureResolver, Service service, diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientTests.java index 9ef62594c0..8bd5804eab 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientTests.java @@ -39,8 +39,8 @@ import org.springframework.boot.test.system.CapturedOutput; import org.springframework.boot.test.system.OutputCaptureExtension; import org.springframework.cloud.client.ServiceInstance; -import org.springframework.cloud.kubernetes.commons.discovery.ExternalNameServiceInstance; import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; +import org.springframework.cloud.kubernetes.commons.discovery.KubernetesExternalNameServiceInstance; /** * @author wind57 @@ -65,6 +65,7 @@ static void setUp() { @AfterEach void afterEach() { client.endpoints().inAnyNamespace().delete(); + client.services().inAnyNamespace().delete(); } /** @@ -519,7 +520,8 @@ void testExternalNameService() { KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null); List result = discoveryClient.getInstances("blue-service"); Assertions.assertEquals(result.size(), 1); - ExternalNameServiceInstance externalNameServiceInstance = (ExternalNameServiceInstance) result.get(0); + KubernetesExternalNameServiceInstance externalNameServiceInstance = (KubernetesExternalNameServiceInstance) result + .get(0); Assertions.assertEquals(externalNameServiceInstance.getServiceId(), "blue-service"); Assertions.assertEquals(externalNameServiceInstance.getHost(), "k8s-spring-b"); Assertions.assertEquals(externalNameServiceInstance.getPort(), -1); diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/configmap/Fabric8DiscoveryController.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/configmap/Fabric8DiscoveryController.java index 7cf7d06ee4..430901f1bf 100644 --- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/configmap/Fabric8DiscoveryController.java +++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/configmap/Fabric8DiscoveryController.java @@ -20,6 +20,7 @@ import io.fabric8.kubernetes.api.model.Endpoints; +import org.springframework.cloud.client.ServiceInstance; import org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClient; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -47,4 +48,9 @@ public List getEndPointsList(@PathVariable("serviceId") String servic return discoveryClient.getEndPointsList(serviceId); } + @GetMapping("/service-instances/{serviceId}") + public List serviceInstances(@PathVariable("serviceId") String serviceId) { + return discoveryClient.getInstances(serviceId); + } + } diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/configmap/Fabric8DiscoveryIT.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/configmap/Fabric8DiscoveryIT.java index cf84a3725e..68899d95e6 100644 --- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/configmap/Fabric8DiscoveryIT.java +++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/configmap/Fabric8DiscoveryIT.java @@ -18,9 +18,13 @@ import java.io.InputStream; import java.time.Duration; +import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.Objects; +import io.fabric8.kubernetes.api.model.EnvVar; +import io.fabric8.kubernetes.api.model.EnvVarBuilder; import io.fabric8.kubernetes.api.model.Service; import io.fabric8.kubernetes.api.model.apps.Deployment; import io.fabric8.kubernetes.api.model.networking.v1.Ingress; @@ -29,14 +33,17 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import org.springframework.cloud.kubernetes.commons.discovery.KubernetesExternalNameServiceInstance; import org.testcontainers.k3s.K3sContainer; import reactor.netty.http.client.HttpClient; import reactor.util.retry.Retry; import reactor.util.retry.RetryBackoffSpec; +import org.springframework.cloud.client.ServiceInstance; import org.springframework.cloud.kubernetes.integration.tests.commons.Commons; import org.springframework.cloud.kubernetes.integration.tests.commons.Phase; import org.springframework.cloud.kubernetes.integration.tests.commons.fabric8_client.Util; +import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.HttpMethod; import org.springframework.http.client.reactive.ReactorClientHttpConnector; import org.springframework.web.reactive.function.client.WebClient; @@ -78,18 +85,44 @@ static void after() throws Exception { Commons.cleanUp(IMAGE_NAME, K3S); } + /** + * KubernetesDiscoveryClient::getServices call must include the external-name-service + * also. + */ @Test - void test() { + void testAllServices() { WebClient client = builder().baseUrl("localhost/services").build(); - @SuppressWarnings("unchecked") - List result = (List) client.method(HttpMethod.GET).retrieve().bodyToMono(List.class) - .retryWhen(retrySpec()).block(); + List result = client.method(HttpMethod.GET).retrieve() + .bodyToMono(new ParameterizedTypeReference>() { - Assertions.assertEquals(result.size(), 3); + }).retryWhen(retrySpec()).block(); + + Assertions.assertEquals(result.size(), 4); Assertions.assertTrue(result.contains("kubernetes")); Assertions.assertTrue(result.contains("spring-cloud-kubernetes-fabric8-client-discovery")); Assertions.assertTrue(result.contains("service-wiremock")); + Assertions.assertTrue(result.contains("external-name-service")); + } + + @Test + void testExternalNameServiceInstance() { + + WebClient client = builder().baseUrl("localhost/service-instances/external-name-service").build(); + List serviceInstances = client.method(HttpMethod.GET).retrieve() + .bodyToMono(new ParameterizedTypeReference>() { + + }).retryWhen(retrySpec()).block(); + + Assertions.assertEquals(serviceInstances.size(), 1); + Assertions.assertEquals(serviceInstances.get(0).getServiceId(), "external-name-service"); + Assertions.assertNotNull(serviceInstances.get(0).getInstanceId()); + Assertions.assertEquals(serviceInstances.get(0).getHost(), "spring.io"); + Assertions.assertEquals(serviceInstances.get(0).getPort(), -1); + Assertions.assertEquals(serviceInstances.get(0).getMetadata(), Map.of("k8s_namespace", "default")); + Assertions.assertFalse(serviceInstances.get(0).isSecure()); + Assertions.assertEquals(serviceInstances.get(0).getUri().toASCIIString(), "spring.io"); + Assertions.assertNull(serviceInstances.get(0).getScheme()); } private static void manifests(Phase phase) { @@ -97,16 +130,30 @@ private static void manifests(Phase phase) { InputStream deploymentStream = util.inputStream("fabric8-discovery-deployment.yaml"); InputStream serviceStream = util.inputStream("fabric8-discovery-service.yaml"); InputStream ingressStream = util.inputStream("fabric8-discovery-ingress.yaml"); + InputStream externalNameServiceInputStream = util.inputStream("external-name-service.yaml"); Deployment deployment = client.apps().deployments().load(deploymentStream).get(); + + List existing = new ArrayList<>( + deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getEnv()); + existing.add(new EnvVarBuilder().withName("SPRING_CLOUD_KUBERNETES_DISCOVERY_INCLUDEEXTERNALNAMESERVICES") + .withValue("true").build()); + existing.add( + new EnvVarBuilder().withName("LOGGING_LEVEL_ORG_SPRINGFRAMEWORK_CLOUD_KUBERNETES_FABRIC8_DISCOVERY") + .withValue("DEBUG").build()); + deployment.getSpec().getTemplate().getSpec().getContainers().get(0).setEnv(existing); + Service service = client.services().load(serviceStream).get(); + Service externalNameService = client.services().load(externalNameServiceInputStream).get(); Ingress ingress = client.network().v1().ingresses().load(ingressStream).get(); if (phase.equals(Phase.CREATE)) { util.createAndWait(NAMESPACE, null, deployment, service, ingress, true); + util.createAndWait(NAMESPACE, null, null, externalNameService, null, false); } else { util.deleteAndWait(NAMESPACE, deployment, service, ingress); + util.deleteAndWait(NAMESPACE, null, externalNameService, null); } } diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/test/resources/external-name-service.yaml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/test/resources/external-name-service.yaml new file mode 100644 index 0000000000..649d5da75c --- /dev/null +++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/test/resources/external-name-service.yaml @@ -0,0 +1,7 @@ +kind: Service +apiVersion: v1 +metadata: + name: external-name-service +spec: + type: ExternalName + externalName: spring.io diff --git a/spring-cloud-kubernetes-test-support/src/main/java/org/springframework/cloud/kubernetes/integration/tests/commons/fabric8_client/Util.java b/spring-cloud-kubernetes-test-support/src/main/java/org/springframework/cloud/kubernetes/integration/tests/commons/fabric8_client/Util.java index 5e2469d8f7..748f6203d9 100644 --- a/spring-cloud-kubernetes-test-support/src/main/java/org/springframework/cloud/kubernetes/integration/tests/commons/fabric8_client/Util.java +++ b/spring-cloud-kubernetes-test-support/src/main/java/org/springframework/cloud/kubernetes/integration/tests/commons/fabric8_client/Util.java @@ -74,24 +74,29 @@ public Util(K3sContainer container) { * tight as possible, providing reasonable defaults. * */ - public void createAndWait(String namespace, String name, Deployment deployment, Service service, + public void createAndWait(String namespace, String name, @Nullable Deployment deployment, Service service, @Nullable Ingress ingress, boolean changeVersion) { try { - String imageFromDeployment = deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getImage(); - if (changeVersion) { - deployment.getSpec().getTemplate().getSpec().getContainers().get(0) - .setImage(imageFromDeployment + ":" + pomVersion()); - } - else { - String[] image = imageFromDeployment.split(":", 2); - pullImage(image[0], image[1], container); - loadImage(image[0], image[1], name, container); + if (deployment != null) { + String imageFromDeployment = deployment.getSpec().getTemplate().getSpec().getContainers().get(0) + .getImage(); + if (changeVersion) { + deployment.getSpec().getTemplate().getSpec().getContainers().get(0) + .setImage(imageFromDeployment + ":" + pomVersion()); + } + else { + String[] image = imageFromDeployment.split(":", 2); + pullImage(image[0], image[1], container); + loadImage(image[0], image[1], name, container); + } + + client.apps().deployments().inNamespace(namespace).resource(deployment).create(); + waitForDeployment(namespace, deployment); } - client.apps().deployments().inNamespace(namespace).resource(deployment).create(); client.services().inNamespace(namespace).resource(service).create(); - waitForDeployment(namespace, deployment); + if (ingress != null) { client.network().v1().ingresses().inNamespace(namespace).resource(ingress).create(); waitForIngress(namespace, ingress); @@ -116,11 +121,16 @@ else if (phase.equals(Phase.DELETE)) { } } - public void deleteAndWait(String namespace, Deployment deployment, Service service, @Nullable Ingress ingress) { + public void deleteAndWait(String namespace, @Nullable Deployment deployment, Service service, + @Nullable Ingress ingress) { try { - client.apps().deployments().inNamespace(namespace).resource(deployment).delete(); + + if (deployment != null) { + client.apps().deployments().inNamespace(namespace).resource(deployment).delete(); + waitForDeploymentToBeDeleted(namespace, deployment); + } + client.services().inNamespace(namespace).resource(service).delete(); - waitForDeploymentToBeDeleted(namespace, deployment); if (ingress != null) { client.network().v1().ingresses().inNamespace(namespace).resource(ingress).delete(); From 4f15edb0cf13f58748476b787bb22044be52f53c Mon Sep 17 00:00:00 2001 From: wind57 Date: Tue, 28 Feb 2023 16:03:52 +0200 Subject: [PATCH 042/151] fix --- .../discovery/KubernetesExternalNameServiceInstance.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/KubernetesExternalNameServiceInstance.java b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/KubernetesExternalNameServiceInstance.java index 9db93b5d7f..559dcdfba4 100644 --- a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/KubernetesExternalNameServiceInstance.java +++ b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/KubernetesExternalNameServiceInstance.java @@ -23,7 +23,7 @@ /** * Type of {@link org.springframework.cloud.client.ServiceInstance} when - * "spec.type=ServiceInstance". + * "spec.type=ExternalName". * * @author wind57 */ From bb29cba0ff9111ef40b5d2cdf6702537af5af7cc Mon Sep 17 00:00:00 2001 From: wind57 Date: Tue, 28 Feb 2023 16:07:46 +0200 Subject: [PATCH 043/151] fix --- .../fabric8/configmap/Fabric8DiscoveryIT.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/configmap/Fabric8DiscoveryIT.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/configmap/Fabric8DiscoveryIT.java index 68899d95e6..9afb2a954e 100644 --- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/configmap/Fabric8DiscoveryIT.java +++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/configmap/Fabric8DiscoveryIT.java @@ -114,15 +114,18 @@ void testExternalNameServiceInstance() { }).retryWhen(retrySpec()).block(); + KubernetesExternalNameServiceInstance result = serviceInstances.get(0); + Assertions.assertEquals(serviceInstances.size(), 1); - Assertions.assertEquals(serviceInstances.get(0).getServiceId(), "external-name-service"); - Assertions.assertNotNull(serviceInstances.get(0).getInstanceId()); - Assertions.assertEquals(serviceInstances.get(0).getHost(), "spring.io"); - Assertions.assertEquals(serviceInstances.get(0).getPort(), -1); - Assertions.assertEquals(serviceInstances.get(0).getMetadata(), Map.of("k8s_namespace", "default")); - Assertions.assertFalse(serviceInstances.get(0).isSecure()); - Assertions.assertEquals(serviceInstances.get(0).getUri().toASCIIString(), "spring.io"); - Assertions.assertNull(serviceInstances.get(0).getScheme()); + Assertions.assertEquals(result.getServiceId(), "external-name-service"); + Assertions.assertNotNull(result.getInstanceId()); + Assertions.assertEquals(result.getHost(), "spring.io"); + Assertions.assertEquals(result.getPort(), -1); + Assertions.assertEquals(result.getMetadata(), Map.of("k8s_namespace", "default")); + Assertions.assertFalse(result.isSecure()); + Assertions.assertEquals(result.getUri().toASCIIString(), "spring.io"); + Assertions.assertNull(result.getScheme()); + Assertions.assertEquals(result.type(), "ExternalName"); } private static void manifests(Phase phase) { From bf63081b4652457fdda721684ab395a63cf9d2cf Mon Sep 17 00:00:00 2001 From: wind57 Date: Tue, 28 Feb 2023 16:08:33 +0200 Subject: [PATCH 044/151] fix --- .../discovery/KubernetesExternalNameServiceInstanceTests.java | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/discovery/KubernetesExternalNameServiceInstanceTests.java b/spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/discovery/KubernetesExternalNameServiceInstanceTests.java index a4f2d60c6d..3a8e1f8a05 100644 --- a/spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/discovery/KubernetesExternalNameServiceInstanceTests.java +++ b/spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/discovery/KubernetesExternalNameServiceInstanceTests.java @@ -37,6 +37,7 @@ void testFields() { Assertions.assertEquals(instance.getMetadata(), Map.of("a", "b")); Assertions.assertNull(instance.getScheme()); Assertions.assertEquals(instance.getUri().toASCIIString(), "spring.io"); + Assertions.assertEquals(instance.type(), "ExternalName"); } } From 1f51e2c95cef3c49213c27df728edd919e83f847 Mon Sep 17 00:00:00 2001 From: wind57 Date: Tue, 28 Feb 2023 16:13:16 +0200 Subject: [PATCH 045/151] fix --- .../cloud/kubernetes/fabric8/configmap/Fabric8DiscoveryIT.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/configmap/Fabric8DiscoveryIT.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/configmap/Fabric8DiscoveryIT.java index 9afb2a954e..3fc9954b1b 100644 --- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/configmap/Fabric8DiscoveryIT.java +++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/configmap/Fabric8DiscoveryIT.java @@ -33,13 +33,12 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import org.springframework.cloud.kubernetes.commons.discovery.KubernetesExternalNameServiceInstance; import org.testcontainers.k3s.K3sContainer; import reactor.netty.http.client.HttpClient; import reactor.util.retry.Retry; import reactor.util.retry.RetryBackoffSpec; -import org.springframework.cloud.client.ServiceInstance; +import org.springframework.cloud.kubernetes.commons.discovery.KubernetesExternalNameServiceInstance; import org.springframework.cloud.kubernetes.integration.tests.commons.Commons; import org.springframework.cloud.kubernetes.integration.tests.commons.Phase; import org.springframework.cloud.kubernetes.integration.tests.commons.fabric8_client.Util; From 618f25aeccb763010ba7777653994148514c8d99 Mon Sep 17 00:00:00 2001 From: erabii Date: Tue, 14 Mar 2023 10:39:50 +0200 Subject: [PATCH 046/151] Delete renovate.json --- renovate.json | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 renovate.json diff --git a/renovate.json b/renovate.json deleted file mode 100644 index 7bd954555f..0000000000 --- a/renovate.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "$schema": "https://docs.renovatebot.com/renovate-schema.json", - "extends": [ - "config:base" - ] -} From 100a9cd110d5c5e614573d8c3726b21788c1b550 Mon Sep 17 00:00:00 2001 From: erabii Date: Tue, 14 Mar 2023 10:40:02 +0200 Subject: [PATCH 047/151] Delete delme.sh --- delme.sh | 1 - 1 file changed, 1 deletion(-) delete mode 100644 delme.sh diff --git a/delme.sh b/delme.sh deleted file mode 100644 index 707d90cb73..0000000000 --- a/delme.sh +++ /dev/null @@ -1 +0,0 @@ -dadsa \ No newline at end of file From 4da9615017819274629ad5bb6023d3c36a9096ea Mon Sep 17 00:00:00 2001 From: wind57 Date: Fri, 17 Mar 2023 07:21:03 +0200 Subject: [PATCH 048/151] trigger build From dc84468dcb97201c89dd02d92904f1561bd0be9a Mon Sep 17 00:00:00 2001 From: wind57 Date: Mon, 20 Mar 2023 07:48:42 +0200 Subject: [PATCH 049/151] formatting --- ...Fabric8KubernetesDiscoveryClientUtils.java | 1 - .../Fabric8KubernetesDiscoveryClientTest.java | 17 ++-- ...c8KubernetesDiscoveryClientUtilsTests.java | 99 ++++++++++--------- 3 files changed, 58 insertions(+), 59 deletions(-) diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtils.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtils.java index cc68d592b3..1ded911dd0 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtils.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtils.java @@ -394,7 +394,6 @@ private static List filteredEndpointSlices( } - private static Optional fromMap(Map existingPorts, String key, String message) { Integer fromPrimaryPortName = existingPorts.get(key); diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientTest.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientTest.java index 66167fc17d..98bf780245 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientTest.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientTest.java @@ -560,29 +560,29 @@ public void instanceWithoutPorts() { Map labels = new HashMap<>(); Endpoints endPoint1 = new EndpointsBuilder().withNewMetadata().withName("endpoint5").withNamespace("test") - .withLabels(labels).endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef() - .withUid("130").endTargetRef().endAddress().endSubset().build(); + .withLabels(labels).endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef() + .withUid("130").endTargetRef().endAddress().endSubset().build(); mockClient.endpoints().inNamespace("test").create(endPoint1); Service service = new ServiceBuilder().withSpec(new ServiceSpecBuilder().withType("ClusterIP").build()) - .withNewMetadata().withName("endpoint5").withNamespace("test").withLabels(labels) - .withAnnotations(labels).endMetadata().build(); + .withNewMetadata().withName("endpoint5").withNamespace("test").withLabels(labels) + .withAnnotations(labels).endMetadata().build(); mockClient.services().inNamespace("test").create(service); final KubernetesDiscoveryProperties properties = KubernetesDiscoveryProperties.DEFAULT; final DiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, properties, - new ServicePortSecureResolver(properties), NAMESPACE_PROVIDER, x -> true); + new ServicePortSecureResolver(properties), NAMESPACE_PROVIDER, x -> true); final List instances = discoveryClient.getInstances("endpoint5"); // We're returning the first discovered port to not change previous behaviour assertThat(instances).hasSize(1).filteredOn(s -> s.getHost().equals("ip1") && !s.isSecure()).hasSize(1) - .filteredOn(s -> s.getUri().toASCIIString().equals("http://ip1")) - .filteredOn(s -> s.getInstanceId().equals("130")).hasSize(1).filteredOn(s -> 0 == s.getPort()) - .hasSize(1); + .filteredOn(s -> s.getUri().toASCIIString().equals("http://ip1")) + .filteredOn(s -> s.getInstanceId().equals("130")).hasSize(1).filteredOn(s -> 0 == s.getPort()) + .hasSize(1); } private static Environment mockEnvironment() { @@ -591,5 +591,4 @@ private static Environment mockEnvironment() { return environment; } - } diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtilsTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtilsTests.java index 9f57734ed5..2f565936fd 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtilsTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtilsTests.java @@ -196,13 +196,13 @@ void testPrimaryPortNameFoundInBothPropertiesAndLabels(CapturedOutput output) { @Test void testEndpointsPortSinglePort(CapturedOutput output) { EndpointSubset endpointSubset = new EndpointSubsetBuilder() - .withPorts(new EndpointPortBuilder().withPort(8080).withName("http").build()).build(); + .withPorts(new EndpointPortBuilder().withPort(8080).withName("http").build()).build(); String serviceId = "spring-k8s"; KubernetesDiscoveryProperties properties = KubernetesDiscoveryProperties.DEFAULT; Service service = new ServiceBuilder().build(); Fabric8ServicePortData portData = Fabric8KubernetesDiscoveryClientUtils.endpointsPort(endpointSubset, serviceId, - properties, service); + properties, service); Assertions.assertEquals(portData.portNumber(), 8080); Assertions.assertEquals(portData.portName(), "http"); Assertions.assertTrue(output.getOut().contains("endpoint ports has a single entry, using port : 8080")); @@ -216,21 +216,21 @@ void testEndpointsPortSinglePort(CapturedOutput output) { @Test void testEndpointsPortNullPrimaryPortName(CapturedOutput output) { EndpointSubset endpointSubset = new EndpointSubsetBuilder() - .withPorts(new EndpointPortBuilder().withPort(8080).build(), - new EndpointPortBuilder().withPort(8081).build()) - .build(); + .withPorts(new EndpointPortBuilder().withPort(8080).build(), + new EndpointPortBuilder().withPort(8081).build()) + .build(); String serviceId = "spring-k8s"; KubernetesDiscoveryProperties properties = KubernetesDiscoveryProperties.DEFAULT; Service service = new ServiceBuilder().withMetadata(new ObjectMeta()).build(); Fabric8ServicePortData portData = Fabric8KubernetesDiscoveryClientUtils.endpointsPort(endpointSubset, serviceId, - properties, service); + properties, service); Assertions.assertEquals(portData.portNumber(), 8080); Assertions.assertNull(portData.portName()); Assertions.assertTrue(output.getOut().contains( - "did not find a primary-port-name in neither properties nor service labels for service with ID : spring-k8s")); + "did not find a primary-port-name in neither properties nor service labels for service with ID : spring-k8s")); Assertions.assertTrue(output.getOut() - .contains("not found primary-port-name (with value: 'null') via properties or service labels")); + .contains("not found primary-port-name (with value: 'null') via properties or service labels")); Assertions.assertTrue(output.getOut().contains("not found primary-port-name via 'https' to match port")); Assertions.assertTrue(output.getOut().contains("not found primary-port-name via 'http' to match port")); Assertions.assertTrue(output.getOut().contains(""" @@ -248,25 +248,25 @@ void testEndpointsPortNullPrimaryPortName(CapturedOutput output) { @Test void testEndpointsPortPrimaryPortNameIsPresentButNotFound(CapturedOutput output) { EndpointSubset endpointSubset = new EndpointSubsetBuilder() - .withPorts(new EndpointPortBuilder().withPort(8080).withName("one").build(), - new EndpointPortBuilder().withPort(8081).withName("two").build()) - .build(); + .withPorts(new EndpointPortBuilder().withPort(8080).withName("one").build(), + new EndpointPortBuilder().withPort(8081).withName("two").build()) + .build(); String serviceId = "spring-k8s"; String primaryPortName = "three"; KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - true, "", Set.of(), Map.of(), primaryPortName, null, 0, false); + true, "", Set.of(), Map.of(), primaryPortName, null, 0, false); Service service = new ServiceBuilder().withMetadata(new ObjectMeta()).build(); Fabric8ServicePortData portData = Fabric8KubernetesDiscoveryClientUtils.endpointsPort(endpointSubset, serviceId, - properties, service); + properties, service); Assertions.assertEquals(portData.portNumber(), 8080); Assertions.assertEquals(portData.portName(), "one"); Assertions.assertTrue( - output.getOut().contains("will use primaryPortName : three for service with ID = spring-k8s")); + output.getOut().contains("will use primaryPortName : three for service with ID = spring-k8s")); Assertions.assertTrue(output.getOut() - .contains("not found primary-port-name (with value: 'three') via properties or service labels")); + .contains("not found primary-port-name (with value: 'three') via properties or service labels")); Assertions.assertTrue(output.getOut().contains("not found primary-port-name via 'https' to match port")); Assertions.assertTrue(output.getOut().contains("not found primary-port-name via 'http' to match port")); Assertions.assertTrue(output.getOut().contains(""" @@ -284,25 +284,25 @@ void testEndpointsPortPrimaryPortNameIsPresentButNotFound(CapturedOutput output) @Test void testEndpointsPortPrimaryPortNameFound(CapturedOutput output) { EndpointSubset endpointSubset = new EndpointSubsetBuilder() - .withPorts(new EndpointPortBuilder().withPort(8080).withName("one").build(), - new EndpointPortBuilder().withPort(8081).withName("two").build()) - .build(); + .withPorts(new EndpointPortBuilder().withPort(8080).withName("one").build(), + new EndpointPortBuilder().withPort(8081).withName("two").build()) + .build(); String serviceId = "spring-k8s"; String primaryPortName = "two"; KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - true, "", Set.of(), Map.of(), primaryPortName, null, 0, false); + true, "", Set.of(), Map.of(), primaryPortName, null, 0, false); Service service = new ServiceBuilder().withMetadata(new ObjectMeta()).build(); Fabric8ServicePortData portData = Fabric8KubernetesDiscoveryClientUtils.endpointsPort(endpointSubset, serviceId, - properties, service); + properties, service); Assertions.assertEquals(portData.portNumber(), 8081); Assertions.assertEquals(portData.portName(), "two"); Assertions.assertTrue( - output.getOut().contains("will use primaryPortName : two for service with ID = spring-k8s")); + output.getOut().contains("will use primaryPortName : two for service with ID = spring-k8s")); Assertions.assertTrue(output.getOut().contains( - "found primary-port-name (with value: 'two') via properties or service labels to match port : 8081")); + "found primary-port-name (with value: 'two') via properties or service labels to match port : 8081")); } /** @@ -314,26 +314,26 @@ void testEndpointsPortPrimaryPortNameFound(CapturedOutput output) { @Test void testEndpointsPortPrimaryPortHttps(CapturedOutput output) { EndpointSubset endpointSubset = new EndpointSubsetBuilder() - .withPorts(new EndpointPortBuilder().withPort(8080).withName("one").build(), - new EndpointPortBuilder().withPort(8081).withName("two").build(), - new EndpointPortBuilder().withPort(8082).withName("https").build()) - .build(); + .withPorts(new EndpointPortBuilder().withPort(8080).withName("one").build(), + new EndpointPortBuilder().withPort(8081).withName("two").build(), + new EndpointPortBuilder().withPort(8082).withName("https").build()) + .build(); String serviceId = "spring-k8s"; String primaryPortName = "three"; KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - true, "", Set.of(), Map.of(), primaryPortName, null, 0, false, false); + true, "", Set.of(), Map.of(), primaryPortName, null, 0, false, false); Service service = new ServiceBuilder().withMetadata(new ObjectMeta()).build(); Fabric8ServicePortData portData = Fabric8KubernetesDiscoveryClientUtils.endpointsPort(endpointSubset, serviceId, - properties, service); + properties, service); Assertions.assertEquals(portData.portNumber(), 8082); Assertions.assertEquals(portData.portName(), "https"); Assertions.assertTrue( - output.getOut().contains("will use primaryPortName : three for service with ID = spring-k8s")); + output.getOut().contains("will use primaryPortName : three for service with ID = spring-k8s")); Assertions.assertTrue(output.getOut().contains( - "not found primary-port-name (with value: 'three') via properties or service labels to match port")); + "not found primary-port-name (with value: 'three') via properties or service labels to match port")); Assertions.assertTrue(output.getOut().contains("found primary-port-name via 'https' to match port : 8082")); } @@ -346,26 +346,26 @@ void testEndpointsPortPrimaryPortHttps(CapturedOutput output) { @Test void testEndpointsPortPrimaryPortHttp(CapturedOutput output) { EndpointSubset endpointSubset = new EndpointSubsetBuilder() - .withPorts(new EndpointPortBuilder().withPort(8080).withName("one").build(), - new EndpointPortBuilder().withPort(8081).withName("two").build(), - new EndpointPortBuilder().withPort(8082).withName("http").build()) - .build(); + .withPorts(new EndpointPortBuilder().withPort(8080).withName("one").build(), + new EndpointPortBuilder().withPort(8081).withName("two").build(), + new EndpointPortBuilder().withPort(8082).withName("http").build()) + .build(); String serviceId = "spring-k8s"; String primaryPortName = "three"; KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - true, "", Set.of(), Map.of(), primaryPortName, null, 0, false); + true, "", Set.of(), Map.of(), primaryPortName, null, 0, false); Service service = new ServiceBuilder().withMetadata(new ObjectMeta()).build(); Fabric8ServicePortData portData = Fabric8KubernetesDiscoveryClientUtils.endpointsPort(endpointSubset, serviceId, - properties, service); + properties, service); Assertions.assertEquals(portData.portNumber(), 8082); Assertions.assertEquals(portData.portName(), "http"); Assertions.assertTrue( - output.getOut().contains("will use primaryPortName : three for service with ID = spring-k8s")); + output.getOut().contains("will use primaryPortName : three for service with ID = spring-k8s")); Assertions.assertTrue(output.getOut().contains( - "not found primary-port-name (with value: 'three') via properties or service labels to match port")); + "not found primary-port-name (with value: 'three') via properties or service labels to match port")); Assertions.assertTrue(output.getOut().contains("found primary-port-name via 'http' to match port : 8082")); } @@ -757,15 +757,15 @@ void testBothAddressesTaken() { @Test void testServiceInstance() { KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - false, "", Set.of(), Map.of(), "", KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, false, false); + false, "", Set.of(), Map.of(), "", KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, false, false); ServicePortSecureResolver resolver = new ServicePortSecureResolver(properties); Service service = new ServiceBuilder().withMetadata(new ObjectMeta()).build(); EndpointAddress address = new EndpointAddressBuilder().withNewTargetRef().withUid("123").endTargetRef() - .withIp("127.0.0.1").build(); + .withIp("127.0.0.1").build(); Fabric8ServicePortData portData = new Fabric8ServicePortData(8080, "http"); - ServiceInstance serviceInstance = Fabric8KubernetesDiscoveryClientUtils.serviceInstance(resolver, service, address, - portData, "my-service", Map.of("a", "b"), "k8s", properties, null); + ServiceInstance serviceInstance = Fabric8KubernetesDiscoveryClientUtils.serviceInstance(resolver, service, + address, portData, "my-service", Map.of("a", "b"), "k8s", properties, null); Assertions.assertTrue(serviceInstance instanceof DefaultKubernetesServiceInstance); DefaultKubernetesServiceInstance defaultInstance = (DefaultKubernetesServiceInstance) serviceInstance; Assertions.assertEquals(defaultInstance.getInstanceId(), "123"); @@ -980,12 +980,12 @@ private KubernetesNamespaceProvider namespaceProvider(String namespace) { @Test void testExternalNameServiceInstance() { Service service = new ServiceBuilder() - .withSpec(new ServiceSpecBuilder().withExternalName("spring.io").withType("ExternalName").build()) - .withMetadata(new ObjectMetaBuilder().withUid("123").build()).build(); + .withSpec(new ServiceSpecBuilder().withExternalName("spring.io").withType("ExternalName").build()) + .withMetadata(new ObjectMetaBuilder().withUid("123").build()).build(); Fabric8ServicePortData portData = new Fabric8ServicePortData(-1, "http"); - ServiceInstance serviceInstance = Fabric8KubernetesDiscoveryClientUtils.serviceInstance(null, service, null, portData, - "my-service", Map.of("a", "b"), "k8s", KubernetesDiscoveryProperties.DEFAULT, null); + ServiceInstance serviceInstance = Fabric8KubernetesDiscoveryClientUtils.serviceInstance(null, service, null, + portData, "my-service", Map.of("a", "b"), "k8s", KubernetesDiscoveryProperties.DEFAULT, null); Assertions.assertTrue(serviceInstance instanceof DefaultKubernetesServiceInstance); DefaultKubernetesServiceInstance defaultInstance = (DefaultKubernetesServiceInstance) serviceInstance; Assertions.assertEquals(defaultInstance.getInstanceId(), "123"); @@ -1003,13 +1003,14 @@ void testExternalNameServiceInstance() { @Test void testNoPortsServiceInstance() { Service service = new ServiceBuilder().withSpec(new ServiceSpecBuilder().withType("ClusterIP").build()) - .withMetadata(new ObjectMetaBuilder().withUid("123").build()).build(); + .withMetadata(new ObjectMetaBuilder().withUid("123").build()).build(); EndpointAddress endpointAddress = new EndpointAddressBuilder().withIp("127.0.0.1").build(); Fabric8ServicePortData portData = new Fabric8ServicePortData(0, "http"); - ServiceInstance serviceInstance = Fabric8KubernetesDiscoveryClientUtils.serviceInstance(null, service, endpointAddress, - portData, "my-service", Map.of("a", "b"), "k8s", KubernetesDiscoveryProperties.DEFAULT, null); + ServiceInstance serviceInstance = Fabric8KubernetesDiscoveryClientUtils.serviceInstance(null, service, + endpointAddress, portData, "my-service", Map.of("a", "b"), "k8s", KubernetesDiscoveryProperties.DEFAULT, + null); Assertions.assertTrue(serviceInstance instanceof DefaultKubernetesServiceInstance); DefaultKubernetesServiceInstance defaultInstance = (DefaultKubernetesServiceInstance) serviceInstance; Assertions.assertEquals(defaultInstance.getInstanceId(), "123"); From 53b7139d3f953473fb5d38ac24b243e35d41235e Mon Sep 17 00:00:00 2001 From: wind57 Date: Mon, 20 Mar 2023 20:15:40 +0200 Subject: [PATCH 050/151] trigger build From 24397c0b65497bc5c2b020d43b8d431aba668602 Mon Sep 17 00:00:00 2001 From: wind57 Date: Thu, 23 Mar 2023 15:22:33 +0200 Subject: [PATCH 051/151] merge main --- .../Fabric8DiscoveryServicesAdapter.java | 98 --- .../Fabric8KubernetesDiscoveryClient.java | 2 +- .../Fabric8KubernetesDiscoveryClientTest.java | 5 - ...Fabric8KubernetesDiscoveryClientTests.java | 5 - ...ubernetesReactiveDiscoveryClientTests.java | 7 - .../KubernetesDiscoveryClientUtilsTests.java | 806 ------------------ 6 files changed, 1 insertion(+), 922 deletions(-) delete mode 100644 spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryServicesAdapter.java delete mode 100644 spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryServicesAdapter.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryServicesAdapter.java deleted file mode 100644 index cdb079c805..0000000000 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryServicesAdapter.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright 2012-2022 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.discovery; - -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.function.Function; -import java.util.function.Predicate; - -import io.fabric8.kubernetes.api.model.Service; -import io.fabric8.kubernetes.client.KubernetesClient; -import org.apache.commons.logging.LogFactory; - -import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; -import org.springframework.core.log.LogAccessor; -import org.springframework.expression.Expression; -import org.springframework.expression.spel.standard.SpelExpressionParser; -import org.springframework.expression.spel.support.SimpleEvaluationContext; - -/** - * Adapts a {@link KubernetesClientServicesFunction} to a Function that takes a - * KubernetesClient as input and returns a List of Services(s), plus adds functionality - * not supported by it. - * - * @author wind57 - */ -final class Fabric8DiscoveryServicesAdapter implements Function> { - - private static final LogAccessor LOG = new LogAccessor(LogFactory.getLog(Fabric8DiscoveryServicesAdapter.class)); - - private static final SpelExpressionParser PARSER = new SpelExpressionParser(); - - private static final SimpleEvaluationContext EVALUATION_CONTEXT = SimpleEvaluationContext.forReadOnlyDataBinding() - .withInstanceMethods().build(); - - private final KubernetesClientServicesFunction function; - - private final KubernetesDiscoveryProperties properties; - - private final Predicate filter; - - Fabric8DiscoveryServicesAdapter(KubernetesClientServicesFunction function, KubernetesDiscoveryProperties properties, - Predicate filter) { - this.function = function; - this.properties = properties; - if (filter == null) { - this.filter = filter(); - } - else { - this.filter = filter; - } - } - - @Override - public List apply(KubernetesClient client) { - if (!properties.namespaces().isEmpty()) { - LOG.debug(() -> "searching in namespaces : " + properties.namespaces() + " with filter : " - + properties.filter()); - List services = new ArrayList<>(); - properties.namespaces().forEach(namespace -> services.addAll(client.services().inNamespace(namespace) - .withLabels(properties.serviceLabels()).list().getItems().stream().filter(filter).toList())); - return services; - } - return function.apply(client).list().getItems().stream().filter(filter).toList(); - } - - Predicate filter() { - String spelExpression = properties.filter(); - Predicate predicate; - if (spelExpression == null || spelExpression.isEmpty()) { - predicate = service -> true; - } - else { - Expression filterExpr = PARSER.parseExpression(spelExpression); - predicate = service -> { - Boolean include = filterExpr.getValue(EVALUATION_CONTEXT, service, Boolean.class); - return Optional.ofNullable(include).orElse(false); - }; - } - return predicate; - } - -} diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClient.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClient.java index eb0f9f682e..bc489ce786 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClient.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClient.java @@ -111,7 +111,7 @@ public List getInstances(String serviceId) { } public List getEndPointsList(String serviceId) { - return endpoints(properties, client, namespaceProvider, "fabric8-discovery", serviceId, adapter.filter()); + return endpoints(properties, client, namespaceProvider, "fabric8-discovery", serviceId, predicate); } private List getNamespaceServiceInstances(EndpointSubsetNS es, String serviceId) { diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientTest.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientTest.java index 46114c442d..c9572a6e15 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientTest.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientTest.java @@ -178,13 +178,8 @@ void getEndPointsListTestAllNamespaces() { KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, false, null, Set.of(), Map.of(), null, KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, false, false); -<<<<<<< HEAD Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, properties, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true); -======= - KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(mockClient, properties, - KubernetesClient::services, x -> true, new ServicePortSecureResolver(properties)); ->>>>>>> main List result_endpoints = discoveryClient.getEndPointsList("endpoint"); diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientTests.java index 1931c5afcc..ad5d2973e3 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientTests.java @@ -432,13 +432,8 @@ void testSelectiveNamespacesSingleEndpointsMatchExactLabels(CapturedOutput outpu KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces, true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false, false); -<<<<<<< HEAD Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties, null, null, null); -======= - KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, x -> true, - null); ->>>>>>> main List result = discoveryClient.getEndPointsList("blue-service"); Assertions.assertEquals(result.size(), 1); Assertions.assertTrue(output.getOut().contains("discovering endpoints in namespaces : [test]")); diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientTests.java index f625284391..9e204a04f4 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientTests.java @@ -179,19 +179,12 @@ void shouldReturnFlux() { kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services/existing-service") .andReturn(200, services.getItems().get(0)).once(); -<<<<<<< HEAD:spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientTests.java Fabric8KubernetesDiscoveryClient fabric8KubernetesDiscoveryClient = new Fabric8KubernetesDiscoveryClient( kubernetesClient, KubernetesDiscoveryProperties.DEFAULT, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true); // Metadata metadata = new Metadata(false, null, false, null, true, "port."); ReactiveDiscoveryClient client = new Fabric8KubernetesReactiveDiscoveryClient(fabric8KubernetesDiscoveryClient); -======= - kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services").andReturn(200, services).once(); - - ReactiveDiscoveryClient client = new KubernetesReactiveDiscoveryClient(kubernetesClient, - KubernetesDiscoveryProperties.DEFAULT, KubernetesClient::services); ->>>>>>> main:spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/reactive/KubernetesReactiveDiscoveryClientTests.java Flux instances = client.getInstances("existing-service"); StepVerifier.create(instances).expectNextCount(1).expectComplete().verify(); } diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java deleted file mode 100644 index 366ca511d7..0000000000 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java +++ /dev/null @@ -1,806 +0,0 @@ -/* - * Copyright 2013-2023 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.discovery; - -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.stream.Collectors; - -import io.fabric8.kubernetes.api.model.EndpointAddress; -import io.fabric8.kubernetes.api.model.EndpointAddressBuilder; -import io.fabric8.kubernetes.api.model.EndpointPortBuilder; -import io.fabric8.kubernetes.api.model.EndpointSubset; -import io.fabric8.kubernetes.api.model.EndpointSubsetBuilder; -import io.fabric8.kubernetes.api.model.Endpoints; -import io.fabric8.kubernetes.api.model.EndpointsBuilder; -import io.fabric8.kubernetes.api.model.ObjectMeta; -import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; -import io.fabric8.kubernetes.api.model.Service; -import io.fabric8.kubernetes.api.model.ServiceBuilder; -import io.fabric8.kubernetes.api.model.ServiceSpecBuilder; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import org.springframework.boot.test.system.CapturedOutput; -import org.springframework.boot.test.system.OutputCaptureExtension; -import org.springframework.cloud.client.ServiceInstance; -import org.springframework.cloud.kubernetes.commons.discovery.DefaultKubernetesServiceInstance; -import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; - -import static org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryConstants.PRIMARY_PORT_NAME_LABEL_KEY; - -/** - * @author wind57 - */ -@ExtendWith(OutputCaptureExtension.class) -class KubernetesDiscoveryClientUtilsTests { - - @Test - void testSubsetsFromEndpointsEmptySubsets() { - Endpoints endpoints = new EndpointsBuilder() - .withMetadata(new ObjectMetaBuilder().withNamespace("non-default").build()).build(); - EndpointSubsetNS result = Fabric8KubernetesDiscoveryClientUtils.subsetsFromEndpoints(endpoints); - Assertions.assertNotNull(result); - Assertions.assertEquals(result.endpointSubset(), List.of()); - Assertions.assertEquals(result.namespace(), "non-default"); - } - - @Test - void testSubsetsFromEndpointsNonEmptySubsets() { - Endpoints endpoints = new EndpointsBuilder().withSubsets((List) null) - .withMetadata(new ObjectMetaBuilder().withNamespace("default").build()) - .withSubsets( - new EndpointSubsetBuilder().withPorts(new EndpointPortBuilder().withPort(8080).build()).build()) - .build(); - EndpointSubsetNS result = Fabric8KubernetesDiscoveryClientUtils.subsetsFromEndpoints(endpoints); - Assertions.assertNotNull(result); - Assertions.assertEquals(result.endpointSubset().size(), 1); - Assertions.assertEquals(result.endpointSubset().get(0).getPorts().get(0).getPort(), 8080); - Assertions.assertEquals(result.namespace(), "default"); - } - - /** - *
-	 *     - properties do not have primary-port-name set
-	 *     - service labels do not have primary-port-name set
-	 *
-	 *     As such null is returned.
-	 * 
- */ - @Test - void testPrimaryPortNameNotFound(CapturedOutput output) { - KubernetesDiscoveryProperties properties = KubernetesDiscoveryProperties.DEFAULT; - Service service = new ServiceBuilder().withMetadata(new ObjectMeta()).build(); - - String result = Fabric8KubernetesDiscoveryClientUtils.primaryPortName(properties, service, "abc"); - Assertions.assertNull(result); - Assertions.assertTrue(output.getOut().contains( - "did not find a primary-port-name in neither properties nor service labels for service with ID : abc")); - } - - /** - *
-	 *     - properties do have primary-port-name set to "https"
-	 *     - service labels do not have primary-port-name set
-	 *
-	 *     As such "https" is returned.
-	 * 
- */ - @Test - void testPrimaryPortNameFoundInProperties(CapturedOutput output) { - String primaryPortName = "https"; - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - true, "", Set.of(), Map.of(), primaryPortName, null, 0, false); - Service service = new ServiceBuilder().withMetadata(new ObjectMeta()).build(); - - String result = Fabric8KubernetesDiscoveryClientUtils.primaryPortName(properties, service, "abc"); - Assertions.assertNotNull(result); - Assertions.assertEquals(result, primaryPortName); - Assertions.assertTrue(output.getOut().contains("will use primaryPortName : https for service with ID = abc")); - } - - /** - *
-	 *     - properties do not have primary-port-name set
-	 *     - service labels do have primary-port-name set to "https"
-	 *
-	 *     As such "https" is returned.
-	 * 
- */ - @Test - void testPrimaryPortNameFoundInLabels(CapturedOutput output) { - Map labels = Map.of(PRIMARY_PORT_NAME_LABEL_KEY, "https"); - KubernetesDiscoveryProperties properties = KubernetesDiscoveryProperties.DEFAULT; - Service service = new ServiceBuilder().withMetadata(new ObjectMetaBuilder().withLabels(labels).build()).build(); - - String result = Fabric8KubernetesDiscoveryClientUtils.primaryPortName(properties, service, "abc"); - Assertions.assertNotNull(result); - Assertions.assertEquals(result, "https"); - Assertions.assertTrue(output.getOut().contains("will use primaryPortName : https for service with ID = abc")); - } - - /** - *
-	 *     - properties do have primary-port-name set to "https"
-	 *     - service labels do have primary-port-name set to "http"
-	 *
-	 *     As such "http" is returned (labels win).
-	 * 
- */ - @Test - void testPrimaryPortNameFoundInBothPropertiesAndLabels(CapturedOutput output) { - String primaryPortName = "https"; - Map labels = Map.of(PRIMARY_PORT_NAME_LABEL_KEY, "http"); - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - true, "", Set.of(), Map.of(), primaryPortName, null, 0, false); - Service service = new ServiceBuilder().withMetadata(new ObjectMetaBuilder().withLabels(labels).build()).build(); - - String result = Fabric8KubernetesDiscoveryClientUtils.primaryPortName(properties, service, "abc"); - Assertions.assertNotNull(result); - Assertions.assertEquals(result, "http"); - Assertions.assertTrue(output.getOut().contains("will use primaryPortName : http for service with ID = abc")); - } - - /** - *
-	 *     - EndpointSubset has no ports.
-	 * 
- */ - @Test - void testEndpointsPortNoPorts(CapturedOutput output) { - EndpointSubset endpointSubset = new EndpointSubsetBuilder().build(); - String serviceId = "spring-k8s"; - KubernetesDiscoveryProperties properties = KubernetesDiscoveryProperties.DEFAULT; - Service service = new ServiceBuilder().build(); - - Fabric8ServicePortData portData = Fabric8KubernetesDiscoveryClientUtils.endpointsPort(endpointSubset, serviceId, - properties, service); - Assertions.assertEquals(portData.portNumber(), 0); - Assertions.assertEquals(portData.portName(), "http"); - Assertions.assertTrue(output.getOut().contains("no ports found for service : spring-k8s, will return zero")); - } - - /** - *
-	 *     - EndpointSubset has a single entry in getPorts.
-	 * 
- */ - @Test - void testEndpointsPortSinglePort(CapturedOutput output) { - EndpointSubset endpointSubset = new EndpointSubsetBuilder() - .withPorts(new EndpointPortBuilder().withPort(8080).withName("http").build()).build(); - String serviceId = "spring-k8s"; - KubernetesDiscoveryProperties properties = KubernetesDiscoveryProperties.DEFAULT; - Service service = new ServiceBuilder().build(); - - Fabric8ServicePortData portData = Fabric8KubernetesDiscoveryClientUtils.endpointsPort(endpointSubset, serviceId, - properties, service); - Assertions.assertEquals(portData.portNumber(), 8080); - Assertions.assertEquals(portData.portName(), "http"); - Assertions.assertTrue(output.getOut().contains("endpoint ports has a single entry, using port : 8080")); - } - - /** - *
-	 *     - primary-port-name is null.
-	 * 
- */ - @Test - void testEndpointsPortNullPrimaryPortName(CapturedOutput output) { - EndpointSubset endpointSubset = new EndpointSubsetBuilder() - .withPorts(new EndpointPortBuilder().withPort(8080).build(), - new EndpointPortBuilder().withPort(8081).build()) - .build(); - String serviceId = "spring-k8s"; - KubernetesDiscoveryProperties properties = KubernetesDiscoveryProperties.DEFAULT; - Service service = new ServiceBuilder().withMetadata(new ObjectMeta()).build(); - - Fabric8ServicePortData portData = Fabric8KubernetesDiscoveryClientUtils.endpointsPort(endpointSubset, serviceId, - properties, service); - Assertions.assertEquals(portData.portNumber(), 8080); - Assertions.assertNull(portData.portName()); - Assertions.assertTrue(output.getOut().contains( - "did not find a primary-port-name in neither properties nor service labels for service with ID : spring-k8s")); - Assertions.assertTrue(output.getOut() - .contains("not found primary-port-name (with value: 'null') via properties or service labels")); - Assertions.assertTrue(output.getOut().contains("not found primary-port-name via 'https' to match port")); - Assertions.assertTrue(output.getOut().contains("not found primary-port-name via 'http' to match port")); - Assertions.assertTrue(output.getOut().contains(""" - Make sure that either the primary-port-name label has been added to the service, - or spring.cloud.kubernetes.discovery.primary-port-name has been configured. - Alternatively name the primary port 'https' or 'http' - An incorrect configuration may result in non-deterministic behaviour.""")); - } - - /** - *
-	 *     - primary-port-name is "three", such a port name does not exist.
-	 * 
- */ - @Test - void testEndpointsPortPrimaryPortNameIsPresentButNotFound(CapturedOutput output) { - EndpointSubset endpointSubset = new EndpointSubsetBuilder() - .withPorts(new EndpointPortBuilder().withPort(8080).withName("one").build(), - new EndpointPortBuilder().withPort(8081).withName("two").build()) - .build(); - String serviceId = "spring-k8s"; - - String primaryPortName = "three"; - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - true, "", Set.of(), Map.of(), primaryPortName, null, 0, false); - - Service service = new ServiceBuilder().withMetadata(new ObjectMeta()).build(); - - Fabric8ServicePortData portData = Fabric8KubernetesDiscoveryClientUtils.endpointsPort(endpointSubset, serviceId, - properties, service); - Assertions.assertEquals(portData.portNumber(), 8080); - Assertions.assertEquals(portData.portName(), "one"); - Assertions.assertTrue( - output.getOut().contains("will use primaryPortName : three for service with ID = spring-k8s")); - Assertions.assertTrue(output.getOut() - .contains("not found primary-port-name (with value: 'three') via properties or service labels")); - Assertions.assertTrue(output.getOut().contains("not found primary-port-name via 'https' to match port")); - Assertions.assertTrue(output.getOut().contains("not found primary-port-name via 'http' to match port")); - Assertions.assertTrue(output.getOut().contains(""" - Make sure that either the primary-port-name label has been added to the service, - or spring.cloud.kubernetes.discovery.primary-port-name has been configured. - Alternatively name the primary port 'https' or 'http' - An incorrect configuration may result in non-deterministic behaviour.""")); - } - - /** - *
-	 *     - primary-port-name is "two", such a port name exists and matches 8081
-	 * 
- */ - @Test - void testEndpointsPortPrimaryPortNameFound(CapturedOutput output) { - EndpointSubset endpointSubset = new EndpointSubsetBuilder() - .withPorts(new EndpointPortBuilder().withPort(8080).withName("one").build(), - new EndpointPortBuilder().withPort(8081).withName("two").build()) - .build(); - String serviceId = "spring-k8s"; - - String primaryPortName = "two"; - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - true, "", Set.of(), Map.of(), primaryPortName, null, 0, false); - - Service service = new ServiceBuilder().withMetadata(new ObjectMeta()).build(); - - Fabric8ServicePortData portData = Fabric8KubernetesDiscoveryClientUtils.endpointsPort(endpointSubset, serviceId, - properties, service); - Assertions.assertEquals(portData.portNumber(), 8081); - Assertions.assertEquals(portData.portName(), "two"); - Assertions.assertTrue( - output.getOut().contains("will use primaryPortName : two for service with ID = spring-k8s")); - Assertions.assertTrue(output.getOut().contains( - "found primary-port-name (with value: 'two') via properties or service labels to match port : 8081")); - } - - /** - *
-	 *     - primary-port-name is "three", such a port name does not exist.
-	 *     - https port exists and this one is returned
-	 * 
- */ - @Test - void testEndpointsPortPrimaryPortHttps(CapturedOutput output) { - EndpointSubset endpointSubset = new EndpointSubsetBuilder() - .withPorts(new EndpointPortBuilder().withPort(8080).withName("one").build(), - new EndpointPortBuilder().withPort(8081).withName("two").build(), - new EndpointPortBuilder().withPort(8082).withName("https").build()) - .build(); - String serviceId = "spring-k8s"; - - String primaryPortName = "three"; - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - true, "", Set.of(), Map.of(), primaryPortName, null, 0, false, false); - - Service service = new ServiceBuilder().withMetadata(new ObjectMeta()).build(); - - Fabric8ServicePortData portData = Fabric8KubernetesDiscoveryClientUtils.endpointsPort(endpointSubset, serviceId, - properties, service); - Assertions.assertEquals(portData.portNumber(), 8082); - Assertions.assertEquals(portData.portName(), "https"); - Assertions.assertTrue( - output.getOut().contains("will use primaryPortName : three for service with ID = spring-k8s")); - Assertions.assertTrue(output.getOut().contains( - "not found primary-port-name (with value: 'three') via properties or service labels to match port")); - Assertions.assertTrue(output.getOut().contains("found primary-port-name via 'https' to match port : 8082")); - } - - /** - *
-	 *     - primary-port-name is "three", such a port name does not exist.
-	 *     - http port exists and this one is returned
-	 * 
- */ - @Test - void testEndpointsPortPrimaryPortHttp(CapturedOutput output) { - EndpointSubset endpointSubset = new EndpointSubsetBuilder() - .withPorts(new EndpointPortBuilder().withPort(8080).withName("one").build(), - new EndpointPortBuilder().withPort(8081).withName("two").build(), - new EndpointPortBuilder().withPort(8082).withName("http").build()) - .build(); - String serviceId = "spring-k8s"; - - String primaryPortName = "three"; - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - true, "", Set.of(), Map.of(), primaryPortName, null, 0, false); - - Service service = new ServiceBuilder().withMetadata(new ObjectMeta()).build(); - - Fabric8ServicePortData portData = Fabric8KubernetesDiscoveryClientUtils.endpointsPort(endpointSubset, serviceId, - properties, service); - Assertions.assertEquals(portData.portNumber(), 8082); - Assertions.assertEquals(portData.portName(), "http"); - Assertions.assertTrue( - output.getOut().contains("will use primaryPortName : three for service with ID = spring-k8s")); - Assertions.assertTrue(output.getOut().contains( - "not found primary-port-name (with value: 'three') via properties or service labels to match port")); - Assertions.assertTrue(output.getOut().contains("found primary-port-name via 'http' to match port : 8082")); - } - - /** - *
-	 *     - labels are not added
-	 *     - annotations are not added
-	 * 
- */ - @Test - void testServiceMetadataEmpty() { - boolean addLabels = false; - String labelsPrefix = ""; - boolean addAnnotations = false; - String annotationsPrefix = ""; - boolean addPorts = false; - String portsPrefix = ""; - - String namespace = "default"; - - KubernetesDiscoveryProperties.Metadata metadata = new KubernetesDiscoveryProperties.Metadata(addLabels, - labelsPrefix, addAnnotations, annotationsPrefix, addPorts, portsPrefix); - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - true, "", Set.of(), Map.of(), "", metadata, 0, false, false); - Service service = new ServiceBuilder().withSpec(new ServiceSpecBuilder().withType("ClusterIP").build()).build(); - - Map result = Fabric8KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, - properties, List.of(), namespace); - Assertions.assertEquals(result.size(), 2); - Assertions.assertEquals(result, Map.of("k8s_namespace", "default", "type", "ClusterIP")); - } - - /** - *
-	 *     - labels are added without a prefix
-	 *     - annotations are not added
-	 * 
- */ - @Test - void testServiceMetadataAddLabelsNoPrefix(CapturedOutput output) { - boolean addLabels = true; - String labelsPrefix = ""; - boolean addAnnotations = false; - String annotationsPrefix = ""; - boolean addPorts = false; - String portsPrefix = ""; - - String namespace = "default"; - - KubernetesDiscoveryProperties.Metadata metadata = new KubernetesDiscoveryProperties.Metadata(addLabels, - labelsPrefix, addAnnotations, annotationsPrefix, addPorts, portsPrefix); - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - true, "", Set.of(), Map.of(), "", metadata, 0, false, false); - Service service = new ServiceBuilder().withSpec(new ServiceSpecBuilder().withType("ClusterIP").build()) - .withMetadata(new ObjectMetaBuilder().withLabels(Map.of("a", "b")).build()).build(); - - Map result = Fabric8KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, - properties, List.of(), namespace); - Assertions.assertEquals(result.size(), 3); - Assertions.assertEquals(result, Map.of("a", "b", "k8s_namespace", "default", "type", "ClusterIP")); - String labelsMetadata = filterOnK8sNamespaceAndType(result); - Assertions.assertTrue( - output.getOut().contains("Adding labels metadata: " + labelsMetadata + " for serviceId: my-service")); - } - - /** - *
-	 *     - labels are added with prefix
-	 *     - annotations are not added
-	 * 
- */ - @Test - void testServiceMetadataAddLabelsWithPrefix(CapturedOutput output) { - boolean addLabels = true; - String labelsPrefix = "prefix-"; - boolean addAnnotations = false; - String annotationsPrefix = ""; - boolean addPorts = false; - String portsPrefix = ""; - - String namespace = "default"; - - KubernetesDiscoveryProperties.Metadata metadata = new KubernetesDiscoveryProperties.Metadata(addLabels, - labelsPrefix, addAnnotations, annotationsPrefix, addPorts, portsPrefix); - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - true, "", Set.of(), Map.of(), "", metadata, 0, false, false); - Service service = new ServiceBuilder().withSpec(new ServiceSpecBuilder().withType("ClusterIP").build()) - .withMetadata(new ObjectMetaBuilder().withLabels(Map.of("a", "b", "c", "d")).build()).build(); - - Map result = Fabric8KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, - properties, List.of(), namespace); - Assertions.assertEquals(result.size(), 4); - Assertions.assertEquals(result, - Map.of("prefix-a", "b", "prefix-c", "d", "k8s_namespace", "default", "type", "ClusterIP")); - // so that result is deterministic in assertion - String labelsMetadata = filterOnK8sNamespaceAndType(result); - Assertions.assertTrue( - output.getOut().contains("Adding labels metadata: " + labelsMetadata + " for serviceId: my-service")); - } - - /** - *
-	 *     - labels are not added
-	 *     - annotations are added without prefix
-	 * 
- */ - @Test - void testServiceMetadataAddAnnotationsNoPrefix(CapturedOutput output) { - boolean addLabels = false; - String labelsPrefix = ""; - boolean addAnnotations = true; - String annotationsPrefix = ""; - boolean addPorts = false; - String portsPrefix = ""; - - String namespace = "default"; - - KubernetesDiscoveryProperties.Metadata metadata = new KubernetesDiscoveryProperties.Metadata(addLabels, - labelsPrefix, addAnnotations, annotationsPrefix, addPorts, portsPrefix); - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - true, "", Set.of(), Map.of(), "", metadata, 0, false, false); - Service service = new ServiceBuilder().withSpec(new ServiceSpecBuilder().withType("ClusterIP").build()) - .withMetadata(new ObjectMetaBuilder().withAnnotations(Map.of("aa", "bb")).withLabels(Map.of("a", "b")) - .build()) - .build(); - - Map result = Fabric8KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, - properties, List.of(), namespace); - Assertions.assertEquals(result.size(), 3); - Assertions.assertEquals(result, Map.of("aa", "bb", "k8s_namespace", "default", "type", "ClusterIP")); - Assertions - .assertTrue(output.getOut().contains("Adding annotations metadata: {aa=bb} for serviceId: my-service")); - } - - /** - *
-	 *     - labels are not added
-	 *     - annotations are added with prefix
-	 * 
- */ - @Test - void testServiceMetadataAddAnnotationsWithPrefix(CapturedOutput output) { - boolean addLabels = false; - String labelsPrefix = ""; - boolean addAnnotations = true; - String annotationsPrefix = "prefix-"; - boolean addPorts = false; - String portsPrefix = ""; - - String namespace = "default"; - - KubernetesDiscoveryProperties.Metadata metadata = new KubernetesDiscoveryProperties.Metadata(addLabels, - labelsPrefix, addAnnotations, annotationsPrefix, addPorts, portsPrefix); - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - true, "", Set.of(), Map.of(), "", metadata, 0, false, false); - Service service = new ServiceBuilder().withSpec(new ServiceSpecBuilder().withType("ClusterIP").build()) - .withMetadata(new ObjectMetaBuilder().withAnnotations(Map.of("aa", "bb", "cc", "dd")) - .withLabels(Map.of("a", "b")).build()) - .build(); - - Map result = Fabric8KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, - properties, List.of(), namespace); - Assertions.assertEquals(result.size(), 4); - Assertions.assertEquals(result, - Map.of("prefix-aa", "bb", "prefix-cc", "dd", "k8s_namespace", "default", "type", "ClusterIP")); - // so that result is deterministic in assertion - String annotations = filterOnK8sNamespaceAndType(result); - Assertions.assertTrue( - output.getOut().contains("Adding annotations metadata: " + annotations + " for serviceId: my-service")); - } - - /** - *
-	 *     - labels are added with prefix
-	 *     - annotations are added with prefix
-	 * 
- */ - @Test - void testServiceMetadataAddLabelsAndAnnotationsWithPrefix(CapturedOutput output) { - boolean addLabels = true; - String labelsPrefix = "label-"; - boolean addAnnotations = true; - String annotationsPrefix = "annotation-"; - boolean addPorts = false; - String portsPrefix = ""; - - String namespace = "default"; - - KubernetesDiscoveryProperties.Metadata metadata = new KubernetesDiscoveryProperties.Metadata(addLabels, - labelsPrefix, addAnnotations, annotationsPrefix, addPorts, portsPrefix); - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - true, "", Set.of(), Map.of(), "", metadata, 0, false, false); - Service service = new ServiceBuilder() - .withSpec(new ServiceSpecBuilder().withType("ClusterIP").build()).withMetadata(new ObjectMetaBuilder() - .withAnnotations(Map.of("aa", "bb", "cc", "dd")).withLabels(Map.of("a", "b", "c", "d")).build()) - .build(); - - Map result = Fabric8KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, - properties, List.of(), namespace); - Assertions.assertEquals(result.size(), 6); - Assertions.assertEquals(result, Map.of("annotation-aa", "bb", "annotation-cc", "dd", "label-a", "b", "label-c", - "d", "k8s_namespace", "default", "type", "ClusterIP")); - // so that result is deterministic in assertion - String labels = result.entrySet().stream().filter(en -> en.getKey().contains("label")) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)).toString(); - String annotations = result.entrySet().stream().filter(en -> en.getKey().contains("annotation")) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)).toString(); - Assertions.assertTrue( - output.getOut().contains("Adding labels metadata: " + labels + " for serviceId: my-service")); - Assertions.assertTrue( - output.getOut().contains("Adding annotations metadata: " + annotations + " for serviceId: my-service")); - } - - /** - *
-	 *     - ports without prefix are added
-	 * 
- */ - @Test - void testServiceMetadataAddPortsWithoutPrefix(CapturedOutput output) { - boolean addLabels = false; - String labelsPrefix = ""; - boolean addAnnotations = false; - String annotationsPrefix = "prefix-"; - boolean addPorts = true; - String portsPrefix = ""; - - String namespace = "default"; - - KubernetesDiscoveryProperties.Metadata metadata = new KubernetesDiscoveryProperties.Metadata(addLabels, - labelsPrefix, addAnnotations, annotationsPrefix, addPorts, portsPrefix); - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - true, "", Set.of(), Map.of(), "", metadata, 0, false, false); - Service service = new ServiceBuilder().withSpec(new ServiceSpecBuilder().withType("ClusterIP").build()) - .withMetadata(new ObjectMetaBuilder().withAnnotations(Map.of("aa", "bb", "cc", "dd")) - .withLabels(Map.of("a", "b")).build()) - .build(); - - List endpointSubsets = List.of( - new EndpointSubsetBuilder().withPorts(new EndpointPortBuilder().withPort(8081).withName("").build()) - .build(), - new EndpointSubsetBuilder() - .withPorts(new EndpointPortBuilder().withPort(8080).withName("https").build()).build()); - - Map result = Fabric8KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, - properties, endpointSubsets, namespace); - Assertions.assertEquals(result.size(), 3); - Assertions.assertEquals(result, Map.of("https", "8080", "k8s_namespace", "default", "type", "ClusterIP")); - Assertions - .assertTrue(output.getOut().contains("Adding port metadata: {https=8080} for serviceId : my-service")); - } - - /** - *
-	 *     - ports without prefix are added
-	 * 
- */ - @Test - void testServiceMetadataAddPortsWithPrefix(CapturedOutput output) { - boolean addLabels = false; - String labelsPrefix = ""; - boolean addAnnotations = false; - String annotationsPrefix = "prefix-"; - boolean addPorts = true; - String portsPrefix = "prefix-"; - - String namespace = "default"; - - KubernetesDiscoveryProperties.Metadata metadata = new KubernetesDiscoveryProperties.Metadata(addLabels, - labelsPrefix, addAnnotations, annotationsPrefix, addPorts, portsPrefix); - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - true, "", Set.of(), Map.of(), "", metadata, 0, false, false); - Service service = new ServiceBuilder().withSpec(new ServiceSpecBuilder().withType("ClusterIP").build()) - .withMetadata(new ObjectMetaBuilder().withAnnotations(Map.of("aa", "bb", "cc", "dd")) - .withLabels(Map.of("a", "b")).build()) - .build(); - - List endpointSubsets = List.of( - new EndpointSubsetBuilder().withPorts(new EndpointPortBuilder().withPort(8081).withName("http").build()) - .build(), - new EndpointSubsetBuilder() - .withPorts(new EndpointPortBuilder().withPort(8080).withName("https").build()).build()); - - Map result = Fabric8KubernetesDiscoveryClientUtils.serviceMetadata("my-service", service, - properties, endpointSubsets, namespace); - Assertions.assertEquals(result.size(), 4); - Assertions.assertEquals(result, - Map.of("prefix-https", "8080", "prefix-http", "8081", "k8s_namespace", "default", "type", "ClusterIP")); - Assertions.assertTrue(output.getOut() - .contains("Adding port metadata: {prefix-http=8081, prefix-https=8080} for serviceId : my-service")); - } - - /** - *
-	 *      - ready addresses are empty
-	 *      - not ready addresses are not included
-	 * 
- */ - @Test - void testEmptyAddresses() { - boolean includeNotReadyAddresses = false; - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - includeNotReadyAddresses, "", Set.of(), Map.of(), "", null, 0, false, false); - EndpointSubset endpointSubset = new EndpointSubsetBuilder().build(); - List addresses = Fabric8KubernetesDiscoveryClientUtils.addresses(endpointSubset, properties); - Assertions.assertEquals(addresses.size(), 0); - } - - /** - *
-	 *      - ready addresses has two entries
-	 *      - not ready addresses are not included
-	 * 
- */ - @Test - void testReadyAddressesOnly() { - boolean includeNotReadyAddresses = false; - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - includeNotReadyAddresses, "", Set.of(), Map.of(), "", null, 0, false); - EndpointSubset endpointSubset = new EndpointSubsetBuilder() - .withAddresses(new EndpointAddressBuilder().withHostname("one").build(), - new EndpointAddressBuilder().withHostname("two").build()) - .build(); - List addresses = Fabric8KubernetesDiscoveryClientUtils.addresses(endpointSubset, properties); - Assertions.assertEquals(addresses.size(), 2); - } - - /** - *
-	 *      - ready addresses has two entries
-	 *      - not ready addresses has a single entry, but we do not take it
-	 * 
- */ - @Test - void testReadyAddressesTakenNotReadyAddressesNotTaken() { - boolean includeNotReadyAddresses = false; - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - includeNotReadyAddresses, "", Set.of(), Map.of(), "", null, 0, false, false); - EndpointSubset endpointSubset = new EndpointSubsetBuilder() - .withAddresses(new EndpointAddressBuilder().withHostname("one").build(), - new EndpointAddressBuilder().withHostname("two").build()) - .withNotReadyAddresses(new EndpointAddressBuilder().withHostname("three").build()).build(); - List addresses = Fabric8KubernetesDiscoveryClientUtils.addresses(endpointSubset, properties); - Assertions.assertEquals(addresses.size(), 2); - List hostNames = addresses.stream().map(EndpointAddress::getHostname).sorted().toList(); - Assertions.assertEquals(hostNames, List.of("one", "two")); - } - - /** - *
-	 *      - ready addresses has two entries
-	 *      - not ready addresses has a single entry, but we do not take it
-	 * 
- */ - @Test - void testBothAddressesTaken() { - boolean includeNotReadyAddresses = true; - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - includeNotReadyAddresses, "", Set.of(), Map.of(), "", null, 0, false); - EndpointSubset endpointSubset = new EndpointSubsetBuilder() - .withAddresses(new EndpointAddressBuilder().withHostname("one").build(), - new EndpointAddressBuilder().withHostname("two").build()) - .withNotReadyAddresses(new EndpointAddressBuilder().withHostname("three").build()).build(); - List addresses = Fabric8KubernetesDiscoveryClientUtils.addresses(endpointSubset, properties); - Assertions.assertEquals(addresses.size(), 3); - List hostNames = addresses.stream().map(EndpointAddress::getHostname).sorted().toList(); - Assertions.assertEquals(hostNames, List.of("one", "three", "two")); - } - - @Test - void testServiceInstance() { - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - false, "", Set.of(), Map.of(), "", KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, false, false); - ServicePortSecureResolver resolver = new ServicePortSecureResolver(properties); - Service service = new ServiceBuilder().withMetadata(new ObjectMeta()).build(); - EndpointAddress address = new EndpointAddressBuilder().withNewTargetRef().withUid("123").endTargetRef() - .withIp("127.0.0.1").build(); - - Fabric8ServicePortData portData = new Fabric8ServicePortData(8080, "http"); - ServiceInstance serviceInstance = Fabric8KubernetesDiscoveryClientUtils.serviceInstance(resolver, service, - address, portData, "my-service", Map.of("a", "b"), "k8s", properties, null); - Assertions.assertTrue(serviceInstance instanceof DefaultKubernetesServiceInstance); - DefaultKubernetesServiceInstance defaultInstance = (DefaultKubernetesServiceInstance) serviceInstance; - Assertions.assertEquals(defaultInstance.getInstanceId(), "123"); - Assertions.assertEquals(defaultInstance.getServiceId(), "my-service"); - Assertions.assertEquals(defaultInstance.getHost(), "127.0.0.1"); - Assertions.assertEquals(defaultInstance.getPort(), 8080); - Assertions.assertFalse(defaultInstance.isSecure()); - Assertions.assertEquals(defaultInstance.getUri().toASCIIString(), "http://127.0.0.1:8080"); - Assertions.assertEquals(defaultInstance.getMetadata(), Map.of("a", "b")); - Assertions.assertEquals(defaultInstance.getScheme(), "http"); - Assertions.assertEquals(defaultInstance.getNamespace(), "k8s"); - Assertions.assertNull(defaultInstance.getCluster()); - } - - @Test - void testExternalNameServiceInstance() { - Service service = new ServiceBuilder() - .withSpec(new ServiceSpecBuilder().withExternalName("spring.io").withType("ExternalName").build()) - .withMetadata(new ObjectMetaBuilder().withUid("123").build()).build(); - - Fabric8ServicePortData portData = new Fabric8ServicePortData(-1, "http"); - ServiceInstance serviceInstance = Fabric8KubernetesDiscoveryClientUtils.serviceInstance(null, service, null, - portData, "my-service", Map.of("a", "b"), "k8s", KubernetesDiscoveryProperties.DEFAULT, null); - Assertions.assertTrue(serviceInstance instanceof DefaultKubernetesServiceInstance); - DefaultKubernetesServiceInstance defaultInstance = (DefaultKubernetesServiceInstance) serviceInstance; - Assertions.assertEquals(defaultInstance.getInstanceId(), "123"); - Assertions.assertEquals(defaultInstance.getServiceId(), "my-service"); - Assertions.assertEquals(defaultInstance.getHost(), "spring.io"); - Assertions.assertEquals(defaultInstance.getPort(), -1); - Assertions.assertFalse(defaultInstance.isSecure()); - Assertions.assertEquals(defaultInstance.getUri().toASCIIString(), "spring.io"); - Assertions.assertEquals(defaultInstance.getMetadata(), Map.of("a", "b")); - Assertions.assertEquals(defaultInstance.getScheme(), "http"); - Assertions.assertEquals(defaultInstance.getNamespace(), "k8s"); - Assertions.assertNull(defaultInstance.getCluster()); - } - - @Test - void testNoPortsServiceInstance() { - Service service = new ServiceBuilder().withSpec(new ServiceSpecBuilder().withType("ClusterIP").build()) - .withMetadata(new ObjectMetaBuilder().withUid("123").build()).build(); - - EndpointAddress endpointAddress = new EndpointAddressBuilder().withIp("127.0.0.1").build(); - - Fabric8ServicePortData portData = new Fabric8ServicePortData(0, "http"); - ServiceInstance serviceInstance = Fabric8KubernetesDiscoveryClientUtils.serviceInstance(null, service, - endpointAddress, portData, "my-service", Map.of("a", "b"), "k8s", KubernetesDiscoveryProperties.DEFAULT, - null); - Assertions.assertTrue(serviceInstance instanceof DefaultKubernetesServiceInstance); - DefaultKubernetesServiceInstance defaultInstance = (DefaultKubernetesServiceInstance) serviceInstance; - Assertions.assertEquals(defaultInstance.getInstanceId(), "123"); - Assertions.assertEquals(defaultInstance.getServiceId(), "my-service"); - Assertions.assertEquals(defaultInstance.getHost(), "127.0.0.1"); - Assertions.assertEquals(defaultInstance.getScheme(), "http"); - Assertions.assertEquals(defaultInstance.getPort(), 0); - Assertions.assertFalse(defaultInstance.isSecure()); - Assertions.assertEquals(defaultInstance.getUri().toASCIIString(), "http://127.0.0.1"); - Assertions.assertEquals(defaultInstance.getMetadata(), Map.of("a", "b")); - Assertions.assertEquals(defaultInstance.getNamespace(), "k8s"); - Assertions.assertNull(defaultInstance.getCluster()); - } - - private String filterOnK8sNamespaceAndType(Map result) { - return result.entrySet().stream().filter(en -> !en.getKey().contains("k8s_namespace")) - .filter(en -> !en.getKey().equals("type")) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)).toString(); - } - -} From b4b2666ea3296f93945a0333c4186553a8f966d1 Mon Sep 17 00:00:00 2001 From: wind57 Date: Sat, 25 Mar 2023 08:27:10 +0200 Subject: [PATCH 052/151] trigger build From 9bd3d3e40b42f4bd748217bd38d0fd224bd1856e Mon Sep 17 00:00:00 2001 From: wind57 Date: Fri, 31 Mar 2023 16:37:57 +0300 Subject: [PATCH 053/151] fix --- .../bootstrap/Fabric8DiscoveryBootstrapController.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery-with-bootstrap/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/bootstrap/Fabric8DiscoveryBootstrapController.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery-with-bootstrap/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/bootstrap/Fabric8DiscoveryBootstrapController.java index f9fac40b23..a18f854cbd 100644 --- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery-with-bootstrap/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/bootstrap/Fabric8DiscoveryBootstrapController.java +++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery-with-bootstrap/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/bootstrap/Fabric8DiscoveryBootstrapController.java @@ -18,7 +18,7 @@ import java.util.List; -import org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClient; +import org.springframework.cloud.kubernetes.fabric8.discovery.Fabric8KubernetesDiscoveryClient; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @@ -28,9 +28,9 @@ @RestController public class Fabric8DiscoveryBootstrapController { - private final KubernetesDiscoveryClient discoveryClient; + private final Fabric8KubernetesDiscoveryClient discoveryClient; - public Fabric8DiscoveryBootstrapController(KubernetesDiscoveryClient discoveryClient) { + public Fabric8DiscoveryBootstrapController(Fabric8KubernetesDiscoveryClient discoveryClient) { this.discoveryClient = discoveryClient; } From 8eb1d025e079e50a36bc28deb10726225f41b065 Mon Sep 17 00:00:00 2001 From: wind57 Date: Tue, 4 Apr 2023 19:47:12 +0300 Subject: [PATCH 054/151] increase timeout --- .../integration/tests/commons/native_client/Util.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-cloud-kubernetes-test-support/src/main/java/org/springframework/cloud/kubernetes/integration/tests/commons/native_client/Util.java b/spring-cloud-kubernetes-test-support/src/main/java/org/springframework/cloud/kubernetes/integration/tests/commons/native_client/Util.java index 102cbd8bd5..b15fddc378 100644 --- a/spring-cloud-kubernetes-test-support/src/main/java/org/springframework/cloud/kubernetes/integration/tests/commons/native_client/Util.java +++ b/spring-cloud-kubernetes-test-support/src/main/java/org/springframework/cloud/kubernetes/integration/tests/commons/native_client/Util.java @@ -455,7 +455,7 @@ private String secretName(V1Secret secret) { private void waitForDeployment(String namespace, V1Deployment deployment) { String deploymentName = deploymentName(deployment); - await().pollInterval(Duration.ofSeconds(1)).atMost(600, TimeUnit.SECONDS) + await().pollInterval(Duration.ofSeconds(1)).atMost(900, TimeUnit.SECONDS) .until(() -> isDeploymentReady(deploymentName, namespace)); } From bb02f774afea756675047e8fa8cb33923d4df75f Mon Sep 17 00:00:00 2001 From: wind57 Date: Tue, 4 Apr 2023 20:48:47 +0300 Subject: [PATCH 055/151] fix --- .../discovery/KubernetesClientInformerAutoConfiguration.java | 1 + .../kubernetes/fabric8/discovery/Fabric8DiscoveryController.java | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-cloud-kubernetes-client-discovery/src/main/java/org/springframework/cloud/kubernetes/client/discovery/KubernetesClientInformerAutoConfiguration.java b/spring-cloud-kubernetes-client-discovery/src/main/java/org/springframework/cloud/kubernetes/client/discovery/KubernetesClientInformerAutoConfiguration.java index 132c0f88d6..e0b1a9d4f8 100644 --- a/spring-cloud-kubernetes-client-discovery/src/main/java/org/springframework/cloud/kubernetes/client/discovery/KubernetesClientInformerAutoConfiguration.java +++ b/spring-cloud-kubernetes-client-discovery/src/main/java/org/springframework/cloud/kubernetes/client/discovery/KubernetesClientInformerAutoConfiguration.java @@ -38,6 +38,7 @@ import org.springframework.cloud.kubernetes.client.KubernetesClientAutoConfiguration; import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider; import org.springframework.cloud.kubernetes.commons.config.NamespaceResolutionFailedException; +import org.springframework.cloud.kubernetes.commons.discovery.ConditionalOnBlockingOrReactiveEnabled; import org.springframework.cloud.kubernetes.commons.discovery.ConditionalOnKubernetesDiscoveryEnabled; import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryPropertiesAutoConfiguration; diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryController.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryController.java index 40f2b28df1..4fe38df465 100644 --- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryController.java +++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryController.java @@ -21,7 +21,6 @@ import io.fabric8.kubernetes.api.model.Endpoints; import org.springframework.cloud.client.ServiceInstance; -import org.springframework.cloud.kubernetes.fabric8.discovery.Fabric8KubernetesDiscoveryClient; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RestController; From b6bec7d6cedf6bf36a72d27e6de77e52606237a4 Mon Sep 17 00:00:00 2001 From: wind57 Date: Wed, 5 Apr 2023 11:11:51 +0300 Subject: [PATCH 056/151] trigger build From 7eecbd97d83851d219b6aee151b245130d7fb61d Mon Sep 17 00:00:00 2001 From: wind57 Date: Wed, 5 Apr 2023 14:55:39 +0300 Subject: [PATCH 057/151] see logs --- .../Fabric8DiscoveryBootstrapIT.java | 60 +++++++++++-------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery-with-bootstrap/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/bootstrap/Fabric8DiscoveryBootstrapIT.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery-with-bootstrap/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/bootstrap/Fabric8DiscoveryBootstrapIT.java index 3260e50b9a..658fb03e2a 100644 --- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery-with-bootstrap/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/bootstrap/Fabric8DiscoveryBootstrapIT.java +++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery-with-bootstrap/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/bootstrap/Fabric8DiscoveryBootstrapIT.java @@ -32,6 +32,7 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import org.testcontainers.containers.Container; import org.testcontainers.k3s.K3sContainer; import reactor.netty.http.client.HttpClient; import reactor.util.retry.Retry; @@ -100,31 +101,42 @@ void testSimple() { Assertions.assertTrue(result.contains("service-wiremock")); } - private static void manifests(Phase phase) { - - InputStream deploymentStream = util.inputStream("fabric8-discovery-deployment.yaml"); - InputStream serviceStream = util.inputStream("fabric8-discovery-service.yaml"); - InputStream ingressStream = util.inputStream("fabric8-discovery-ingress.yaml"); - - Deployment deployment = client.apps().deployments().load(deploymentStream).get(); - - List existing = new ArrayList<>( - deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getEnv()); - existing.add(new EnvVarBuilder().withName("SPRING_CLOUD_KUBERNETES_DISCOVERY_INCLUDEEXTERNALNAMESERVICES") - .withValue("true").build()); - existing.add( - new EnvVarBuilder().withName("LOGGING_LEVEL_ORG_SPRINGFRAMEWORK_CLOUD_KUBERNETES_FABRIC8_DISCOVERY") - .withValue("DEBUG").build()); - deployment.getSpec().getTemplate().getSpec().getContainers().get(0).setEnv(existing); - - Service service = client.services().load(serviceStream).get(); - Ingress ingress = client.network().v1().ingresses().load(ingressStream).get(); - - if (phase.equals(Phase.CREATE)) { - util.createAndWait(NAMESPACE, null, deployment, service, ingress, true); + private static void manifests(Phase phase) throws Exception { + + try { + InputStream deploymentStream = util.inputStream("fabric8-discovery-deployment.yaml"); + InputStream serviceStream = util.inputStream("fabric8-discovery-service.yaml"); + InputStream ingressStream = util.inputStream("fabric8-discovery-ingress.yaml"); + + Deployment deployment = client.apps().deployments().load(deploymentStream).get(); + + List existing = new ArrayList<>( + deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getEnv()); + existing.add(new EnvVarBuilder().withName("SPRING_CLOUD_KUBERNETES_DISCOVERY_INCLUDEEXTERNALNAMESERVICES") + .withValue("true").build()); + existing.add( + new EnvVarBuilder().withName("LOGGING_LEVEL_ORG_SPRINGFRAMEWORK_CLOUD_KUBERNETES_FABRIC8_DISCOVERY") + .withValue("TRACE").build()); + deployment.getSpec().getTemplate().getSpec().getContainers().get(0).setEnv(existing); + + Service service = client.services().load(serviceStream).get(); + Ingress ingress = client.network().v1().ingresses().load(ingressStream).get(); + + if (phase.equals(Phase.CREATE)) { + util.createAndWait(NAMESPACE, null, deployment, service, ingress, true); + } + else { + util.deleteAndWait(NAMESPACE, deployment, service, ingress); + } } - else { - util.deleteAndWait(NAMESPACE, deployment, service, ingress); + catch (Exception e) { + String appPodName = K3S.execInContainer("sh", "-c", + "kubectl get pods -l app=spring-cloud-kubernetes-fabric8-client-discovery -o=name --no-headers | tr -d '\n'") + .getStdout(); + + Container.ExecResult execResult = K3S.execInContainer("sh", "-c", "kubectl logs " + appPodName.trim()); + String ok = execResult.getStdout(); + System.out.println(ok); } } From 051a507eec7496ec8a39ec049869716262074d7b Mon Sep 17 00:00:00 2001 From: wind57 Date: Wed, 5 Apr 2023 16:08:39 +0300 Subject: [PATCH 058/151] see logs --- ...netesDiscoveryClientConfigClientBootstrapConfiguration.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientConfigClientBootstrapConfiguration.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientConfigClientBootstrapConfiguration.java index 7a89cc11a6..b9e37f5fa1 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientConfigClientBootstrapConfiguration.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientConfigClientBootstrapConfiguration.java @@ -32,7 +32,8 @@ @Configuration(proxyBeanMethods = false) @ConditionalOnProperty("spring.cloud.config.discovery.enabled") @Import({ Fabric8AutoConfiguration.class, Fabric8KubernetesDiscoveryClientAutoConfiguration.class }) -@EnableConfigurationProperties({ KubernetesDiscoveryProperties.class, KubernetesClientProperties.class }) +@EnableConfigurationProperties({ KubernetesDiscoveryProperties.class, KubernetesClientProperties.class, + Fabric8DiscoveryClientPredicateAutoConfiguration.class }) class Fabric8KubernetesDiscoveryClientConfigClientBootstrapConfiguration { } From 2e2af4a4adf80230bd9ed4a2103e80ff66e085ee Mon Sep 17 00:00:00 2001 From: wind57 Date: Sun, 23 Apr 2023 11:09:44 +0300 Subject: [PATCH 059/151] fix compilation --- ...rnetesClientInformerSelectiveNamespacesAutoConfiguration.java | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-cloud-kubernetes-client-discovery/src/main/java/org/springframework/cloud/kubernetes/client/discovery/KubernetesClientInformerSelectiveNamespacesAutoConfiguration.java b/spring-cloud-kubernetes-client-discovery/src/main/java/org/springframework/cloud/kubernetes/client/discovery/KubernetesClientInformerSelectiveNamespacesAutoConfiguration.java index 5f44ed9b21..f9373818c7 100644 --- a/spring-cloud-kubernetes-client-discovery/src/main/java/org/springframework/cloud/kubernetes/client/discovery/KubernetesClientInformerSelectiveNamespacesAutoConfiguration.java +++ b/spring-cloud-kubernetes-client-discovery/src/main/java/org/springframework/cloud/kubernetes/client/discovery/KubernetesClientInformerSelectiveNamespacesAutoConfiguration.java @@ -39,6 +39,7 @@ import org.springframework.cloud.client.ConditionalOnDiscoveryEnabled; import org.springframework.cloud.client.discovery.simple.SimpleDiscoveryClientAutoConfiguration; import org.springframework.cloud.kubernetes.client.KubernetesClientAutoConfiguration; +import org.springframework.cloud.kubernetes.commons.discovery.ConditionalOnBlockingOrReactiveEnabled; import org.springframework.cloud.kubernetes.commons.discovery.ConditionalOnKubernetesDiscoveryEnabled; import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryPropertiesAutoConfiguration; From de5476b543789e41b4dcd4b0ebbf6f4a2bfd588e Mon Sep 17 00:00:00 2001 From: wind57 Date: Fri, 28 Apr 2023 19:09:10 +0300 Subject: [PATCH 060/151] fix --- ...tEventBasedSecretsChangeDetectorTests.java | 21 +++++++------------ ...netesDiscoveryClientAutoConfiguration.java | 2 +- ...ubernetesReactiveDiscoveryClientTests.java | 4 ++-- .../Fabric8ReactiveDiscoveryController.java | 7 +++---- 4 files changed, 13 insertions(+), 21 deletions(-) diff --git a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/reload/KubernetesClientEventBasedSecretsChangeDetectorTests.java b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/reload/KubernetesClientEventBasedSecretsChangeDetectorTests.java index c4fa1d326e..98bfef6cf1 100644 --- a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/reload/KubernetesClientEventBasedSecretsChangeDetectorTests.java +++ b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/reload/KubernetesClientEventBasedSecretsChangeDetectorTests.java @@ -183,8 +183,7 @@ void equalsOne() { } /** - * - left is empty map - * - right is null + * - left is empty map - right is null * * treat as equal, that is: no change */ @@ -198,8 +197,7 @@ void equalsTwo() { } /** - * - left is empty map - * - right is null + * - left is empty map - right is null * * treat as equal, that is: no change */ @@ -213,8 +211,7 @@ void equalsThree() { } /** - * - left is null - * - right is empty map + * - left is null - right is empty map * * treat as equal, that is: no change */ @@ -228,8 +225,7 @@ void equalsFour() { } /** - * - left is empty map - * - right is empty map + * - left is empty map - right is empty map * * treat as equal, that is: no change */ @@ -243,8 +239,7 @@ void equalsFive() { } /** - * - left is empty map - * - right is [1, b] + * - left is empty map - right is [1, b] * * treat as non-equal, that is change */ @@ -258,8 +253,7 @@ void equalsSix() { } /** - * - left is [1, a] - * - right is [1, b] + * - left is [1, a] - right is [1, b] * * treat as non-equal, that is change */ @@ -273,8 +267,7 @@ void equalsSeven() { } /** - * - left is [1, a, 2 aa] - * - right is [1, b, 2, aa] + * - left is [1, a, 2 aa] - right is [1, b, 2, aa] * * treat as non-equal, that is change */ diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAutoConfiguration.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAutoConfiguration.java index 91e061d9b7..b461333675 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAutoConfiguration.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAutoConfiguration.java @@ -64,7 +64,7 @@ class Fabric8KubernetesDiscoveryClientAutoConfiguration { private static final LogAccessor LOG = new LogAccessor( - LogFactory.getLog(KubernetesDiscoveryClientAutoConfiguration.class)); + LogFactory.getLog(Fabric8KubernetesDiscoveryClientAutoConfiguration.class)); @Bean @ConditionalOnMissingBean diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientTests.java index 691e8e07cb..39da282237 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientTests.java @@ -84,8 +84,8 @@ void afterEach() { @Test void verifyDefaults() { Fabric8KubernetesDiscoveryClient fabric8KubernetesDiscoveryClient = new Fabric8KubernetesDiscoveryClient( - kubernetesClient, KubernetesDiscoveryProperties.DEFAULT, SERVICE_PORT_SECURE_RESOLVER, - NAMESPACE_PROVIDER, x -> true); + kubernetesClient, KubernetesDiscoveryProperties.DEFAULT, SERVICE_PORT_SECURE_RESOLVER, + NAMESPACE_PROVIDER, x -> true); ReactiveDiscoveryClient client = new Fabric8KubernetesReactiveDiscoveryClient(fabric8KubernetesDiscoveryClient); assertThat(client.description()).isEqualTo("Fabric8 Kubernetes Reactive Discovery Client"); assertThat(client.getOrder()).isEqualTo(ReactiveDiscoveryClient.DEFAULT_ORDER); diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8ReactiveDiscoveryController.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8ReactiveDiscoveryController.java index d497f6f10e..a6bfe8531f 100644 --- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8ReactiveDiscoveryController.java +++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8ReactiveDiscoveryController.java @@ -22,7 +22,6 @@ import org.springframework.beans.factory.ObjectProvider; import org.springframework.cloud.client.ServiceInstance; -import org.springframework.cloud.kubernetes.fabric8.discovery.reactive.KubernetesReactiveDiscoveryClient; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RestController; @@ -33,11 +32,11 @@ @RestController public class Fabric8ReactiveDiscoveryController { - private final KubernetesReactiveDiscoveryClient reactiveDiscoveryClient; + private final Fabric8KubernetesReactiveDiscoveryClient reactiveDiscoveryClient; public Fabric8ReactiveDiscoveryController( - ObjectProvider reactiveDiscoveryClient) { - KubernetesReactiveDiscoveryClient[] local = new KubernetesReactiveDiscoveryClient[1]; + ObjectProvider reactiveDiscoveryClient) { + Fabric8KubernetesReactiveDiscoveryClient[] local = new Fabric8KubernetesReactiveDiscoveryClient[1]; reactiveDiscoveryClient.ifAvailable(x -> local[0] = x); this.reactiveDiscoveryClient = local[0]; } From 1481bd1fdc9a3e9e04aac54c0a94b917c2a38503 Mon Sep 17 00:00:00 2001 From: wind57 Date: Mon, 17 Jul 2023 14:20:27 +0300 Subject: [PATCH 061/151] fix bad merge --- .../Fabric8ConfigServerBootstrapper.java | 15 +++-- ...ernetesClientServicesFunctionProvider.java | 64 ------------------- 2 files changed, 9 insertions(+), 70 deletions(-) delete mode 100644 spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesClientServicesFunctionProvider.java diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8ConfigServerBootstrapper.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8ConfigServerBootstrapper.java index 46e5d63963..a3e1ba0389 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8ConfigServerBootstrapper.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8ConfigServerBootstrapper.java @@ -30,6 +30,7 @@ import org.springframework.cloud.client.ServiceInstance; import org.springframework.cloud.config.client.ConfigServerInstanceProvider; import org.springframework.cloud.kubernetes.commons.KubernetesClientProperties; +import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider; import org.springframework.cloud.kubernetes.commons.config.KubernetesConfigServerBootstrapper; import org.springframework.cloud.kubernetes.commons.config.KubernetesConfigServerInstanceProvider; import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; @@ -85,18 +86,20 @@ public List apply(String serviceId, Binder binder, BindHandler private KubernetesConfigServerInstanceProvider getInstanceProvider( KubernetesDiscoveryProperties discoveryProperties, KubernetesClientProperties clientProperties, BootstrapContext context, Binder binder, BindHandler bindHandler) { - if (context.isRegistered(KubernetesDiscoveryClient.class)) { - KubernetesDiscoveryClient client = context.get(KubernetesDiscoveryClient.class); + if (context.isRegistered(Fabric8KubernetesDiscoveryClient.class)) { + Fabric8KubernetesDiscoveryClient client = context.get(Fabric8KubernetesDiscoveryClient.class); return client::getInstances; } else { Fabric8AutoConfiguration fabric8AutoConfiguration = new Fabric8AutoConfiguration(); Config config = fabric8AutoConfiguration.kubernetesClientConfig(clientProperties); KubernetesClient kubernetesClient = fabric8AutoConfiguration.kubernetesClient(config); - KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(kubernetesClient, - discoveryProperties, KubernetesClientServicesFunctionProvider - .servicesFunction(discoveryProperties, binder, bindHandler), - null, new ServicePortSecureResolver(discoveryProperties)); + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient( + kubernetesClient, + discoveryProperties, + new ServicePortSecureResolver(discoveryProperties), + new KubernetesNamespaceProvider(binder, bindHandler), + new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(discoveryProperties)); return discoveryClient::getInstances; } } diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesClientServicesFunctionProvider.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesClientServicesFunctionProvider.java deleted file mode 100644 index 820d3a3f72..0000000000 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesClientServicesFunctionProvider.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2013-2023 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.discovery; - -import org.springframework.boot.context.properties.bind.BindHandler; -import org.springframework.boot.context.properties.bind.Binder; -import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider; -import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; -import org.springframework.cloud.kubernetes.fabric8.Fabric8Utils; -import org.springframework.core.env.Environment; - -/** - * @author wind57 - */ -public final class KubernetesClientServicesFunctionProvider { - - private KubernetesClientServicesFunctionProvider() { - } - - public static KubernetesClientServicesFunction servicesFunction(KubernetesDiscoveryProperties properties, - Environment environment) { - - if (properties.allNamespaces()) { - return (client) -> client.services().inAnyNamespace().withLabels(properties.serviceLabels()); - } - - return client -> { - String namespace = Fabric8Utils.getApplicationNamespace(client, null, "discovery-service", - new KubernetesNamespaceProvider(environment)); - return client.services().inNamespace(namespace).withLabels(properties.serviceLabels()); - }; - - } - - public static KubernetesClientServicesFunction servicesFunction(KubernetesDiscoveryProperties properties, - Binder binder, BindHandler bindHandler) { - - if (properties.allNamespaces()) { - return (client) -> client.services().inAnyNamespace().withLabels(properties.serviceLabels()); - } - - return client -> { - String namespace = Fabric8Utils.getApplicationNamespace(client, null, "discovery-service", - new KubernetesNamespaceProvider(binder, bindHandler)); - return client.services().inNamespace(namespace).withLabels(properties.serviceLabels()); - }; - - } - -} From cedf0492083cb314bbc24037a4db577af2b0b68c Mon Sep 17 00:00:00 2001 From: wind57 Date: Wed, 19 Jul 2023 07:27:45 +0300 Subject: [PATCH 062/151] trigger From b9c4ee21bb079f50404eea73fa806ef7d043def5 Mon Sep 17 00:00:00 2001 From: wind57 Date: Tue, 25 Jul 2023 09:24:50 +0300 Subject: [PATCH 063/151] trigger From 117e9a0fa1e0eb1c71fd1e9d14936ab2054e91b7 Mon Sep 17 00:00:00 2001 From: wind57 Date: Sat, 5 Aug 2023 14:37:04 +0300 Subject: [PATCH 064/151] fix issue --- .../discovery/Fabric8KubernetesDiscoveryClientFilterTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientFilterTest.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientFilterTest.java index c74eeb4235..4acd02ee51 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientFilterTest.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientFilterTest.java @@ -35,6 +35,7 @@ import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider; import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; +import org.springframework.cloud.kubernetes.commons.discovery.ServicePortSecureResolver; import org.springframework.core.env.Environment; import org.springframework.mock.env.MockEnvironment; From ac49d21334ac89ebfc2647467b01eea0a2c8366c Mon Sep 17 00:00:00 2001 From: wind57 Date: Sat, 5 Aug 2023 18:23:16 +0300 Subject: [PATCH 065/151] fix compilation issues --- .../Fabric8KubernetesDiscoveryClientFilterMetadataTest.java | 1 + .../discovery/Fabric8KubernetesReactiveDiscoveryClientTests.java | 1 + 2 files changed, 2 insertions(+) diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientFilterMetadataTest.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientFilterMetadataTest.java index 6835efa2fe..da5eb00366 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientFilterMetadataTest.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientFilterMetadataTest.java @@ -47,6 +47,7 @@ import org.springframework.cloud.client.ServiceInstance; import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider; import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; +import org.springframework.cloud.kubernetes.commons.discovery.ServicePortSecureResolver; import org.springframework.core.env.Environment; import org.springframework.mock.env.MockEnvironment; diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientTests.java index 39da282237..940f91e1a5 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientTests.java @@ -42,6 +42,7 @@ import org.springframework.cloud.client.discovery.ReactiveDiscoveryClient; import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider; import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; +import org.springframework.cloud.kubernetes.commons.discovery.ServicePortSecureResolver; import org.springframework.core.env.Environment; import org.springframework.mock.env.MockEnvironment; From 66c525613a583d6f3d29f64a0feebdce17c5efaf Mon Sep 17 00:00:00 2001 From: wind57 Date: Tue, 8 Aug 2023 08:25:58 +0300 Subject: [PATCH 066/151] fix --- ...Fabric8KubernetesDiscoveryClientUtils.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtils.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtils.java index 1d43d5f235..e8a5a50feb 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtils.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtils.java @@ -68,6 +68,35 @@ static EndpointSubsetNS subsetsFromEndpoints(Endpoints endpoints) { return new EndpointSubsetNS(endpoints.getMetadata().getNamespace(), endpoints.getSubsets()); } + static List endpointSlices(KubernetesDiscoveryProperties properties, KubernetesClient client, + KubernetesNamespaceProvider namespaceProvider, String target) { + + List endpointSlices; + + if (properties.allNamespaces()) { + LOG.debug(() -> "discovering endpoint slices in all namespaces"); + endpointSlices = filteredEndpointSlices( + client.discovery().v1().endpointSlices().inAnyNamespace().withNewFilter(), properties); + } + else if (!properties.namespaces().isEmpty()) { + LOG.debug(() -> "discovering endpoint slices in namespaces : " + properties.namespaces()); + List inner = new ArrayList<>(properties.namespaces().size()); + properties.namespaces() + .forEach(namespace -> inner.addAll(filteredEndpointSlices( + client.discovery().v1().endpointSlices().inNamespace(namespace).withNewFilter(), + properties))); + endpointSlices = inner; + } + else { + String namespace = Fabric8Utils.getApplicationNamespace(client, null, target, namespaceProvider); + LOG.debug(() -> "discovering endpoint slices in namespace : " + namespace); + endpointSlices = filteredEndpointSlices( + client.discovery().v1().endpointSlices().inNamespace(namespace).withNewFilter(), properties); + } + + return endpointSlices; + } + static List endpoints(KubernetesDiscoveryProperties properties, KubernetesClient client, KubernetesNamespaceProvider namespaceProvider, String target, @Nullable String serviceName, Predicate filter) { From 11edd5ed956040bb5a611b37e3b95930fd88806d Mon Sep 17 00:00:00 2001 From: wind57 Date: Tue, 8 Aug 2023 11:23:12 +0300 Subject: [PATCH 067/151] fix --- ...c8KubernetesDiscoveryClientUtilsTests.java | 83 ------------------- 1 file changed, 83 deletions(-) diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtilsTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtilsTests.java index c8a2182c3f..cf3214aacb 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtilsTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtilsTests.java @@ -27,7 +27,6 @@ import io.fabric8.kubernetes.api.model.EndpointSubsetBuilder; import io.fabric8.kubernetes.api.model.Endpoints; import io.fabric8.kubernetes.api.model.EndpointsBuilder; -import io.fabric8.kubernetes.api.model.ObjectMeta; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.fabric8.kubernetes.api.model.Service; import io.fabric8.kubernetes.api.model.ServiceBuilder; @@ -39,13 +38,11 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.boot.test.system.CapturedOutput; import org.springframework.boot.test.system.OutputCaptureExtension; import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider; import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; import org.springframework.mock.env.MockEnvironment; -import static org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryConstants.PRIMARY_PORT_NAME_LABEL_KEY; import static org.springframework.cloud.kubernetes.fabric8.discovery.Fabric8KubernetesDiscoveryClientUtils.services; /** @@ -87,23 +84,6 @@ void testSubsetsFromEndpointsNonEmptySubsets() { } - /* - *
 - properties do not have primary-port-name set - service labels do not have
-	 * primary-port-name set
-	 *
-	 * As such null is returned. 
- */ - @Test - void testPrimaryPortNameNotFound(CapturedOutput output) { - KubernetesDiscoveryProperties properties = KubernetesDiscoveryProperties.DEFAULT; - Service service = new ServiceBuilder().withMetadata(new ObjectMeta()).build(); - - String result = Fabric8KubernetesDiscoveryClientUtils.primaryPortName(properties, service, "abc"); - Assertions.assertNull(result); - Assertions.assertTrue(output.getOut().contains( - "did not find a primary-port-name in neither properties nor service labels for service with ID : abc")); - } - /* *
 - all-namespaces = true - serviceA present in namespace "A" - serviceB
 	 * present in namespace "B" - no filters are applied, so both are present 
@@ -122,69 +102,6 @@ void testServicesAllNamespacesNoFilters() { List.of("serviceA", "serviceB")); } - /** - *
-	 *     - properties do have primary-port-name set to "https"
-	 *     - service labels do not have primary-port-name set
-	 *
-	 *     As such "https" is returned.
-	 * 
- */ - @Test - void testPrimaryPortNameFoundInProperties(CapturedOutput output) { - String primaryPortName = "https"; - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - true, "", Set.of(), Map.of(), primaryPortName, null, 0, false, false); - Service service = new ServiceBuilder().withMetadata(new ObjectMeta()).build(); - - String result = Fabric8KubernetesDiscoveryClientUtils.primaryPortName(properties, service, "abc"); - Assertions.assertNotNull(result); - Assertions.assertEquals(result, primaryPortName); - Assertions.assertTrue(output.getOut().contains("will use primaryPortName : https for service with ID = abc")); - } - - /** - *
-	 *     - properties do not have primary-port-name set
-	 *     - service labels do have primary-port-name set to "https"
-	 *
-	 *     As such "https" is returned.
-	 * 
- */ - @Test - void testPrimaryPortNameFoundInLabels(CapturedOutput output) { - Map labels = Map.of(PRIMARY_PORT_NAME_LABEL_KEY, "https"); - KubernetesDiscoveryProperties properties = KubernetesDiscoveryProperties.DEFAULT; - Service service = new ServiceBuilder().withMetadata(new ObjectMetaBuilder().withLabels(labels).build()).build(); - - String result = Fabric8KubernetesDiscoveryClientUtils.primaryPortName(properties, service, "abc"); - Assertions.assertNotNull(result); - Assertions.assertEquals(result, "https"); - Assertions.assertTrue(output.getOut().contains("will use primaryPortName : https for service with ID = abc")); - } - - /** - *
-	 *     - properties do have primary-port-name set to "https"
-	 *     - service labels do have primary-port-name set to "http"
-	 *
-	 *     As such "http" is returned (labels win).
-	 * 
- */ - @Test - void testPrimaryPortNameFoundInBothPropertiesAndLabels(CapturedOutput output) { - String primaryPortName = "https"; - Map labels = Map.of(PRIMARY_PORT_NAME_LABEL_KEY, "http"); - KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L, - true, "", Set.of(), Map.of(), primaryPortName, null, 0, false, false); - Service service = new ServiceBuilder().withMetadata(new ObjectMetaBuilder().withLabels(labels).build()).build(); - - String result = Fabric8KubernetesDiscoveryClientUtils.primaryPortName(properties, service, "abc"); - Assertions.assertNotNull(result); - Assertions.assertEquals(result, "http"); - Assertions.assertTrue(output.getOut().contains("will use primaryPortName : http for service with ID = abc")); - } - /* *
 - all-namespaces = true - serviceA present in namespace "A" - serviceB
 	 * present in namespace "B" - we search only for "serviceA" filter, so only one is

From ebf25e5f8cfd24efb6a5c93c78e528e2138422a9 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Tue, 8 Aug 2023 12:28:46 +0300
Subject: [PATCH 068/151] trigger


From 2c0e235cbaefc2b20b2a9c35b681067d1dc4db84 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Tue, 22 Aug 2023 22:33:09 +0300
Subject: [PATCH 069/151] checkstyle

---
 .../discovery/Fabric8KubernetesDiscoveryClientUtils.java  | 2 +-
 .../fabric8/discovery/Fabric8DiscoveryPodMetadataIT.java  | 8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtils.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtils.java
index 2d0680a6a8..fb48144063 100644
--- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtils.java
+++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtils.java
@@ -32,9 +32,9 @@
 import io.fabric8.kubernetes.api.model.ObjectMeta;
 import io.fabric8.kubernetes.api.model.Service;
 import io.fabric8.kubernetes.api.model.ServiceList;
+import io.fabric8.kubernetes.api.model.ServiceSpec;
 import io.fabric8.kubernetes.api.model.discovery.v1.EndpointSlice;
 import io.fabric8.kubernetes.api.model.discovery.v1.EndpointSliceList;
-import io.fabric8.kubernetes.api.model.ServiceSpec;
 import io.fabric8.kubernetes.client.KubernetesClient;
 import io.fabric8.kubernetes.client.dsl.FilterNested;
 import io.fabric8.kubernetes.client.dsl.FilterWatchListDeletable;
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryPodMetadataIT.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryPodMetadataIT.java
index e932c34dc4..b47f2db05c 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryPodMetadataIT.java
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryPodMetadataIT.java
@@ -246,14 +246,14 @@ private static void manifests(Phase phase) {
 		Ingress ingress = client.network().v1().ingresses().load(ingressStream).item();
 
 		if (phase.equals(Phase.CREATE)) {
-			client.rbac().clusterRoleBindings().resource(client.rbac().clusterRoleBindings().load(getAdminRole()).item())
-					.create();
+			client.rbac().clusterRoleBindings()
+					.resource(client.rbac().clusterRoleBindings().load(getAdminRole()).item()).create();
 			util.createAndWait(NAMESPACE, IMAGE_NAME, deployment, discoveryService, ingress, true);
 			util.createAndWait(NAMESPACE, null, null, externalServiceName, null, true);
 		}
 		else {
-			client.rbac().clusterRoleBindings().resource(client.rbac().clusterRoleBindings().load(getAdminRole()).item())
-					.delete();
+			client.rbac().clusterRoleBindings()
+					.resource(client.rbac().clusterRoleBindings().load(getAdminRole()).item()).delete();
 			util.deleteAndWait(NAMESPACE, deployment, discoveryService, ingress);
 			util.deleteAndWait(NAMESPACE, null, externalServiceName, null);
 		}

From 58fbdbad79109b51c26e1fe64c25512cb1b92c4d Mon Sep 17 00:00:00 2001
From: wind57 
Date: Tue, 22 Aug 2023 23:08:49 +0300
Subject: [PATCH 070/151] fix compilation

---
 ...ubernetesDiscoveryClientServiceWithoutPortNameTests.java | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientServiceWithoutPortNameTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientServiceWithoutPortNameTests.java
index 9a774b1051..a1b33916ff 100644
--- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientServiceWithoutPortNameTests.java
+++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientServiceWithoutPortNameTests.java
@@ -36,7 +36,9 @@
 import org.junit.jupiter.api.Test;
 
 import org.springframework.cloud.client.ServiceInstance;
+import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider;
 import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
+import org.springframework.cloud.kubernetes.commons.discovery.ServicePortSecureResolver;
 
 /**
  * @author wind57
@@ -67,7 +69,9 @@ void testDiscoveryWithoutAServicePortName() {
 		KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(NAMESPACE),
 				true, 60, false, null, Set.of(), Map.of(), null, KubernetesDiscoveryProperties.Metadata.DEFAULT, 0,
 				true);
-		KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(mockClient, properties, a -> null);
+		Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, properties,
+			new ServicePortSecureResolver(properties), new KubernetesNamespaceProvider(null),
+			a -> true);
 
 		List serviceInstances = discoveryClient.getInstances("no-port-name-service");
 		Assertions.assertEquals(serviceInstances.size(), 1);

From 3386a3ed459367856146230ee59de915fde59101 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Wed, 23 Aug 2023 07:52:35 +0300
Subject: [PATCH 071/151] fix compilation

---
 .../composites/maven-build-with-dry-run-for-tests/action.yaml   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/workflows/composites/maven-build-with-dry-run-for-tests/action.yaml b/.github/workflows/composites/maven-build-with-dry-run-for-tests/action.yaml
index dd709b8062..2c04237a0d 100644
--- a/.github/workflows/composites/maven-build-with-dry-run-for-tests/action.yaml
+++ b/.github/workflows/composites/maven-build-with-dry-run-for-tests/action.yaml
@@ -8,7 +8,7 @@ runs:
       run: |
           # find all the tests that are supposed to be run, but don't actually run them.
           # this is achieved via: 'spring.cloud.k8s.skip.tests=true' in DisabledTestsCondition
-          ./mvnw test -B -Dskip.build.image=true -Dspring.cloud.k8s.skip.tests=true \
+          ./mvnw package -B -Dskip.build.image=true -Dspring.cloud.k8s.skip.tests=true \
                 -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=error \
                 -T 1C -q > /tmp/tests.txt
 

From 280b1b547b8dba21f293e00c284720e4c7664d57 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Wed, 23 Aug 2023 08:10:44 +0300
Subject: [PATCH 072/151] fix compilation

---
 .../composites/maven-build-with-dry-run-for-tests/action.yaml   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/workflows/composites/maven-build-with-dry-run-for-tests/action.yaml b/.github/workflows/composites/maven-build-with-dry-run-for-tests/action.yaml
index 2c04237a0d..33e71aecf8 100644
--- a/.github/workflows/composites/maven-build-with-dry-run-for-tests/action.yaml
+++ b/.github/workflows/composites/maven-build-with-dry-run-for-tests/action.yaml
@@ -8,7 +8,7 @@ runs:
       run: |
           # find all the tests that are supposed to be run, but don't actually run them.
           # this is achieved via: 'spring.cloud.k8s.skip.tests=true' in DisabledTestsCondition
-          ./mvnw package -B -Dskip.build.image=true -Dspring.cloud.k8s.skip.tests=true \
+          ./mvnw install -B -Dskip.build.image=true -Dspring.cloud.k8s.skip.tests=true \
                 -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=error \
                 -T 1C -q > /tmp/tests.txt
 

From a6b2ca8d1f4b6902f6b8543c2db9181e451909a5 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Wed, 20 Sep 2023 11:15:01 +0300
Subject: [PATCH 073/151] fix issue

---
 ...rnetesClientDiscoveryHealthITDelegate.java | 69 ++++++++++---------
 .../it/DiscoveryClientFilterNamespaceIT.java  |  7 +-
 2 files changed, 40 insertions(+), 36 deletions(-)

diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-discovery-it/src/test/java/org/springframework/cloud/kubernetes/client/discovery/it/KubernetesClientDiscoveryHealthITDelegate.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-discovery-it/src/test/java/org/springframework/cloud/kubernetes/client/discovery/it/KubernetesClientDiscoveryHealthITDelegate.java
index ee03815f27..f11fb27899 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-discovery-it/src/test/java/org/springframework/cloud/kubernetes/client/discovery/it/KubernetesClientDiscoveryHealthITDelegate.java
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-discovery-it/src/test/java/org/springframework/cloud/kubernetes/client/discovery/it/KubernetesClientDiscoveryHealthITDelegate.java
@@ -156,8 +156,8 @@ void testDefaultConfiguration(K3sContainer container) {
 
 		String healthResult = healthClient.method(HttpMethod.GET).retrieve().bodyToMono(String.class)
 				.retryWhen(retrySpec()).block();
-		String infoResult = infoClient.method(HttpMethod.GET).retrieve().bodyToMono(String.class)
-			.retryWhen(retrySpec()).block();
+		String infoResult = infoClient.method(HttpMethod.GET).retrieve().bodyToMono(String.class).retryWhen(retrySpec())
+				.block();
 
 		Assertions.assertThat(BASIC_JSON_TESTER.from(healthResult))
 				.extractingJsonPathStringValue("$.components.discoveryComposite.status").isEqualTo("UP");
@@ -188,55 +188,56 @@ void testDefaultConfiguration(K3sContainer container) {
 	}
 
 	private void assertHealth(String healthResult) {
-		Assertions.assertThat(BASIC_JSON_TESTER.from(healthResult)).extractingJsonPathStringValue(
-			"$.components.kubernetes.status").isEqualTo("UP");
+		Assertions.assertThat(BASIC_JSON_TESTER.from(healthResult))
+				.extractingJsonPathStringValue("$.components.kubernetes.status").isEqualTo("UP");
 
-		Assertions.assertThat(BASIC_JSON_TESTER.from(healthResult)).extractingJsonPathStringValue(
-			"$.components.kubernetes.details.hostIp").isNotEmpty();
+		Assertions.assertThat(BASIC_JSON_TESTER.from(healthResult))
+				.extractingJsonPathStringValue("$.components.kubernetes.details.hostIp").isNotEmpty();
 
-		Assertions.assertThat(BASIC_JSON_TESTER.from(healthResult)).extractingJsonPathBooleanValue(
-			"$.components.kubernetes.details.inside").isEqualTo(true);
+		Assertions.assertThat(BASIC_JSON_TESTER.from(healthResult))
+				.extractingJsonPathBooleanValue("$.components.kubernetes.details.inside").isEqualTo(true);
 
-		Assertions.assertThat(BASIC_JSON_TESTER.from(healthResult)).extractingJsonPathStringValue(
-			"$.components.kubernetes.details.labels.app").isEqualTo("spring-cloud-kubernetes-client-discovery-it");
+		Assertions.assertThat(BASIC_JSON_TESTER.from(healthResult))
+				.extractingJsonPathStringValue("$.components.kubernetes.details.labels.app")
+				.isEqualTo("spring-cloud-kubernetes-client-discovery-it");
 
-		Assertions.assertThat(BASIC_JSON_TESTER.from(healthResult)).extractingJsonPathStringValue(
-			"$.components.kubernetes.details.namespace").isNotEmpty();
+		Assertions.assertThat(BASIC_JSON_TESTER.from(healthResult))
+				.extractingJsonPathStringValue("$.components.kubernetes.details.namespace").isNotEmpty();
 
-		Assertions.assertThat(BASIC_JSON_TESTER.from(healthResult)).extractingJsonPathStringValue(
-			"$.components.kubernetes.details.nodeName").isNotEmpty();
+		Assertions.assertThat(BASIC_JSON_TESTER.from(healthResult))
+				.extractingJsonPathStringValue("$.components.kubernetes.details.nodeName").isNotEmpty();
 
-		Assertions.assertThat(BASIC_JSON_TESTER.from(healthResult)).extractingJsonPathStringValue(
-			"$.components.kubernetes.details.podIp").isNotEmpty();
+		Assertions.assertThat(BASIC_JSON_TESTER.from(healthResult))
+				.extractingJsonPathStringValue("$.components.kubernetes.details.podIp").isNotEmpty();
 
-		Assertions.assertThat(BASIC_JSON_TESTER.from(healthResult)).extractingJsonPathStringValue(
-			"$.components.kubernetes.details.podName").isNotEmpty();
+		Assertions.assertThat(BASIC_JSON_TESTER.from(healthResult))
+				.extractingJsonPathStringValue("$.components.kubernetes.details.podName").isNotEmpty();
 
-		Assertions.assertThat(BASIC_JSON_TESTER.from(healthResult)).extractingJsonPathStringValue(
-			"$.components.kubernetes.details.serviceAccount").isNotEmpty();
+		Assertions.assertThat(BASIC_JSON_TESTER.from(healthResult))
+				.extractingJsonPathStringValue("$.components.kubernetes.details.serviceAccount").isNotEmpty();
 	}
 
 	private void assertInfo(String infoResult) {
-		Assertions.assertThat(BASIC_JSON_TESTER.from(infoResult)).extractingJsonPathStringValue(
-			"$.kubernetes.hostIp").isNotEmpty();
+		Assertions.assertThat(BASIC_JSON_TESTER.from(infoResult)).extractingJsonPathStringValue("$.kubernetes.hostIp")
+				.isNotEmpty();
 
-		Assertions.assertThat(BASIC_JSON_TESTER.from(infoResult)).extractingJsonPathBooleanValue(
-			"$.kubernetes.inside").isEqualTo(true);
+		Assertions.assertThat(BASIC_JSON_TESTER.from(infoResult)).extractingJsonPathBooleanValue("$.kubernetes.inside")
+				.isEqualTo(true);
 
-		Assertions.assertThat(BASIC_JSON_TESTER.from(infoResult)).extractingJsonPathStringValue(
-			"$.kubernetes.namespace").isNotEmpty();
+		Assertions.assertThat(BASIC_JSON_TESTER.from(infoResult))
+				.extractingJsonPathStringValue("$.kubernetes.namespace").isNotEmpty();
 
-		Assertions.assertThat(BASIC_JSON_TESTER.from(infoResult)).extractingJsonPathStringValue(
-			"$.kubernetes.nodeName").isNotEmpty();
+		Assertions.assertThat(BASIC_JSON_TESTER.from(infoResult)).extractingJsonPathStringValue("$.kubernetes.nodeName")
+				.isNotEmpty();
 
-		Assertions.assertThat(BASIC_JSON_TESTER.from(infoResult)).extractingJsonPathStringValue(
-			"$.kubernetes.podIp").isNotEmpty();
+		Assertions.assertThat(BASIC_JSON_TESTER.from(infoResult)).extractingJsonPathStringValue("$.kubernetes.podIp")
+				.isNotEmpty();
 
-		Assertions.assertThat(BASIC_JSON_TESTER.from(infoResult)).extractingJsonPathStringValue(
-			"$.kubernetes.podName").isNotEmpty();
+		Assertions.assertThat(BASIC_JSON_TESTER.from(infoResult)).extractingJsonPathStringValue("$.kubernetes.podName")
+				.isNotEmpty();
 
-		Assertions.assertThat(BASIC_JSON_TESTER.from(infoResult)).extractingJsonPathStringValue(
-			"$.kubernetes.serviceAccount").isNotEmpty();
+		Assertions.assertThat(BASIC_JSON_TESTER.from(infoResult))
+				.extractingJsonPathStringValue("$.kubernetes.serviceAccount").isNotEmpty();
 	}
 
 	private WebClient.Builder builder() {
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-discoveryclient-it/src/test/java/org/springframework/cloud/kubernetes/discoveryclient/it/DiscoveryClientFilterNamespaceIT.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-discoveryclient-it/src/test/java/org/springframework/cloud/kubernetes/discoveryclient/it/DiscoveryClientFilterNamespaceIT.java
index 65491ee126..3d42774cdc 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-discoveryclient-it/src/test/java/org/springframework/cloud/kubernetes/discoveryclient/it/DiscoveryClientFilterNamespaceIT.java
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-discoveryclient-it/src/test/java/org/springframework/cloud/kubernetes/discoveryclient/it/DiscoveryClientFilterNamespaceIT.java
@@ -71,6 +71,8 @@ class DiscoveryClientFilterNamespaceIT {
 
 	private static RbacAuthorizationV1Api rbacApi;
 
+	private static V1ClusterRoleBinding clusterRole;
+
 	@BeforeAll
 	static void beforeAll() throws Exception {
 		K3S.start();
@@ -83,18 +85,19 @@ static void beforeAll() throws Exception {
 
 		util = new Util(K3S);
 		rbacApi = new RbacAuthorizationV1Api();
+		clusterRole = (V1ClusterRoleBinding) util
+				.yaml("namespace-filter/cluster-admin-serviceaccount-role.yaml");
 		util.createNamespace(NAMESPACE_LEFT);
 		util.createNamespace(NAMESPACE_RIGHT);
 		util.setUp(NAMESPACE);
 
-		V1ClusterRoleBinding clusterRole = (V1ClusterRoleBinding) util
-				.yaml("namespace-filter/cluster-admin-serviceaccount-role.yaml");
 		rbacApi.createClusterRoleBinding(clusterRole, null, null, null, null);
 		discoveryServer(Phase.CREATE);
 	}
 
 	@AfterAll
 	static void afterAll() throws Exception {
+		rbacApi.deleteClusterRoleBinding(clusterRole.getMetadata().getName(), null, null, null, null, null, null);
 		Commons.cleanUp(DISCOVERY_SERVER_APP_NAME, K3S);
 		Commons.cleanUp(SPRING_CLOUD_K8S_DISCOVERY_CLIENT_APP_NAME, K3S);
 		discoveryServer(Phase.DELETE);

From 3ed982ac5035dc2ebfea0b49d4d50e6353d8ad62 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Wed, 20 Sep 2023 12:42:06 +0300
Subject: [PATCH 074/151] fix issue

---
 .../it/DiscoveryClientFilterNamespaceIT.java         |  9 +++++----
 .../discoveryclient/it/DiscoveryClientIT.java        | 12 +++++++++---
 2 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-discoveryclient-it/src/test/java/org/springframework/cloud/kubernetes/discoveryclient/it/DiscoveryClientFilterNamespaceIT.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-discoveryclient-it/src/test/java/org/springframework/cloud/kubernetes/discoveryclient/it/DiscoveryClientFilterNamespaceIT.java
index 3d42774cdc..fe10560904 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-discoveryclient-it/src/test/java/org/springframework/cloud/kubernetes/discoveryclient/it/DiscoveryClientFilterNamespaceIT.java
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-discoveryclient-it/src/test/java/org/springframework/cloud/kubernetes/discoveryclient/it/DiscoveryClientFilterNamespaceIT.java
@@ -71,7 +71,7 @@ class DiscoveryClientFilterNamespaceIT {
 
 	private static RbacAuthorizationV1Api rbacApi;
 
-	private static V1ClusterRoleBinding clusterRole;
+	private static V1ClusterRoleBinding clusterRoleBinding;
 
 	@BeforeAll
 	static void beforeAll() throws Exception {
@@ -85,19 +85,20 @@ static void beforeAll() throws Exception {
 
 		util = new Util(K3S);
 		rbacApi = new RbacAuthorizationV1Api();
-		clusterRole = (V1ClusterRoleBinding) util
+		clusterRoleBinding = (V1ClusterRoleBinding) util
 				.yaml("namespace-filter/cluster-admin-serviceaccount-role.yaml");
 		util.createNamespace(NAMESPACE_LEFT);
 		util.createNamespace(NAMESPACE_RIGHT);
 		util.setUp(NAMESPACE);
 
-		rbacApi.createClusterRoleBinding(clusterRole, null, null, null, null);
+		rbacApi.createClusterRoleBinding(clusterRoleBinding, null, null, null, null);
 		discoveryServer(Phase.CREATE);
 	}
 
 	@AfterAll
 	static void afterAll() throws Exception {
-		rbacApi.deleteClusterRoleBinding(clusterRole.getMetadata().getName(), null, null, null, null, null, null);
+		rbacApi.deleteClusterRoleBinding(clusterRoleBinding.getMetadata().getName(), null, null, null, null, null,
+				null);
 		Commons.cleanUp(DISCOVERY_SERVER_APP_NAME, K3S);
 		Commons.cleanUp(SPRING_CLOUD_K8S_DISCOVERY_CLIENT_APP_NAME, K3S);
 		discoveryServer(Phase.DELETE);
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-discoveryclient-it/src/test/java/org/springframework/cloud/kubernetes/discoveryclient/it/DiscoveryClientIT.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-discoveryclient-it/src/test/java/org/springframework/cloud/kubernetes/discoveryclient/it/DiscoveryClientIT.java
index 7f4903717e..e3ca48a385 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-discoveryclient-it/src/test/java/org/springframework/cloud/kubernetes/discoveryclient/it/DiscoveryClientIT.java
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-discoveryclient-it/src/test/java/org/springframework/cloud/kubernetes/discoveryclient/it/DiscoveryClientIT.java
@@ -113,6 +113,10 @@ class DiscoveryClientIT {
 
 	private static Util util;
 
+	private static RbacAuthorizationV1Api rbacApi;
+
+	private static V1ClusterRoleBinding clusterRoleBinding;
+
 	@BeforeAll
 	static void beforeAll() throws Exception {
 		K3S.start();
@@ -124,15 +128,15 @@ static void beforeAll() throws Exception {
 		Commons.loadSpringCloudKubernetesImage(SPRING_CLOUD_K8S_DISCOVERY_CLIENT_APP_NAME, K3S);
 
 		util = new Util(K3S);
+		rbacApi = new RbacAuthorizationV1Api();
 		util.setUp(NAMESPACE);
 
 		util.createNamespace(NAMESPACE_LEFT);
 		util.createNamespace(NAMESPACE_RIGHT);
 
-		RbacAuthorizationV1Api rbacApi = new RbacAuthorizationV1Api();
-		V1ClusterRoleBinding clusterRole = (V1ClusterRoleBinding) util
+		clusterRoleBinding = (V1ClusterRoleBinding) util
 				.yaml("namespace-filter/cluster-admin-serviceaccount-role.yaml");
-		rbacApi.createClusterRoleBinding(clusterRole, null, null, null, null);
+		rbacApi.createClusterRoleBinding(clusterRoleBinding, null, null, null, null);
 
 		util.wiremock(NAMESPACE_LEFT, "/wiremock-" + NAMESPACE_LEFT, Phase.CREATE, false);
 		util.wiremock(NAMESPACE_RIGHT, "/wiremock-" + NAMESPACE_RIGHT, Phase.CREATE, false);
@@ -143,6 +147,8 @@ static void beforeAll() throws Exception {
 
 	@AfterAll
 	static void afterAll() throws Exception {
+		rbacApi.deleteClusterRoleBinding(clusterRoleBinding.getMetadata().getName(), null, null, null, null, null,
+				null);
 		Commons.cleanUp(DISCOVERY_SERVER_APP_NAME, K3S);
 		Commons.cleanUp(SPRING_CLOUD_K8S_DISCOVERY_CLIENT_APP_NAME, K3S);
 

From a8aecc6a6d00c42f86eff04d4258607faa2e5c7f Mon Sep 17 00:00:00 2001
From: wind57 
Date: Thu, 21 Sep 2023 19:25:44 +0300
Subject: [PATCH 075/151] fix

---
 .../composites/maven-build-with-dry-run-for-tests/action.yaml   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/workflows/composites/maven-build-with-dry-run-for-tests/action.yaml b/.github/workflows/composites/maven-build-with-dry-run-for-tests/action.yaml
index 3230b5945f..5e6b4397cb 100644
--- a/.github/workflows/composites/maven-build-with-dry-run-for-tests/action.yaml
+++ b/.github/workflows/composites/maven-build-with-dry-run-for-tests/action.yaml
@@ -10,7 +10,7 @@ runs:
         ./mvnw install -B  \
               -Dskip.build.image=true \
               -DskipTests -DskipITs \
-              -T 1C -q
+              -T -U 1C -q
 
     - name: find all classpath entries
       shell: bash

From dc17a0f197cefcde86dfba4f575ade02c0686653 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Thu, 21 Sep 2023 19:33:17 +0300
Subject: [PATCH 076/151] test

---
 .../composites/maven-build-with-dry-run-for-tests/action.yaml   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/workflows/composites/maven-build-with-dry-run-for-tests/action.yaml b/.github/workflows/composites/maven-build-with-dry-run-for-tests/action.yaml
index 5e6b4397cb..a6d5c279ff 100644
--- a/.github/workflows/composites/maven-build-with-dry-run-for-tests/action.yaml
+++ b/.github/workflows/composites/maven-build-with-dry-run-for-tests/action.yaml
@@ -10,7 +10,7 @@ runs:
         ./mvnw install -B  \
               -Dskip.build.image=true \
               -DskipTests -DskipITs \
-              -T -U 1C -q
+              -U -T 1C -q
 
     - name: find all classpath entries
       shell: bash

From ea4e8376f66823b6a83eea2f0773fdfb79e2baf9 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Fri, 22 Sep 2023 13:46:54 +0300
Subject: [PATCH 077/151] test

---
 .../workflows/composites/build-controllers-project/action.yaml  | 2 +-
 .../composites/maven-build-with-dry-run-for-tests/action.yaml   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/.github/workflows/composites/build-controllers-project/action.yaml b/.github/workflows/composites/build-controllers-project/action.yaml
index 307451c8f5..0b11f0a445 100644
--- a/.github/workflows/composites/build-controllers-project/action.yaml
+++ b/.github/workflows/composites/build-controllers-project/action.yaml
@@ -7,5 +7,5 @@ runs:
       shell: bash
       run: |
         cd spring-cloud-kubernetes-controllers
-        .././mvnw -T 1C -U clean install
+        .././mvnw -T 1C clean install
         cd ..
diff --git a/.github/workflows/composites/maven-build-with-dry-run-for-tests/action.yaml b/.github/workflows/composites/maven-build-with-dry-run-for-tests/action.yaml
index a6d5c279ff..5c1709308b 100644
--- a/.github/workflows/composites/maven-build-with-dry-run-for-tests/action.yaml
+++ b/.github/workflows/composites/maven-build-with-dry-run-for-tests/action.yaml
@@ -4,7 +4,7 @@ runs:
   using: "composite"
   steps:
 
-    - name: run 'package' on the project
+    - name: run 'install' on the project
       shell: bash
       run: |
         ./mvnw install -B  \

From b7388969f8c4bccc6d9e8104f2389935523f92f2 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Fri, 22 Sep 2023 14:56:22 +0300
Subject: [PATCH 078/151] test

---
 .../composites/pre-test-actions/action.yaml      | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/.github/workflows/composites/pre-test-actions/action.yaml b/.github/workflows/composites/pre-test-actions/action.yaml
index d2bb6b96b9..c606683971 100644
--- a/.github/workflows/composites/pre-test-actions/action.yaml
+++ b/.github/workflows/composites/pre-test-actions/action.yaml
@@ -25,14 +25,14 @@ runs:
     - name: build controllers project
       uses: ./.github/workflows/composites/build-controllers-project
 
-    - name: build integration tests project
-      uses: ./.github/workflows/composites/build-integration-tests-project
-
-    - name: download tests
-      uses: actions/download-artifact@v3
-      with:
-        name: tests.txt
-        path: /tmp
+#    - name: build integration tests project
+#      uses: ./.github/workflows/composites/build-integration-tests-project
+#
+#    - name: download tests
+#      uses: actions/download-artifact@v3
+#      with:
+#        name: tests.txt
+#        path: /tmp
 
 
 

From 493f2298fb611356bd8c44831fdbefcab9ea75b0 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Fri, 22 Sep 2023 15:28:04 +0300
Subject: [PATCH 079/151] test

---
 .../build-integration-tests-project/action.yaml  |  2 +-
 .../composites/pre-test-actions/action.yaml      | 16 ++++++++--------
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/.github/workflows/composites/build-integration-tests-project/action.yaml b/.github/workflows/composites/build-integration-tests-project/action.yaml
index 23fbb33aa8..f0a7593304 100644
--- a/.github/workflows/composites/build-integration-tests-project/action.yaml
+++ b/.github/workflows/composites/build-integration-tests-project/action.yaml
@@ -13,5 +13,5 @@ runs:
         
         cd spring-cloud-kubernetes-integration-tests
         # build the images, but dont run the tests
-        .././mvnw -T 1C clean install -DskipTests
+        .././mvnw -T 1C clean install -o -DskipTests
         cd ..
diff --git a/.github/workflows/composites/pre-test-actions/action.yaml b/.github/workflows/composites/pre-test-actions/action.yaml
index c606683971..d2bb6b96b9 100644
--- a/.github/workflows/composites/pre-test-actions/action.yaml
+++ b/.github/workflows/composites/pre-test-actions/action.yaml
@@ -25,14 +25,14 @@ runs:
     - name: build controllers project
       uses: ./.github/workflows/composites/build-controllers-project
 
-#    - name: build integration tests project
-#      uses: ./.github/workflows/composites/build-integration-tests-project
-#
-#    - name: download tests
-#      uses: actions/download-artifact@v3
-#      with:
-#        name: tests.txt
-#        path: /tmp
+    - name: build integration tests project
+      uses: ./.github/workflows/composites/build-integration-tests-project
+
+    - name: download tests
+      uses: actions/download-artifact@v3
+      with:
+        name: tests.txt
+        path: /tmp
 
 
 

From dc5af9bd44a51cad6c5923e279b7d839d2cac0ab Mon Sep 17 00:00:00 2001
From: wind57 
Date: Fri, 22 Sep 2023 16:13:01 +0300
Subject: [PATCH 080/151] test

---
 .../composites/build-integration-tests-project/action.yaml      | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/workflows/composites/build-integration-tests-project/action.yaml b/.github/workflows/composites/build-integration-tests-project/action.yaml
index f0a7593304..23fbb33aa8 100644
--- a/.github/workflows/composites/build-integration-tests-project/action.yaml
+++ b/.github/workflows/composites/build-integration-tests-project/action.yaml
@@ -13,5 +13,5 @@ runs:
         
         cd spring-cloud-kubernetes-integration-tests
         # build the images, but dont run the tests
-        .././mvnw -T 1C clean install -o -DskipTests
+        .././mvnw -T 1C clean install -DskipTests
         cd ..

From 9bae1fe58703fbc0cee93aadb4359469b3fdc8a8 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Fri, 22 Sep 2023 18:37:38 +0300
Subject: [PATCH 081/151] test

---
 .../composites/build-integration-tests-project/action.yaml      | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/workflows/composites/build-integration-tests-project/action.yaml b/.github/workflows/composites/build-integration-tests-project/action.yaml
index 23fbb33aa8..f83e11b202 100644
--- a/.github/workflows/composites/build-integration-tests-project/action.yaml
+++ b/.github/workflows/composites/build-integration-tests-project/action.yaml
@@ -13,5 +13,5 @@ runs:
         
         cd spring-cloud-kubernetes-integration-tests
         # build the images, but dont run the tests
-        .././mvnw -T 1C clean install -DskipTests
+        .././mvnw -T 1C clean install -nsu -DskipTests
         cd ..

From 1f74eac42df95570455d294a741952108ea8a14d Mon Sep 17 00:00:00 2001
From: wind57 
Date: Fri, 22 Sep 2023 22:07:37 +0300
Subject: [PATCH 082/151] test

---
 .github/workflows/composites/cache/action.yaml                | 4 ++++
 ...8KubernetesDiscoveryClientServiceWithoutPortNameTests.java | 3 +--
 .../discovery/bootstrap/Fabric8DiscoveryBootstrapIT.java      | 1 -
 3 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/.github/workflows/composites/cache/action.yaml b/.github/workflows/composites/cache/action.yaml
index 792bb396c8..a6ab8ae916 100644
--- a/.github/workflows/composites/cache/action.yaml
+++ b/.github/workflows/composites/cache/action.yaml
@@ -12,4 +12,8 @@ runs:
           path: ~/.m2/repository
           key: ${{ runner.os }}-cache-${{ env.BRANCH_NAME }}-${{ hashFiles('**/pom.xml') }}
           restore-keys: ${{ runner.os }}-cache-${{ env.BRANCH_NAME }}-${{ hashFiles('**/pom.xml') }}
+
+    - name: show path
+      shell: bash
+      run: ls ~/.m2/repository/org/springframework/cloud/spring-cloud-kubernetes-fabric8-discovery/3.1.0-SNAPSHOT
         
diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientServiceWithoutPortNameTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientServiceWithoutPortNameTests.java
index a1b33916ff..2971d5db0a 100644
--- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientServiceWithoutPortNameTests.java
+++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientServiceWithoutPortNameTests.java
@@ -70,8 +70,7 @@ void testDiscoveryWithoutAServicePortName() {
 				true, 60, false, null, Set.of(), Map.of(), null, KubernetesDiscoveryProperties.Metadata.DEFAULT, 0,
 				true);
 		Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, properties,
-			new ServicePortSecureResolver(properties), new KubernetesNamespaceProvider(null),
-			a -> true);
+				new ServicePortSecureResolver(properties), new KubernetesNamespaceProvider(null), a -> true);
 
 		List serviceInstances = discoveryClient.getInstances("no-port-name-service");
 		Assertions.assertEquals(serviceInstances.size(), 1);
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery-with-bootstrap/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/bootstrap/Fabric8DiscoveryBootstrapIT.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery-with-bootstrap/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/bootstrap/Fabric8DiscoveryBootstrapIT.java
index a95740259d..0816c05a43 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery-with-bootstrap/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/bootstrap/Fabric8DiscoveryBootstrapIT.java
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery-with-bootstrap/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/bootstrap/Fabric8DiscoveryBootstrapIT.java
@@ -110,7 +110,6 @@ private static void manifests(Phase phase) throws Exception {
 			InputStream serviceStream = util.inputStream("fabric8-discovery-service.yaml");
 			InputStream ingressStream = util.inputStream("fabric8-discovery-ingress.yaml");
 
-
 			Deployment deployment = Serialization.unmarshal(deploymentStream, Deployment.class);
 
 			List existing = new ArrayList<>(

From 38943323f40291ad1fe99a1b0599467ae0c9af9c Mon Sep 17 00:00:00 2001
From: wind57 
Date: Fri, 22 Sep 2023 22:08:49 +0300
Subject: [PATCH 083/151] test

---
 .../composites/build-integration-tests-project/action.yaml      | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/workflows/composites/build-integration-tests-project/action.yaml b/.github/workflows/composites/build-integration-tests-project/action.yaml
index f83e11b202..23fbb33aa8 100644
--- a/.github/workflows/composites/build-integration-tests-project/action.yaml
+++ b/.github/workflows/composites/build-integration-tests-project/action.yaml
@@ -13,5 +13,5 @@ runs:
         
         cd spring-cloud-kubernetes-integration-tests
         # build the images, but dont run the tests
-        .././mvnw -T 1C clean install -nsu -DskipTests
+        .././mvnw -T 1C clean install -DskipTests
         cd ..

From 0a8ba6585e0d27acc7425bcd189d238bc88979f3 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Fri, 22 Sep 2023 22:17:45 +0300
Subject: [PATCH 084/151] trigger


From 53a6f4b97e2a63e1537998955d5ac333d7c99c79 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Fri, 22 Sep 2023 22:40:19 +0300
Subject: [PATCH 085/151] test

---
 .../composites/build-integration-tests-project/action.yaml      | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/workflows/composites/build-integration-tests-project/action.yaml b/.github/workflows/composites/build-integration-tests-project/action.yaml
index 23fbb33aa8..c68c96ba6b 100644
--- a/.github/workflows/composites/build-integration-tests-project/action.yaml
+++ b/.github/workflows/composites/build-integration-tests-project/action.yaml
@@ -8,7 +8,7 @@ runs:
       run: |
         
         cd spring-cloud-kubernetes-test-support
-        .././mvnw clean install -U
+        .././mvnw clean install
         cd ..
         
         cd spring-cloud-kubernetes-integration-tests

From 10cc66909ca250fd6266b50f1c51060c36c7013c Mon Sep 17 00:00:00 2001
From: wind57 
Date: Sat, 23 Sep 2023 10:12:08 +0300
Subject: [PATCH 086/151] test

---
 .../composites/build-integration-tests-project/action.yaml | 7 ++++++-
 .github/workflows/composites/cache/action.yaml             | 4 ----
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/.github/workflows/composites/build-integration-tests-project/action.yaml b/.github/workflows/composites/build-integration-tests-project/action.yaml
index c68c96ba6b..bf5d61087b 100644
--- a/.github/workflows/composites/build-integration-tests-project/action.yaml
+++ b/.github/workflows/composites/build-integration-tests-project/action.yaml
@@ -3,12 +3,17 @@ description: build integration tests project without tests
 runs:
   using: "composite"
   steps:
+
+    - name: show path
+      shell: bash
+      run: ls ~/.m2/repository/org/springframework/cloud/spring-cloud-kubernetes-fabric8-discovery/3.1.0-SNAPSHOT
+
     - name: build integration tests project without tests
       shell: bash
       run: |
         
         cd spring-cloud-kubernetes-test-support
-        .././mvnw clean install
+        .././mvnw clean install -U
         cd ..
         
         cd spring-cloud-kubernetes-integration-tests
diff --git a/.github/workflows/composites/cache/action.yaml b/.github/workflows/composites/cache/action.yaml
index a6ab8ae916..792bb396c8 100644
--- a/.github/workflows/composites/cache/action.yaml
+++ b/.github/workflows/composites/cache/action.yaml
@@ -12,8 +12,4 @@ runs:
           path: ~/.m2/repository
           key: ${{ runner.os }}-cache-${{ env.BRANCH_NAME }}-${{ hashFiles('**/pom.xml') }}
           restore-keys: ${{ runner.os }}-cache-${{ env.BRANCH_NAME }}-${{ hashFiles('**/pom.xml') }}
-
-    - name: show path
-      shell: bash
-      run: ls ~/.m2/repository/org/springframework/cloud/spring-cloud-kubernetes-fabric8-discovery/3.1.0-SNAPSHOT
         

From a509f4f191793b17e5c757a3864f9d22bc27c2b7 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Sat, 23 Sep 2023 11:17:52 +0300
Subject: [PATCH 087/151] clean-up

---
 .../composites/build-integration-tests-project/action.yaml    | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/.github/workflows/composites/build-integration-tests-project/action.yaml b/.github/workflows/composites/build-integration-tests-project/action.yaml
index bf5d61087b..a42969ede4 100644
--- a/.github/workflows/composites/build-integration-tests-project/action.yaml
+++ b/.github/workflows/composites/build-integration-tests-project/action.yaml
@@ -4,10 +4,6 @@ runs:
   using: "composite"
   steps:
 
-    - name: show path
-      shell: bash
-      run: ls ~/.m2/repository/org/springframework/cloud/spring-cloud-kubernetes-fabric8-discovery/3.1.0-SNAPSHOT
-
     - name: build integration tests project without tests
       shell: bash
       run: |

From 0b365fd32e4db2e39e90233315881e35cddfd9f1 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Sun, 24 Sep 2023 09:30:43 +0300
Subject: [PATCH 088/151] test

---
 .../composites/build-integration-tests-project/action.yaml    | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/.github/workflows/composites/build-integration-tests-project/action.yaml b/.github/workflows/composites/build-integration-tests-project/action.yaml
index a42969ede4..87f8533745 100644
--- a/.github/workflows/composites/build-integration-tests-project/action.yaml
+++ b/.github/workflows/composites/build-integration-tests-project/action.yaml
@@ -12,6 +12,10 @@ runs:
         .././mvnw clean install -U
         cd ..
         
+        echo "==================================="
+        ls ~/.m2/repository/org/springframework/cloud/spring-cloud-kubernetes-fabric8-discovery/3.1.0-SNAPSHOT
+        echo "==================================="
+        
         cd spring-cloud-kubernetes-integration-tests
         # build the images, but dont run the tests
         .././mvnw -T 1C clean install -DskipTests

From 9876bef14fcea004346be05b388274bfacccef87 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Sun, 24 Sep 2023 12:50:36 +0300
Subject: [PATCH 089/151] test

---
 .../composites/build-integration-tests-project/action.yaml       | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.github/workflows/composites/build-integration-tests-project/action.yaml b/.github/workflows/composites/build-integration-tests-project/action.yaml
index 87f8533745..9f95e3cb8c 100644
--- a/.github/workflows/composites/build-integration-tests-project/action.yaml
+++ b/.github/workflows/composites/build-integration-tests-project/action.yaml
@@ -15,6 +15,7 @@ runs:
         echo "==================================="
         ls ~/.m2/repository/org/springframework/cloud/spring-cloud-kubernetes-fabric8-discovery/3.1.0-SNAPSHOT
         echo "==================================="
+        less ~/.m2/settings.xml
         
         cd spring-cloud-kubernetes-integration-tests
         # build the images, but dont run the tests

From 2c9c3ea7c31b01123c6a7b21a3e9086a70d24792 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Sun, 24 Sep 2023 16:03:39 +0300
Subject: [PATCH 090/151] test

---
 .../composites/build-integration-tests-project/action.yaml    | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/.github/workflows/composites/build-integration-tests-project/action.yaml b/.github/workflows/composites/build-integration-tests-project/action.yaml
index 9f95e3cb8c..059551bfe2 100644
--- a/.github/workflows/composites/build-integration-tests-project/action.yaml
+++ b/.github/workflows/composites/build-integration-tests-project/action.yaml
@@ -15,7 +15,9 @@ runs:
         echo "==================================="
         ls ~/.m2/repository/org/springframework/cloud/spring-cloud-kubernetes-fabric8-discovery/3.1.0-SNAPSHOT
         echo "==================================="
-        less ~/.m2/settings.xml
+        less ~/.m2/repository/org/springframework/cloud/spring-cloud-kubernetes-fabric8-discovery/3.1.0-SNAPSHOT/_remote.repositories
+        echo "==================================="
+        less  ~/.m2/repository/org/springframework/cloud/spring-cloud-kubernetes-fabric8-discovery/3.1.0-SNAPSHOT/maven-metadata-local.xml
         
         cd spring-cloud-kubernetes-integration-tests
         # build the images, but dont run the tests

From d587b4b8fa179a810f57a07e781d306874f13385 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Sun, 24 Sep 2023 16:42:35 +0300
Subject: [PATCH 091/151] test

---
 .../composites/build-integration-tests-project/action.yaml | 7 -------
 .github/workflows/composites/pre-test-actions/action.yaml  | 5 +++++
 2 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/.github/workflows/composites/build-integration-tests-project/action.yaml b/.github/workflows/composites/build-integration-tests-project/action.yaml
index 059551bfe2..a42969ede4 100644
--- a/.github/workflows/composites/build-integration-tests-project/action.yaml
+++ b/.github/workflows/composites/build-integration-tests-project/action.yaml
@@ -12,13 +12,6 @@ runs:
         .././mvnw clean install -U
         cd ..
         
-        echo "==================================="
-        ls ~/.m2/repository/org/springframework/cloud/spring-cloud-kubernetes-fabric8-discovery/3.1.0-SNAPSHOT
-        echo "==================================="
-        less ~/.m2/repository/org/springframework/cloud/spring-cloud-kubernetes-fabric8-discovery/3.1.0-SNAPSHOT/_remote.repositories
-        echo "==================================="
-        less  ~/.m2/repository/org/springframework/cloud/spring-cloud-kubernetes-fabric8-discovery/3.1.0-SNAPSHOT/maven-metadata-local.xml
-        
         cd spring-cloud-kubernetes-integration-tests
         # build the images, but dont run the tests
         .././mvnw -T 1C clean install -DskipTests
diff --git a/.github/workflows/composites/pre-test-actions/action.yaml b/.github/workflows/composites/pre-test-actions/action.yaml
index d2bb6b96b9..12ea4b2b6c 100644
--- a/.github/workflows/composites/pre-test-actions/action.yaml
+++ b/.github/workflows/composites/pre-test-actions/action.yaml
@@ -22,6 +22,11 @@ runs:
     - name: cache local maven repository
       uses: ./.github/workflows/composites/cache
 
+    - name: build project
+      shell: bash
+      run: | 
+        ./mvnw install -B -Dskip.build.image=true -DskipTests -DskipITs -U -T 1C -q
+
     - name: build controllers project
       uses: ./.github/workflows/composites/build-controllers-project
 

From bc612fbe819eea5404fa99c2d1adc2cdee7c65ca Mon Sep 17 00:00:00 2001
From: wind57 
Date: Sun, 24 Sep 2023 16:59:27 +0300
Subject: [PATCH 092/151] test

---
 .github/workflows/composites/pre-test-actions/action.yaml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/workflows/composites/pre-test-actions/action.yaml b/.github/workflows/composites/pre-test-actions/action.yaml
index 12ea4b2b6c..5cbf42e555 100644
--- a/.github/workflows/composites/pre-test-actions/action.yaml
+++ b/.github/workflows/composites/pre-test-actions/action.yaml
@@ -25,7 +25,7 @@ runs:
     - name: build project
       shell: bash
       run: | 
-        ./mvnw install -B -Dskip.build.image=true -DskipTests -DskipITs -U -T 1C -q
+        ./mvnw clean install -Dskip.build.image=true -DskipITs -DskipTests -T1C -U -B -q
 
     - name: build controllers project
       uses: ./.github/workflows/composites/build-controllers-project

From ab5796b27308868fa326de5b052219a12e6db2d1 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Tue, 26 Sep 2023 09:00:55 +0300
Subject: [PATCH 093/151] test

---
 .../action.yaml                               |  2 +-
 .../action.yaml                               |  2 +-
 .../save-controller-images/action.yaml        | 15 --------------
 .../save-integration-tests-images/action.yaml | 20 -------------------
 4 files changed, 2 insertions(+), 37 deletions(-)
 delete mode 100644 .github/workflows/composites/save-controller-images/action.yaml
 delete mode 100644 .github/workflows/composites/save-integration-tests-images/action.yaml

diff --git a/.github/workflows/composites/run-and-save-test-times-when-cache-missing/action.yaml b/.github/workflows/composites/run-and-save-test-times-when-cache-missing/action.yaml
index 39e79ebdd7..0cb4085b21 100644
--- a/.github/workflows/composites/run-and-save-test-times-when-cache-missing/action.yaml
+++ b/.github/workflows/composites/run-and-save-test-times-when-cache-missing/action.yaml
@@ -61,7 +61,7 @@ runs:
            ./mvnw -s .settings.xml \
            -DtestsToRun=${TEST_ARG[@]} \
            -e clean install \
-           -U -P sonar -nsu --batch-mode \
+           -P sonar -nsu --batch-mode \
            -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn \
            -Dhttp.keepAlive=false \
            -Dmaven.wagon.http.pool=false \
diff --git a/.github/workflows/composites/run-and-save-test-times-when-cache-present/action.yaml b/.github/workflows/composites/run-and-save-test-times-when-cache-present/action.yaml
index ce8c81cff3..f658cfbf58 100644
--- a/.github/workflows/composites/run-and-save-test-times-when-cache-present/action.yaml
+++ b/.github/workflows/composites/run-and-save-test-times-when-cache-present/action.yaml
@@ -150,7 +150,7 @@ runs:
         ./mvnw -s .settings.xml \
               -DtestsToRun=${tests_to_run_in_current_index} \
               -e clean install \
-              -U -P sonar -nsu --batch-mode \
+              -P sonar -nsu --batch-mode \
               -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn \
               -Dhttp.keepAlive=false \
               -Dmaven.wagon.http.pool=false \
diff --git a/.github/workflows/composites/save-controller-images/action.yaml b/.github/workflows/composites/save-controller-images/action.yaml
deleted file mode 100644
index 056b1b2adb..0000000000
--- a/.github/workflows/composites/save-controller-images/action.yaml
+++ /dev/null
@@ -1,15 +0,0 @@
-name: save controller docker images
-description: save controller docker images
-runs:
-  using: "composite"
-  steps:
-    - name: save controller docker images
-      shell: bash
-      run: |
-        mkdir -p /tmp/docker/images
-        TAG=$(./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout)
-        cd spring-cloud-kubernetes-controllers
-        while read controller_image; do
-          docker save -o /tmp/docker/images/${controller_image}.tar docker.io/springcloud/${controller_image}:$TAG
-        done < <(mvn -Dexec.executable='echo' -Dexec.args='${project.artifactId}' exec:exec -q | grep -v 'spring-cloud-kubernetes-controllers')
-        cd ..
diff --git a/.github/workflows/composites/save-integration-tests-images/action.yaml b/.github/workflows/composites/save-integration-tests-images/action.yaml
deleted file mode 100644
index cbc92e55f7..0000000000
--- a/.github/workflows/composites/save-integration-tests-images/action.yaml
+++ /dev/null
@@ -1,20 +0,0 @@
-name: save integration tests docker images
-description: save integration tests docker images
-runs:
-  using: "composite"
-  steps:
-    - name: save integration tests docker images
-      shell: bash
-      run: |
-        mkdir -p /tmp/docker/images
-        TAG=$(./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout)
-        cd spring-cloud-kubernetes-integration-tests
-        while read integ_test; do
-          docker save -o /tmp/docker/images/${integ_test}.tar docker.io/springcloud/${integ_test}:$TAG
-        done < <(mvn -Dexec.executable='echo' -Dexec.args='${project.artifactId}' exec:exec -q \
-                        | grep -v 'spring-cloud-kubernetes-integration-tests' \
-                        | grep -v 'spring-cloud-kubernetes-client-configmap-event-reload-multiple-apps' \
-                        | grep -v 'spring-cloud-kubernetes-client-configuration-watcher-configmap-test-app' \
-                        | grep -v 'spring-cloud-kubernetes-client-secrets-event-reload-multiple-apps' \
-                        | grep -v 'spring-cloud-kubernetes-client-configuration-watcher-secrets-test-app' )
-        cd ..

From 80c100c1ea084e761bbba334e06470faec3538e6 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Tue, 26 Sep 2023 09:27:38 +0300
Subject: [PATCH 094/151] placeholder commit


From 4763bdc5bcb5541082c582fd1237d4696241d0ba Mon Sep 17 00:00:00 2001
From: wind57 
Date: Tue, 26 Sep 2023 10:53:24 +0300
Subject: [PATCH 095/151] test

---
 .../spring-cloud-kubernetes-client-catalog-watcher/pom.xml       | 1 +
 .../pom.xml                                                      | 1 +
 .../spring-cloud-kubernetes-client-discovery-it/pom.xml          | 1 +
 .../pom.xml                                                      | 1 +
 .../spring-cloud-kubernetes-client-loadbalancer-it/pom.xml       | 1 +
 .../pom.xml                                                      | 1 +
 .../spring-cloud-kubernetes-configuration-watcher-it/pom.xml     | 1 +
 .../spring-cloud-kubernetes-discoveryclient-it/pom.xml           | 1 +
 .../pom.xml                                                      | 1 +
 .../pom.xml                                                      | 1 +
 .../pom.xml                                                      | 1 +
 .../spring-cloud-kubernetes-fabric8-client-configmap/pom.xml     | 1 +
 .../pom.xml                                                      | 1 +
 .../spring-cloud-kubernetes-fabric8-client-discovery/pom.xml     | 1 +
 .../spring-cloud-kubernetes-fabric8-client-loadbalancer/pom.xml  | 1 +
 .../pom.xml                                                      | 1 +
 .../spring-cloud-kubernetes-fabric8-istio-it/pom.xml             | 1 +
 17 files changed, 17 insertions(+)

diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-catalog-watcher/pom.xml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-catalog-watcher/pom.xml
index 38f4e18e73..2b5afdca5d 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-catalog-watcher/pom.xml
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-catalog-watcher/pom.xml
@@ -86,6 +86,7 @@
 			
 				org.apache.maven.plugins
 				maven-failsafe-plugin
+				3.1.2
 				
 					
 						
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-configmap-event-reload-multiple-apps/spring-cloud-kubernetes-client-configuration-watcher-configmap-test-app/pom.xml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-configmap-event-reload-multiple-apps/spring-cloud-kubernetes-client-configuration-watcher-configmap-test-app/pom.xml
index 382886e789..530756302e 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-configmap-event-reload-multiple-apps/spring-cloud-kubernetes-client-configuration-watcher-configmap-test-app/pom.xml
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-configmap-event-reload-multiple-apps/spring-cloud-kubernetes-client-configuration-watcher-configmap-test-app/pom.xml
@@ -55,6 +55,7 @@
 			
 				org.apache.maven.plugins
 				maven-failsafe-plugin
+				3.1.2
 				
 					
 						
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-discovery-it/pom.xml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-discovery-it/pom.xml
index ec84212c8a..243f1a4d32 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-discovery-it/pom.xml
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-discovery-it/pom.xml
@@ -96,6 +96,7 @@
 			
 				org.apache.maven.plugins
 				maven-failsafe-plugin
+				3.1.2
 				
 					
 						
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-event-and-polling-reload/pom.xml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-event-and-polling-reload/pom.xml
index dfc5d03931..10a1503128 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-event-and-polling-reload/pom.xml
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-event-and-polling-reload/pom.xml
@@ -95,6 +95,7 @@
 			
 				org.apache.maven.plugins
 				maven-failsafe-plugin
+				3.1.2
 				
 					
 						
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-loadbalancer-it/pom.xml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-loadbalancer-it/pom.xml
index 61e6ba120f..1aea888da1 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-loadbalancer-it/pom.xml
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-loadbalancer-it/pom.xml
@@ -91,6 +91,7 @@
 			
 				org.apache.maven.plugins
 				maven-failsafe-plugin
+				3.1.2
 				
 					
 						
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-secrets-event-reload-multiple-apps/spring-cloud-kubernetes-client-configuration-watcher-secrets-test-app/pom.xml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-secrets-event-reload-multiple-apps/spring-cloud-kubernetes-client-configuration-watcher-secrets-test-app/pom.xml
index ba73ef90b8..38b3156899 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-secrets-event-reload-multiple-apps/spring-cloud-kubernetes-client-configuration-watcher-secrets-test-app/pom.xml
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-secrets-event-reload-multiple-apps/spring-cloud-kubernetes-client-configuration-watcher-secrets-test-app/pom.xml
@@ -55,6 +55,7 @@
 			
 				org.apache.maven.plugins
 				maven-failsafe-plugin
+				3.1.2
 				
 					
 						
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-configuration-watcher-it/pom.xml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-configuration-watcher-it/pom.xml
index 69d3aac1de..4179f2975c 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-configuration-watcher-it/pom.xml
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-configuration-watcher-it/pom.xml
@@ -111,6 +111,7 @@
 			
 				org.apache.maven.plugins
 				maven-failsafe-plugin
+				3.1.2
 				
 					
 						
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-discoveryclient-it/pom.xml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-discoveryclient-it/pom.xml
index 74e485be7f..512716a58c 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-discoveryclient-it/pom.xml
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-discoveryclient-it/pom.xml
@@ -92,6 +92,7 @@
 			
 				org.apache.maven.plugins
 				maven-failsafe-plugin
+				3.1.2
 				
 					
 						
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/pom.xml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/pom.xml
index e30c96300f..0f93f700fb 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/pom.xml
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/pom.xml
@@ -86,6 +86,7 @@
 			
 				org.apache.maven.plugins
 				maven-failsafe-plugin
+				3.1.2
 				
 					
 						
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-configmap-event-reload/pom.xml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-configmap-event-reload/pom.xml
index a1ba8bb15b..bc22366d8b 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-configmap-event-reload/pom.xml
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-configmap-event-reload/pom.xml
@@ -93,6 +93,7 @@
 			
 				org.apache.maven.plugins
 				maven-failsafe-plugin
+				3.1.2
 				
 					
 						
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-configmap-polling-reload/pom.xml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-configmap-polling-reload/pom.xml
index c5b250af03..5add6f8edd 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-configmap-polling-reload/pom.xml
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-configmap-polling-reload/pom.xml
@@ -96,6 +96,7 @@
 			
 				org.apache.maven.plugins
 				maven-failsafe-plugin
+				3.1.2
 				
 					
 						
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-configmap/pom.xml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-configmap/pom.xml
index f95d31e806..5d411470b7 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-configmap/pom.xml
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-configmap/pom.xml
@@ -86,6 +86,7 @@
 			
 				org.apache.maven.plugins
 				maven-failsafe-plugin
+				3.1.2
 				
 					
 						
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery-with-bootstrap/pom.xml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery-with-bootstrap/pom.xml
index 0f5a4a4934..d0eb7669fd 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery-with-bootstrap/pom.xml
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery-with-bootstrap/pom.xml
@@ -90,6 +90,7 @@
 			
 				org.apache.maven.plugins
 				maven-failsafe-plugin
+				3.1.2
 				
 					
 						
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/pom.xml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/pom.xml
index dfe6a31ec6..bb1d63c5dc 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/pom.xml
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/pom.xml
@@ -86,6 +86,7 @@
 			
 				org.apache.maven.plugins
 				maven-failsafe-plugin
+				3.1.2
 				
 					
 						
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-loadbalancer/pom.xml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-loadbalancer/pom.xml
index 9362129cb0..1df946c6c0 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-loadbalancer/pom.xml
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-loadbalancer/pom.xml
@@ -86,6 +86,7 @@
 			
 				org.apache.maven.plugins
 				maven-failsafe-plugin
+				3.1.2
 				
 					
 						
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-secrets-event-reload/pom.xml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-secrets-event-reload/pom.xml
index 0778446710..1c071aa98f 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-secrets-event-reload/pom.xml
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-secrets-event-reload/pom.xml
@@ -88,6 +88,7 @@
 			
 				org.apache.maven.plugins
 				maven-failsafe-plugin
+				3.1.2
 				
 					
 						
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-istio-it/pom.xml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-istio-it/pom.xml
index c1d9fb67a5..3c047314dd 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-istio-it/pom.xml
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-istio-it/pom.xml
@@ -86,6 +86,7 @@
 			
 				org.apache.maven.plugins
 				maven-failsafe-plugin
+				3.1.2
 				
 					
 						

From 970c875e3e4ceaf444e687a6be7be56bf548b183 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Tue, 26 Sep 2023 11:42:21 +0300
Subject: [PATCH 096/151] test

---
 .github/workflows/composites/clean-space/action.yaml | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/.github/workflows/composites/clean-space/action.yaml b/.github/workflows/composites/clean-space/action.yaml
index 69d61642fd..e110dc0c7e 100644
--- a/.github/workflows/composites/clean-space/action.yaml
+++ b/.github/workflows/composites/clean-space/action.yaml
@@ -7,6 +7,14 @@ runs:
       shell: bash
       run: |
         sudo apt-get update
+        
+        
+    # temporary workaround for an error in free disk space action
+    # https://github.com/jlumbroso/free-disk-space/issues/14
+    - name: Update Package List and Remove Dotnet
+      shell: bash
+      run: |
+        sudo apt-get update
 
     - name: Free Disk Space
       uses: jlumbroso/free-disk-space@main

From edcc9964527cf151de7c0f16346c679f8c4f33f4 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Tue, 26 Sep 2023 12:20:39 +0300
Subject: [PATCH 097/151] test

---
 .github/workflows/composites/clean-space/action.yaml |  8 --------
 .github/workflows/maven.yaml                         | 10 +++++-----
 2 files changed, 5 insertions(+), 13 deletions(-)

diff --git a/.github/workflows/composites/clean-space/action.yaml b/.github/workflows/composites/clean-space/action.yaml
index e110dc0c7e..69d61642fd 100644
--- a/.github/workflows/composites/clean-space/action.yaml
+++ b/.github/workflows/composites/clean-space/action.yaml
@@ -7,14 +7,6 @@ runs:
       shell: bash
       run: |
         sudo apt-get update
-        
-        
-    # temporary workaround for an error in free disk space action
-    # https://github.com/jlumbroso/free-disk-space/issues/14
-    - name: Update Package List and Remove Dotnet
-      shell: bash
-      run: |
-        sudo apt-get update
 
     - name: Free Disk Space
       uses: jlumbroso/free-disk-space@main
diff --git a/.github/workflows/maven.yaml b/.github/workflows/maven.yaml
index 6264d4c008..eb0740edf4 100644
--- a/.github/workflows/maven.yaml
+++ b/.github/workflows/maven.yaml
@@ -8,7 +8,7 @@ on:
 
 jobs:
   build:
-    runs-on: ubuntu-latest
+    runs-on: ubuntu-20.04
     env:
       # this might get set to true if there is an existing cache of test times
       # this happens in 'matrix-bounds-on-test-times-cache-hit'
@@ -96,7 +96,7 @@ jobs:
 
   test_when_cache_present:
     needs: [ build ]
-    runs-on: ubuntu-latest
+    runs-on: ubuntu-20.04
     env:
       SEGMENT_DOWNLOAD_TIMEOUT_MINS: 30
     # only run this one if there is a previous cache of test times
@@ -145,7 +145,7 @@ jobs:
 
   test_when_cache_missing:
     needs: [ build ]
-    runs-on: ubuntu-latest
+    runs-on: ubuntu-20.04
     env:
       SEGMENT_DOWNLOAD_TIMEOUT_MINS: 30
     timeout-minutes: 60
@@ -197,7 +197,7 @@ jobs:
         uses: ./.github/workflows/composites/run-and-save-test-times-when-cache-missing
 
   save_test_times_when_cache_missing:
-    runs-on: ubuntu-latest
+    runs-on: ubuntu-20.04
     needs: [build, test_when_cache_missing ]
 
     steps:
@@ -210,7 +210,7 @@ jobs:
         uses: ./.github/workflows/composites/test-times
 
   save_test_times_when_cache_present:
-    runs-on: ubuntu-latest
+    runs-on: ubuntu-20.04
     needs: [ build, test_when_cache_present ]
 
     steps:

From 82d5f2ff89af9e96324715d3e9a151fc6e3639d9 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Tue, 26 Sep 2023 12:52:54 +0300
Subject: [PATCH 098/151] test

---
 .github/workflows/composites/clean-space/action.yaml |  1 +
 .github/workflows/maven.yaml                         | 10 +++++-----
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/.github/workflows/composites/clean-space/action.yaml b/.github/workflows/composites/clean-space/action.yaml
index 69d61642fd..e65d11f0c0 100644
--- a/.github/workflows/composites/clean-space/action.yaml
+++ b/.github/workflows/composites/clean-space/action.yaml
@@ -7,6 +7,7 @@ runs:
       shell: bash
       run: |
         sudo apt-get update
+        sudo apt-get remove google-cloud-sdk*
 
     - name: Free Disk Space
       uses: jlumbroso/free-disk-space@main
diff --git a/.github/workflows/maven.yaml b/.github/workflows/maven.yaml
index eb0740edf4..6264d4c008 100644
--- a/.github/workflows/maven.yaml
+++ b/.github/workflows/maven.yaml
@@ -8,7 +8,7 @@ on:
 
 jobs:
   build:
-    runs-on: ubuntu-20.04
+    runs-on: ubuntu-latest
     env:
       # this might get set to true if there is an existing cache of test times
       # this happens in 'matrix-bounds-on-test-times-cache-hit'
@@ -96,7 +96,7 @@ jobs:
 
   test_when_cache_present:
     needs: [ build ]
-    runs-on: ubuntu-20.04
+    runs-on: ubuntu-latest
     env:
       SEGMENT_DOWNLOAD_TIMEOUT_MINS: 30
     # only run this one if there is a previous cache of test times
@@ -145,7 +145,7 @@ jobs:
 
   test_when_cache_missing:
     needs: [ build ]
-    runs-on: ubuntu-20.04
+    runs-on: ubuntu-latest
     env:
       SEGMENT_DOWNLOAD_TIMEOUT_MINS: 30
     timeout-minutes: 60
@@ -197,7 +197,7 @@ jobs:
         uses: ./.github/workflows/composites/run-and-save-test-times-when-cache-missing
 
   save_test_times_when_cache_missing:
-    runs-on: ubuntu-20.04
+    runs-on: ubuntu-latest
     needs: [build, test_when_cache_missing ]
 
     steps:
@@ -210,7 +210,7 @@ jobs:
         uses: ./.github/workflows/composites/test-times
 
   save_test_times_when_cache_present:
-    runs-on: ubuntu-20.04
+    runs-on: ubuntu-latest
     needs: [ build, test_when_cache_present ]
 
     steps:

From 2b56337faa481f1e02bb2514095caa36a2fb5e96 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Tue, 26 Sep 2023 12:54:50 +0300
Subject: [PATCH 099/151] test

---
 .github/workflows/composites/clean-space/action.yaml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/workflows/composites/clean-space/action.yaml b/.github/workflows/composites/clean-space/action.yaml
index e65d11f0c0..a61f9558e1 100644
--- a/.github/workflows/composites/clean-space/action.yaml
+++ b/.github/workflows/composites/clean-space/action.yaml
@@ -7,7 +7,7 @@ runs:
       shell: bash
       run: |
         sudo apt-get update
-        sudo apt-get remove google-cloud-sdk*
+        sudo apt-get purge google-cloud-sdk
 
     - name: Free Disk Space
       uses: jlumbroso/free-disk-space@main

From dcbc5decdccdae860f15a75e89a4322475779359 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Tue, 26 Sep 2023 13:09:07 +0300
Subject: [PATCH 100/151] test

---
 .github/workflows/composites/clean-space/action.yaml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/workflows/composites/clean-space/action.yaml b/.github/workflows/composites/clean-space/action.yaml
index a61f9558e1..4f70007353 100644
--- a/.github/workflows/composites/clean-space/action.yaml
+++ b/.github/workflows/composites/clean-space/action.yaml
@@ -7,7 +7,7 @@ runs:
       shell: bash
       run: |
         sudo apt-get update
-        sudo apt-get purge google-cloud-sdk
+        sudo apt-get remove google-cloud-sdk
 
     - name: Free Disk Space
       uses: jlumbroso/free-disk-space@main

From d48d61ff3c48e6ea6706aa220971881b56942647 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Tue, 26 Sep 2023 13:17:16 +0300
Subject: [PATCH 101/151] test

---
 .github/workflows/composites/clean-space/action.yaml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/workflows/composites/clean-space/action.yaml b/.github/workflows/composites/clean-space/action.yaml
index 4f70007353..b8e8b619a1 100644
--- a/.github/workflows/composites/clean-space/action.yaml
+++ b/.github/workflows/composites/clean-space/action.yaml
@@ -7,7 +7,7 @@ runs:
       shell: bash
       run: |
         sudo apt-get update
-        sudo apt-get remove google-cloud-sdk
+        sudo apt-get remove -y azure-cli google-cloud-sdk google-chrome-stable firefox powershell mono-devel libgl1-mesa-dri
 
     - name: Free Disk Space
       uses: jlumbroso/free-disk-space@main

From db8d950892bf7400c7d55919a11564262d82b0a5 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Tue, 26 Sep 2023 13:20:29 +0300
Subject: [PATCH 102/151] test

---
 .github/workflows/composites/clean-space/action.yaml | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/.github/workflows/composites/clean-space/action.yaml b/.github/workflows/composites/clean-space/action.yaml
index b8e8b619a1..fd1f337aa7 100644
--- a/.github/workflows/composites/clean-space/action.yaml
+++ b/.github/workflows/composites/clean-space/action.yaml
@@ -3,11 +3,11 @@ description: clean space
 runs:
   using: "composite"
   steps:
-    - name: apt-update
-      shell: bash
-      run: |
-        sudo apt-get update
-        sudo apt-get remove -y azure-cli google-cloud-sdk google-chrome-stable firefox powershell mono-devel libgl1-mesa-dri
+#    - name: apt-update
+#      shell: bash
+#      run: |
+#        sudo apt-get update
+#        sudo apt-get remove -y azure-cli google-cloud-sdk google-chrome-stable firefox powershell mono-devel libgl1-mesa-dri
 
     - name: Free Disk Space
       uses: jlumbroso/free-disk-space@main

From ae31faf5be485cb1177be65ce40a83670ec73392 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Tue, 26 Sep 2023 13:55:02 +0300
Subject: [PATCH 103/151] test

---
 .github/workflows/composites/clean-space/action.yaml | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/.github/workflows/composites/clean-space/action.yaml b/.github/workflows/composites/clean-space/action.yaml
index fd1f337aa7..3b2761a64c 100644
--- a/.github/workflows/composites/clean-space/action.yaml
+++ b/.github/workflows/composites/clean-space/action.yaml
@@ -3,11 +3,9 @@ description: clean space
 runs:
   using: "composite"
   steps:
-#    - name: apt-update
-#      shell: bash
-#      run: |
-#        sudo apt-get update
-#        sudo apt-get remove -y azure-cli google-cloud-sdk google-chrome-stable firefox powershell mono-devel libgl1-mesa-dri
+    - name: gcloud
+      shell: bash
+      run: gcloud info
 
     - name: Free Disk Space
       uses: jlumbroso/free-disk-space@main

From dfca45b9ef1a4618df5c7b2ab7bb0a6d8aaacc4a Mon Sep 17 00:00:00 2001
From: wind57 
Date: Tue, 26 Sep 2023 14:08:20 +0300
Subject: [PATCH 104/151] test

---
 .github/workflows/composites/clean-space/action.yaml | 3 ---
 .github/workflows/maven.yaml                         | 3 ---
 2 files changed, 6 deletions(-)

diff --git a/.github/workflows/composites/clean-space/action.yaml b/.github/workflows/composites/clean-space/action.yaml
index 3b2761a64c..f115de3a20 100644
--- a/.github/workflows/composites/clean-space/action.yaml
+++ b/.github/workflows/composites/clean-space/action.yaml
@@ -3,9 +3,6 @@ description: clean space
 runs:
   using: "composite"
   steps:
-    - name: gcloud
-      shell: bash
-      run: gcloud info
 
     - name: Free Disk Space
       uses: jlumbroso/free-disk-space@main
diff --git a/.github/workflows/maven.yaml b/.github/workflows/maven.yaml
index 6264d4c008..4fcc70635b 100644
--- a/.github/workflows/maven.yaml
+++ b/.github/workflows/maven.yaml
@@ -29,9 +29,6 @@ jobs:
       - name: checkout project
         uses: actions/checkout@v2
 
-      - name: clean space
-        uses: ./.github/workflows/composites/clean-space
-
       - name: set env variables
         uses: ./.github/workflows/composites/env-variables
 

From 34648ebd07b36a70d598ad3b61de9f629ac35c90 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Tue, 26 Sep 2023 14:19:09 +0300
Subject: [PATCH 105/151] placeholder commit


From 1eacf6cbbe1235a37b912ad6ec6f3bed0d4a952a Mon Sep 17 00:00:00 2001
From: wind57 
Date: Tue, 26 Sep 2023 14:27:40 +0300
Subject: [PATCH 106/151] test

---
 .github/workflows/composites/clean-space/action.yaml | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/.github/workflows/composites/clean-space/action.yaml b/.github/workflows/composites/clean-space/action.yaml
index f115de3a20..3b2761a64c 100644
--- a/.github/workflows/composites/clean-space/action.yaml
+++ b/.github/workflows/composites/clean-space/action.yaml
@@ -3,6 +3,9 @@ description: clean space
 runs:
   using: "composite"
   steps:
+    - name: gcloud
+      shell: bash
+      run: gcloud info
 
     - name: Free Disk Space
       uses: jlumbroso/free-disk-space@main

From c77b86acc4a4febe8da63b5783f0b1eac657fb71 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Tue, 26 Sep 2023 14:39:06 +0300
Subject: [PATCH 107/151] test

---
 .github/workflows/composites/clean-space/action.yaml | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/.github/workflows/composites/clean-space/action.yaml b/.github/workflows/composites/clean-space/action.yaml
index 3b2761a64c..e1bb096bd5 100644
--- a/.github/workflows/composites/clean-space/action.yaml
+++ b/.github/workflows/composites/clean-space/action.yaml
@@ -5,7 +5,9 @@ runs:
   steps:
     - name: gcloud
       shell: bash
-      run: gcloud info
+      run: | 
+        sudo apt-get update
+        gcloud info
 
     - name: Free Disk Space
       uses: jlumbroso/free-disk-space@main

From 5c244f5edb3ed12776f97dd28046d417e7b6ebd5 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Tue, 26 Sep 2023 18:50:16 +0300
Subject: [PATCH 108/151] review comments

---
 spring-cloud-kubernetes-integration-tests/pom.xml     | 11 +++++++++++
 .../pom.xml                                           |  1 -
 .../pom.xml                                           |  1 -
 .../pom.xml                                           |  1 -
 .../pom.xml                                           |  1 -
 .../pom.xml                                           |  1 -
 .../pom.xml                                           |  1 -
 .../pom.xml                                           |  1 -
 .../pom.xml                                           |  1 -
 .../pom.xml                                           |  1 -
 .../pom.xml                                           |  1 -
 .../pom.xml                                           |  1 -
 .../pom.xml                                           |  1 -
 .../pom.xml                                           |  1 -
 .../pom.xml                                           |  1 -
 .../pom.xml                                           |  1 -
 .../pom.xml                                           |  1 -
 .../spring-cloud-kubernetes-fabric8-istio-it/pom.xml  |  1 -
 18 files changed, 11 insertions(+), 17 deletions(-)

diff --git a/spring-cloud-kubernetes-integration-tests/pom.xml b/spring-cloud-kubernetes-integration-tests/pom.xml
index ebd7479cf8..142af47a7c 100644
--- a/spring-cloud-kubernetes-integration-tests/pom.xml
+++ b/spring-cloud-kubernetes-integration-tests/pom.xml
@@ -32,6 +32,17 @@
 				
 			
 		
+
+		
+			
+				
+					org.apache.maven.plugins
+					maven-failsafe-plugin
+					3.1.2
+				
+			
+		
+
 	
 
 	
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-catalog-watcher/pom.xml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-catalog-watcher/pom.xml
index 2b5afdca5d..38f4e18e73 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-catalog-watcher/pom.xml
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-catalog-watcher/pom.xml
@@ -86,7 +86,6 @@
 			
 				org.apache.maven.plugins
 				maven-failsafe-plugin
-				3.1.2
 				
 					
 						
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-configmap-event-reload-multiple-apps/spring-cloud-kubernetes-client-configuration-watcher-configmap-test-app/pom.xml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-configmap-event-reload-multiple-apps/spring-cloud-kubernetes-client-configuration-watcher-configmap-test-app/pom.xml
index 530756302e..382886e789 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-configmap-event-reload-multiple-apps/spring-cloud-kubernetes-client-configuration-watcher-configmap-test-app/pom.xml
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-configmap-event-reload-multiple-apps/spring-cloud-kubernetes-client-configuration-watcher-configmap-test-app/pom.xml
@@ -55,7 +55,6 @@
 			
 				org.apache.maven.plugins
 				maven-failsafe-plugin
-				3.1.2
 				
 					
 						
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-discovery-it/pom.xml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-discovery-it/pom.xml
index 243f1a4d32..ec84212c8a 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-discovery-it/pom.xml
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-discovery-it/pom.xml
@@ -96,7 +96,6 @@
 			
 				org.apache.maven.plugins
 				maven-failsafe-plugin
-				3.1.2
 				
 					
 						
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-event-and-polling-reload/pom.xml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-event-and-polling-reload/pom.xml
index 10a1503128..dfc5d03931 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-event-and-polling-reload/pom.xml
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-event-and-polling-reload/pom.xml
@@ -95,7 +95,6 @@
 			
 				org.apache.maven.plugins
 				maven-failsafe-plugin
-				3.1.2
 				
 					
 						
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-loadbalancer-it/pom.xml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-loadbalancer-it/pom.xml
index 1aea888da1..61e6ba120f 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-loadbalancer-it/pom.xml
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-loadbalancer-it/pom.xml
@@ -91,7 +91,6 @@
 			
 				org.apache.maven.plugins
 				maven-failsafe-plugin
-				3.1.2
 				
 					
 						
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-secrets-event-reload-multiple-apps/spring-cloud-kubernetes-client-configuration-watcher-secrets-test-app/pom.xml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-secrets-event-reload-multiple-apps/spring-cloud-kubernetes-client-configuration-watcher-secrets-test-app/pom.xml
index 38b3156899..ba73ef90b8 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-secrets-event-reload-multiple-apps/spring-cloud-kubernetes-client-configuration-watcher-secrets-test-app/pom.xml
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-secrets-event-reload-multiple-apps/spring-cloud-kubernetes-client-configuration-watcher-secrets-test-app/pom.xml
@@ -55,7 +55,6 @@
 			
 				org.apache.maven.plugins
 				maven-failsafe-plugin
-				3.1.2
 				
 					
 						
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-configuration-watcher-it/pom.xml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-configuration-watcher-it/pom.xml
index 4179f2975c..69d3aac1de 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-configuration-watcher-it/pom.xml
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-configuration-watcher-it/pom.xml
@@ -111,7 +111,6 @@
 			
 				org.apache.maven.plugins
 				maven-failsafe-plugin
-				3.1.2
 				
 					
 						
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-discoveryclient-it/pom.xml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-discoveryclient-it/pom.xml
index 512716a58c..74e485be7f 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-discoveryclient-it/pom.xml
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-discoveryclient-it/pom.xml
@@ -92,7 +92,6 @@
 			
 				org.apache.maven.plugins
 				maven-failsafe-plugin
-				3.1.2
 				
 					
 						
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/pom.xml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/pom.xml
index 0f93f700fb..e30c96300f 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/pom.xml
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/pom.xml
@@ -86,7 +86,6 @@
 			
 				org.apache.maven.plugins
 				maven-failsafe-plugin
-				3.1.2
 				
 					
 						
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-configmap-event-reload/pom.xml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-configmap-event-reload/pom.xml
index bc22366d8b..a1ba8bb15b 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-configmap-event-reload/pom.xml
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-configmap-event-reload/pom.xml
@@ -93,7 +93,6 @@
 			
 				org.apache.maven.plugins
 				maven-failsafe-plugin
-				3.1.2
 				
 					
 						
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-configmap-polling-reload/pom.xml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-configmap-polling-reload/pom.xml
index 5add6f8edd..c5b250af03 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-configmap-polling-reload/pom.xml
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-configmap-polling-reload/pom.xml
@@ -96,7 +96,6 @@
 			
 				org.apache.maven.plugins
 				maven-failsafe-plugin
-				3.1.2
 				
 					
 						
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-configmap/pom.xml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-configmap/pom.xml
index 5d411470b7..f95d31e806 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-configmap/pom.xml
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-configmap/pom.xml
@@ -86,7 +86,6 @@
 			
 				org.apache.maven.plugins
 				maven-failsafe-plugin
-				3.1.2
 				
 					
 						
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery-with-bootstrap/pom.xml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery-with-bootstrap/pom.xml
index d0eb7669fd..0f5a4a4934 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery-with-bootstrap/pom.xml
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery-with-bootstrap/pom.xml
@@ -90,7 +90,6 @@
 			
 				org.apache.maven.plugins
 				maven-failsafe-plugin
-				3.1.2
 				
 					
 						
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/pom.xml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/pom.xml
index bb1d63c5dc..dfe6a31ec6 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/pom.xml
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/pom.xml
@@ -86,7 +86,6 @@
 			
 				org.apache.maven.plugins
 				maven-failsafe-plugin
-				3.1.2
 				
 					
 						
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-loadbalancer/pom.xml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-loadbalancer/pom.xml
index 1df946c6c0..9362129cb0 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-loadbalancer/pom.xml
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-loadbalancer/pom.xml
@@ -86,7 +86,6 @@
 			
 				org.apache.maven.plugins
 				maven-failsafe-plugin
-				3.1.2
 				
 					
 						
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-secrets-event-reload/pom.xml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-secrets-event-reload/pom.xml
index 1c071aa98f..0778446710 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-secrets-event-reload/pom.xml
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-secrets-event-reload/pom.xml
@@ -88,7 +88,6 @@
 			
 				org.apache.maven.plugins
 				maven-failsafe-plugin
-				3.1.2
 				
 					
 						
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-istio-it/pom.xml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-istio-it/pom.xml
index 3c047314dd..c1d9fb67a5 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-istio-it/pom.xml
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-istio-it/pom.xml
@@ -86,7 +86,6 @@
 			
 				org.apache.maven.plugins
 				maven-failsafe-plugin
-				3.1.2
 				
 					
 						

From 6810e8f6bcff9ea9ca42b1d8a4e07d759df3fed9 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Tue, 26 Sep 2023 19:37:56 +0300
Subject: [PATCH 109/151] test

---
 .github/workflows/composites/clean-space/action.yaml | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/.github/workflows/composites/clean-space/action.yaml b/.github/workflows/composites/clean-space/action.yaml
index e1bb096bd5..f0e9488b01 100644
--- a/.github/workflows/composites/clean-space/action.yaml
+++ b/.github/workflows/composites/clean-space/action.yaml
@@ -7,7 +7,14 @@ runs:
       shell: bash
       run: | 
         sudo apt-get update
-        gcloud info
+        sudo apt-get remove -y '^dotnet-.*'
+        sudo apt-get remove -y '^llvm-.*'
+        sudo apt-get remove -y 'php.*'
+        sudo apt-get remove -y '^mongodb-.*'
+        sudo apt-get remove -y '^mysql-.*'
+        sudo apt-get remove -y azure-cli google-cloud-sdk google-chrome-stable firefox powershell mono-devel libgl1-mesa-dri
+        sudo apt-get autoremove -y
+        sudo apt-get clean
 
     - name: Free Disk Space
       uses: jlumbroso/free-disk-space@main
@@ -16,5 +23,5 @@ runs:
         android: true
         dotnet: true
         haskell: true
-        large-packages: true
+        large-packages: false
         swap-storage: true

From dc62bbc6eade9231fca82df7b7f7735ba7f85335 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Tue, 26 Sep 2023 19:48:30 +0300
Subject: [PATCH 110/151] test

---
 .../composites/clean-space/action.yaml        | 20 +++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/.github/workflows/composites/clean-space/action.yaml b/.github/workflows/composites/clean-space/action.yaml
index f0e9488b01..5f76a9f56a 100644
--- a/.github/workflows/composites/clean-space/action.yaml
+++ b/.github/workflows/composites/clean-space/action.yaml
@@ -12,16 +12,16 @@ runs:
         sudo apt-get remove -y 'php.*'
         sudo apt-get remove -y '^mongodb-.*'
         sudo apt-get remove -y '^mysql-.*'
-        sudo apt-get remove -y azure-cli google-cloud-sdk google-chrome-stable firefox powershell mono-devel libgl1-mesa-dri
+        sudo apt-get remove -y azure-cli # google-cloud-sdk google-chrome-stable firefox powershell mono-devel libgl1-mesa-dri
         sudo apt-get autoremove -y
         sudo apt-get clean
 
-    - name: Free Disk Space
-      uses: jlumbroso/free-disk-space@main
-      with:
-        tool-cache: true
-        android: true
-        dotnet: true
-        haskell: true
-        large-packages: false
-        swap-storage: true
+#    - name: Free Disk Space
+#      uses: jlumbroso/free-disk-space@main
+#      with:
+#        tool-cache: true
+#        android: true
+#        dotnet: true
+#        haskell: true
+#        large-packages: false
+#        swap-storage: true

From 5d5ea38c31d693dcb2836db9cca4484dde3a82ec Mon Sep 17 00:00:00 2001
From: wind57 
Date: Tue, 26 Sep 2023 20:05:04 +0300
Subject: [PATCH 111/151] test

---
 .github/workflows/composites/clean-space/action.yaml | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/.github/workflows/composites/clean-space/action.yaml b/.github/workflows/composites/clean-space/action.yaml
index 5f76a9f56a..07affc2139 100644
--- a/.github/workflows/composites/clean-space/action.yaml
+++ b/.github/workflows/composites/clean-space/action.yaml
@@ -12,9 +12,10 @@ runs:
         sudo apt-get remove -y 'php.*'
         sudo apt-get remove -y '^mongodb-.*'
         sudo apt-get remove -y '^mysql-.*'
-        sudo apt-get remove -y azure-cli # google-cloud-sdk google-chrome-stable firefox powershell mono-devel libgl1-mesa-dri
-        sudo apt-get autoremove -y
-        sudo apt-get clean
+        sudo apt-get remove -y azure-cli # google-chrome-stable firefox powershell mono-devel libgl1-mesa-dri
+        sudo apt-get remove -y google-cloud-sdk
+        #sudo apt-get autoremove -y
+        #sudo apt-get clean
 
 #    - name: Free Disk Space
 #      uses: jlumbroso/free-disk-space@main

From f31d7414544fa277fb6d3c362aa91aadf5c2468a Mon Sep 17 00:00:00 2001
From: wind57 
Date: Tue, 26 Sep 2023 20:16:31 +0300
Subject: [PATCH 112/151] test

---
 .github/workflows/composites/clean-space/action.yaml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/.github/workflows/composites/clean-space/action.yaml b/.github/workflows/composites/clean-space/action.yaml
index 07affc2139..2bf4004714 100644
--- a/.github/workflows/composites/clean-space/action.yaml
+++ b/.github/workflows/composites/clean-space/action.yaml
@@ -14,8 +14,8 @@ runs:
         sudo apt-get remove -y '^mysql-.*'
         sudo apt-get remove -y azure-cli # google-chrome-stable firefox powershell mono-devel libgl1-mesa-dri
         sudo apt-get remove -y google-cloud-sdk
-        #sudo apt-get autoremove -y
-        #sudo apt-get clean
+        sudo apt-get autoremove -y
+        sudo apt-get clean
 
 #    - name: Free Disk Space
 #      uses: jlumbroso/free-disk-space@main

From 8de4b9c09390f9d952becc250ef4f4b68dc87bfa Mon Sep 17 00:00:00 2001
From: wind57 
Date: Tue, 26 Sep 2023 20:24:27 +0300
Subject: [PATCH 113/151] test

---
 .../composites/clean-space/action.yaml        | 23 +++++++++----------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/.github/workflows/composites/clean-space/action.yaml b/.github/workflows/composites/clean-space/action.yaml
index 2bf4004714..1e33aa9f4f 100644
--- a/.github/workflows/composites/clean-space/action.yaml
+++ b/.github/workflows/composites/clean-space/action.yaml
@@ -3,6 +3,7 @@ description: clean space
 runs:
   using: "composite"
   steps:
+
     - name: gcloud
       shell: bash
       run: | 
@@ -12,17 +13,15 @@ runs:
         sudo apt-get remove -y 'php.*'
         sudo apt-get remove -y '^mongodb-.*'
         sudo apt-get remove -y '^mysql-.*'
-        sudo apt-get remove -y azure-cli # google-chrome-stable firefox powershell mono-devel libgl1-mesa-dri
-        sudo apt-get remove -y google-cloud-sdk
-        sudo apt-get autoremove -y
+        sudo apt-get remove -y azure-cli google-chrome-stable firefox powershell mono-devel libgl1-mesa-dri
         sudo apt-get clean
 
-#    - name: Free Disk Space
-#      uses: jlumbroso/free-disk-space@main
-#      with:
-#        tool-cache: true
-#        android: true
-#        dotnet: true
-#        haskell: true
-#        large-packages: false
-#        swap-storage: true
+    - name: Free Disk Space
+      uses: jlumbroso/free-disk-space@main
+      with:
+        tool-cache: true
+        android: true
+        dotnet: true
+        haskell: true
+        large-packages: false
+        swap-storage: true

From 7715ca5883f8968a4ef154c1b529c4ea128b67b5 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Tue, 26 Sep 2023 20:32:09 +0300
Subject: [PATCH 114/151] test

---
 .github/workflows/composites/clean-space/action.yaml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/workflows/composites/clean-space/action.yaml b/.github/workflows/composites/clean-space/action.yaml
index 1e33aa9f4f..db87c9a28d 100644
--- a/.github/workflows/composites/clean-space/action.yaml
+++ b/.github/workflows/composites/clean-space/action.yaml
@@ -13,7 +13,7 @@ runs:
         sudo apt-get remove -y 'php.*'
         sudo apt-get remove -y '^mongodb-.*'
         sudo apt-get remove -y '^mysql-.*'
-        sudo apt-get remove -y azure-cli google-chrome-stable firefox powershell mono-devel libgl1-mesa-dri
+        sudo apt-get remove -y azure-cli google-cloud-sdk google-chrome-stable firefox powershell mono-devel libgl1-mesa-dri
         sudo apt-get clean
 
     - name: Free Disk Space

From 40c45148a9da56eb0ef906a080c469180c52d958 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Tue, 26 Sep 2023 20:43:14 +0300
Subject: [PATCH 115/151] test

---
 .github/workflows/composites/clean-space/action.yaml | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/.github/workflows/composites/clean-space/action.yaml b/.github/workflows/composites/clean-space/action.yaml
index db87c9a28d..792bd071a5 100644
--- a/.github/workflows/composites/clean-space/action.yaml
+++ b/.github/workflows/composites/clean-space/action.yaml
@@ -4,6 +4,10 @@ runs:
   using: "composite"
   steps:
 
+    - name: remove google-cloud-sdk
+      shell: bash
+      run: sudo apt-get remove -y google-cloud-sdk
+
     - name: gcloud
       shell: bash
       run: | 
@@ -13,7 +17,8 @@ runs:
         sudo apt-get remove -y 'php.*'
         sudo apt-get remove -y '^mongodb-.*'
         sudo apt-get remove -y '^mysql-.*'
-        sudo apt-get remove -y azure-cli google-cloud-sdk google-chrome-stable firefox powershell mono-devel libgl1-mesa-dri
+        sudo apt-get remove -y azure-cli google-chrome-stable firefox powershell mono-devel libgl1-mesa-dri
+        sudo apt-get autoremove -y
         sudo apt-get clean
 
     - name: Free Disk Space

From 67d1cc4eef488235ef73123bc0e6fc5a85769712 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Tue, 26 Sep 2023 20:50:22 +0300
Subject: [PATCH 116/151] test

---
 .github/workflows/composites/clean-space/action.yaml | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/.github/workflows/composites/clean-space/action.yaml b/.github/workflows/composites/clean-space/action.yaml
index 792bd071a5..10c8985855 100644
--- a/.github/workflows/composites/clean-space/action.yaml
+++ b/.github/workflows/composites/clean-space/action.yaml
@@ -6,12 +6,13 @@ runs:
 
     - name: remove google-cloud-sdk
       shell: bash
-      run: sudo apt-get remove -y google-cloud-sdk
+      run: |
+        sudo apt-get update
+        sudo apt-get remove -y google-cloud-sdk
 
     - name: gcloud
       shell: bash
       run: | 
-        sudo apt-get update
         sudo apt-get remove -y '^dotnet-.*'
         sudo apt-get remove -y '^llvm-.*'
         sudo apt-get remove -y 'php.*'

From 622cc946a8b4d8ced507053e3528a2901df50328 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Tue, 26 Sep 2023 21:00:18 +0300
Subject: [PATCH 117/151] test

---
 .github/workflows/composites/clean-space/action.yaml | 1 +
 .github/workflows/maven.yaml                         | 3 +++
 2 files changed, 4 insertions(+)

diff --git a/.github/workflows/composites/clean-space/action.yaml b/.github/workflows/composites/clean-space/action.yaml
index 10c8985855..a0e78799a6 100644
--- a/.github/workflows/composites/clean-space/action.yaml
+++ b/.github/workflows/composites/clean-space/action.yaml
@@ -8,6 +8,7 @@ runs:
       shell: bash
       run: |
         sudo apt-get update
+        gcloud info
         sudo apt-get remove -y google-cloud-sdk
 
     - name: gcloud
diff --git a/.github/workflows/maven.yaml b/.github/workflows/maven.yaml
index 4fcc70635b..6264d4c008 100644
--- a/.github/workflows/maven.yaml
+++ b/.github/workflows/maven.yaml
@@ -29,6 +29,9 @@ jobs:
       - name: checkout project
         uses: actions/checkout@v2
 
+      - name: clean space
+        uses: ./.github/workflows/composites/clean-space
+
       - name: set env variables
         uses: ./.github/workflows/composites/env-variables
 

From 78734c14cb348d346f529a3238bc8afc0070fad3 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Tue, 26 Sep 2023 21:02:57 +0300
Subject: [PATCH 118/151] test

---
 .github/workflows/composites/clean-space/action.yaml | 2 +-
 .github/workflows/maven.yaml                         | 3 ---
 2 files changed, 1 insertion(+), 4 deletions(-)

diff --git a/.github/workflows/composites/clean-space/action.yaml b/.github/workflows/composites/clean-space/action.yaml
index a0e78799a6..23507eb189 100644
--- a/.github/workflows/composites/clean-space/action.yaml
+++ b/.github/workflows/composites/clean-space/action.yaml
@@ -11,7 +11,7 @@ runs:
         gcloud info
         sudo apt-get remove -y google-cloud-sdk
 
-    - name: gcloud
+    - name: same as 'large-packages' but without 'google-cloud-sdk'
       shell: bash
       run: | 
         sudo apt-get remove -y '^dotnet-.*'
diff --git a/.github/workflows/maven.yaml b/.github/workflows/maven.yaml
index 6264d4c008..4fcc70635b 100644
--- a/.github/workflows/maven.yaml
+++ b/.github/workflows/maven.yaml
@@ -29,9 +29,6 @@ jobs:
       - name: checkout project
         uses: actions/checkout@v2
 
-      - name: clean space
-        uses: ./.github/workflows/composites/clean-space
-
       - name: set env variables
         uses: ./.github/workflows/composites/env-variables
 

From c2ad21e443aba983f7506eb185f17e838d28c20c Mon Sep 17 00:00:00 2001
From: wind57 
Date: Tue, 26 Sep 2023 21:12:38 +0300
Subject: [PATCH 119/151] test

---
 .github/workflows/composites/clean-space/action.yaml | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/.github/workflows/composites/clean-space/action.yaml b/.github/workflows/composites/clean-space/action.yaml
index 23507eb189..1e08c8f49b 100644
--- a/.github/workflows/composites/clean-space/action.yaml
+++ b/.github/workflows/composites/clean-space/action.yaml
@@ -4,13 +4,6 @@ runs:
   using: "composite"
   steps:
 
-    - name: remove google-cloud-sdk
-      shell: bash
-      run: |
-        sudo apt-get update
-        gcloud info
-        sudo apt-get remove -y google-cloud-sdk
-
     - name: same as 'large-packages' but without 'google-cloud-sdk'
       shell: bash
       run: | 

From 1d853d206d1e049a9edea4956a9d02b870d8706f Mon Sep 17 00:00:00 2001
From: wind57 
Date: Tue, 26 Sep 2023 21:15:51 +0300
Subject: [PATCH 120/151] test

---
 .github/workflows/composites/clean-space/action.yaml | 9 +++++++++
 .github/workflows/maven.yaml                         | 3 +++
 2 files changed, 12 insertions(+)

diff --git a/.github/workflows/composites/clean-space/action.yaml b/.github/workflows/composites/clean-space/action.yaml
index 1e08c8f49b..ba3b646879 100644
--- a/.github/workflows/composites/clean-space/action.yaml
+++ b/.github/workflows/composites/clean-space/action.yaml
@@ -4,6 +4,15 @@ runs:
   using: "composite"
   steps:
 
+    - name: manually remove gcloud
+      shell: bash
+      run: |
+        gcloud_sdk_root=$(gcloud info --format='value(installation.sdk_root)')
+        gcloud_global_config=$(gcloud info --format='value(config.paths.global_config_dir)')
+        
+        sudo rm -fr $gcloud_sdk_root
+        sudo rm -fr $gcloud_global_config
+
     - name: same as 'large-packages' but without 'google-cloud-sdk'
       shell: bash
       run: | 
diff --git a/.github/workflows/maven.yaml b/.github/workflows/maven.yaml
index 4fcc70635b..6264d4c008 100644
--- a/.github/workflows/maven.yaml
+++ b/.github/workflows/maven.yaml
@@ -29,6 +29,9 @@ jobs:
       - name: checkout project
         uses: actions/checkout@v2
 
+      - name: clean space
+        uses: ./.github/workflows/composites/clean-space
+
       - name: set env variables
         uses: ./.github/workflows/composites/env-variables
 

From 5e985c5e3c50e05f6b16c83a5a5537875cd5471d Mon Sep 17 00:00:00 2001
From: wind57 
Date: Tue, 26 Sep 2023 21:31:06 +0300
Subject: [PATCH 121/151] test

---
 .github/workflows/composites/clean-space/action.yaml | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/.github/workflows/composites/clean-space/action.yaml b/.github/workflows/composites/clean-space/action.yaml
index ba3b646879..588253a3e6 100644
--- a/.github/workflows/composites/clean-space/action.yaml
+++ b/.github/workflows/composites/clean-space/action.yaml
@@ -10,6 +10,9 @@ runs:
         gcloud_sdk_root=$(gcloud info --format='value(installation.sdk_root)')
         gcloud_global_config=$(gcloud info --format='value(config.paths.global_config_dir)')
         
+        echo "will remove directory : $gcloud_sdk_root"
+        echo "will remove directory : $gcloud_global_config"
+        
         sudo rm -fr $gcloud_sdk_root
         sudo rm -fr $gcloud_global_config
 

From c982060ef0d1317fa9161b4e0e116f652ba43079 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Tue, 26 Sep 2023 21:38:38 +0300
Subject: [PATCH 122/151] test

---
 .github/workflows/maven.yaml | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/.github/workflows/maven.yaml b/.github/workflows/maven.yaml
index 6264d4c008..4fcc70635b 100644
--- a/.github/workflows/maven.yaml
+++ b/.github/workflows/maven.yaml
@@ -29,9 +29,6 @@ jobs:
       - name: checkout project
         uses: actions/checkout@v2
 
-      - name: clean space
-        uses: ./.github/workflows/composites/clean-space
-
       - name: set env variables
         uses: ./.github/workflows/composites/env-variables
 

From 8a42c1582d13c7768cac841818aff5753390b940 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Tue, 26 Sep 2023 22:20:46 +0300
Subject: [PATCH 123/151] fix build

---
 .github/workflows/composites/clean-space/action.yaml | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/.github/workflows/composites/clean-space/action.yaml b/.github/workflows/composites/clean-space/action.yaml
index 588253a3e6..2f9906ce2e 100644
--- a/.github/workflows/composites/clean-space/action.yaml
+++ b/.github/workflows/composites/clean-space/action.yaml
@@ -4,6 +4,9 @@ runs:
   using: "composite"
   steps:
 
+    ### this is supposed to be simpler, but it's a work-around for:
+    ### https://github.com/jlumbroso/free-disk-space/issues/14
+
     - name: manually remove gcloud
       shell: bash
       run: |

From 6a07b131506b7ac03ade2a9fe11f690e1ca70bce Mon Sep 17 00:00:00 2001
From: wind57 
Date: Tue, 26 Sep 2023 22:58:55 +0300
Subject: [PATCH 124/151] placeholder commit


From e9077e285f78ad5c781754c45576ef431a9942a3 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Wed, 27 Sep 2023 07:32:32 +0300
Subject: [PATCH 125/151] review comments

---
 .../action.yaml                               |  2 +-
 .../action.yaml                               |  2 +-
 .../pom.xml                                   | 27 ++++++++++++-------
 3 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/.github/workflows/composites/run-and-save-test-times-when-cache-missing/action.yaml b/.github/workflows/composites/run-and-save-test-times-when-cache-missing/action.yaml
index 0cb4085b21..b1d18fef80 100644
--- a/.github/workflows/composites/run-and-save-test-times-when-cache-missing/action.yaml
+++ b/.github/workflows/composites/run-and-save-test-times-when-cache-missing/action.yaml
@@ -61,7 +61,7 @@ runs:
            ./mvnw -s .settings.xml \
            -DtestsToRun=${TEST_ARG[@]} \
            -e clean install \
-           -P sonar -nsu --batch-mode \
+           -P 'sonar, run-on-github-actions'  -nsu --batch-mode \
            -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn \
            -Dhttp.keepAlive=false \
            -Dmaven.wagon.http.pool=false \
diff --git a/.github/workflows/composites/run-and-save-test-times-when-cache-present/action.yaml b/.github/workflows/composites/run-and-save-test-times-when-cache-present/action.yaml
index f658cfbf58..7130a907c9 100644
--- a/.github/workflows/composites/run-and-save-test-times-when-cache-present/action.yaml
+++ b/.github/workflows/composites/run-and-save-test-times-when-cache-present/action.yaml
@@ -150,7 +150,7 @@ runs:
         ./mvnw -s .settings.xml \
               -DtestsToRun=${tests_to_run_in_current_index} \
               -e clean install \
-              -P sonar -nsu --batch-mode \
+              -P 'sonar, run-on-github-actions' -nsu --batch-mode \
               -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn \
               -Dhttp.keepAlive=false \
               -Dmaven.wagon.http.pool=false \
diff --git a/spring-cloud-kubernetes-integration-tests/pom.xml b/spring-cloud-kubernetes-integration-tests/pom.xml
index 142af47a7c..d1b0cbaf50 100644
--- a/spring-cloud-kubernetes-integration-tests/pom.xml
+++ b/spring-cloud-kubernetes-integration-tests/pom.xml
@@ -33,18 +33,25 @@
 			
 		
 
-		
-			
-				
-					org.apache.maven.plugins
-					maven-failsafe-plugin
-					3.1.2
-				
-			
-		
-
 	
 
+	
+		
+			run-on-github-actions
+			
+				
+					
+						
+							org.apache.maven.plugins
+							maven-failsafe-plugin
+							3.1.2
+						
+					
+				
+			
+		
+	
+
 	
 		
 			

From 5a7695a53209e195dbc8d9ccf31ec74f2084fbc0 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Wed, 27 Sep 2023 14:00:54 +0300
Subject: [PATCH 126/151] merge

---
 .../kubernetes-leader-election-example/pom.xml              | 4 ++--
 spring-cloud-kubernetes-integration-tests/pom.xml           | 6 ++++++
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/spring-cloud-kubernetes-examples/kubernetes-leader-election-example/pom.xml b/spring-cloud-kubernetes-examples/kubernetes-leader-election-example/pom.xml
index d6bc61dbc0..e13b268c78 100644
--- a/spring-cloud-kubernetes-examples/kubernetes-leader-election-example/pom.xml
+++ b/spring-cloud-kubernetes-examples/kubernetes-leader-election-example/pom.xml
@@ -75,11 +75,11 @@
 			
 			
 				maven-surefire-plugin
-				2.22.2
+				3.1.2
 			
 			
 				maven-failsafe-plugin
-				2.22.2
+				3.1.2
 			
 		
 	
diff --git a/spring-cloud-kubernetes-integration-tests/pom.xml b/spring-cloud-kubernetes-integration-tests/pom.xml
index d1b0cbaf50..1dae169f19 100644
--- a/spring-cloud-kubernetes-integration-tests/pom.xml
+++ b/spring-cloud-kubernetes-integration-tests/pom.xml
@@ -46,6 +46,12 @@
 							maven-failsafe-plugin
 							3.1.2
 						
+
+						
+							org.apache.maven.plugins
+							maven-surefire-plugin
+							3.1.2
+						
 					
 				
 			

From 15785d059ae68530a139164222a48c8bfbb9e9b9 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Wed, 27 Sep 2023 19:06:51 +0300
Subject: [PATCH 127/151] test

---
 .../run-and-save-test-times-when-cache-present/action.yaml      | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/workflows/composites/run-and-save-test-times-when-cache-present/action.yaml b/.github/workflows/composites/run-and-save-test-times-when-cache-present/action.yaml
index 7130a907c9..546a266905 100644
--- a/.github/workflows/composites/run-and-save-test-times-when-cache-present/action.yaml
+++ b/.github/workflows/composites/run-and-save-test-times-when-cache-present/action.yaml
@@ -147,7 +147,7 @@ runs:
         
         echo "will run tests : $tests_to_run_in_current_index"
         
-        ./mvnw -s .settings.xml \
+        ./mvnw -X -s .settings.xml \
               -DtestsToRun=${tests_to_run_in_current_index} \
               -e clean install \
               -P 'sonar, run-on-github-actions' -nsu --batch-mode \

From 94b47a8ae391d7a5d465354cbcf31d1a1442503b Mon Sep 17 00:00:00 2001
From: wind57 
Date: Wed, 27 Sep 2023 19:58:26 +0300
Subject: [PATCH 128/151] placeholder commit


From 4d06337213fd8fbb683fef3b31f00bf2fc1b41db Mon Sep 17 00:00:00 2001
From: wind57 
Date: Wed, 27 Sep 2023 21:08:53 +0300
Subject: [PATCH 129/151] test

---
 .../run-and-save-test-times-when-cache-present/action.yaml     | 1 +
 .../kubernetes-leader-election-example/pom.xml                 | 3 +++
 2 files changed, 4 insertions(+)

diff --git a/.github/workflows/composites/run-and-save-test-times-when-cache-present/action.yaml b/.github/workflows/composites/run-and-save-test-times-when-cache-present/action.yaml
index 546a266905..0068b47b7f 100644
--- a/.github/workflows/composites/run-and-save-test-times-when-cache-present/action.yaml
+++ b/.github/workflows/composites/run-and-save-test-times-when-cache-present/action.yaml
@@ -149,6 +149,7 @@ runs:
         
         ./mvnw -X -s .settings.xml \
               -DtestsToRun=${tests_to_run_in_current_index} \
+              -DUNIQUE_PER_MATRIX_STEP=${CURRENT_INDEX} \
               -e clean install \
               -P 'sonar, run-on-github-actions' -nsu --batch-mode \
               -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn \
diff --git a/spring-cloud-kubernetes-examples/kubernetes-leader-election-example/pom.xml b/spring-cloud-kubernetes-examples/kubernetes-leader-election-example/pom.xml
index e245d5cfe8..7b9fe603b2 100644
--- a/spring-cloud-kubernetes-examples/kubernetes-leader-election-example/pom.xml
+++ b/spring-cloud-kubernetes-examples/kubernetes-leader-election-example/pom.xml
@@ -76,6 +76,9 @@
 			
 				maven-surefire-plugin
 				3.1.2
+				
+					${project.build.directory}/surefire-reports/${UNIQUE_PER_MATRIX_STEP}
+				
 			
 			
 				maven-failsafe-plugin

From ea4eaf618ed948d154fa827c51f6b09fad92eafe Mon Sep 17 00:00:00 2001
From: wind57 
Date: Wed, 27 Sep 2023 21:55:21 +0300
Subject: [PATCH 130/151] test

---
 .../run-and-save-test-times-when-cache-present/action.yaml      | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/workflows/composites/run-and-save-test-times-when-cache-present/action.yaml b/.github/workflows/composites/run-and-save-test-times-when-cache-present/action.yaml
index 0068b47b7f..c249a5bd62 100644
--- a/.github/workflows/composites/run-and-save-test-times-when-cache-present/action.yaml
+++ b/.github/workflows/composites/run-and-save-test-times-when-cache-present/action.yaml
@@ -147,7 +147,7 @@ runs:
         
         echo "will run tests : $tests_to_run_in_current_index"
         
-        ./mvnw -X -s .settings.xml \
+        ./mvnw -s .settings.xml \
               -DtestsToRun=${tests_to_run_in_current_index} \
               -DUNIQUE_PER_MATRIX_STEP=${CURRENT_INDEX} \
               -e clean install \

From e13bcd3209513dddd0fb2a72206f4d72478bb577 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Fri, 29 Sep 2023 09:33:32 +0300
Subject: [PATCH 131/151] fix

---
 .../composites/clean-space/action.yaml        | 21 +------------------
 1 file changed, 1 insertion(+), 20 deletions(-)

diff --git a/.github/workflows/composites/clean-space/action.yaml b/.github/workflows/composites/clean-space/action.yaml
index cba74e0221..f115de3a20 100644
--- a/.github/workflows/composites/clean-space/action.yaml
+++ b/.github/workflows/composites/clean-space/action.yaml
@@ -4,25 +4,6 @@ runs:
   using: "composite"
   steps:
 
-    ### this is supposed to be simpler, but it's a work-around for:
-    ### https://github.com/jlumbroso/free-disk-space/issues/14
-
-    - name: manually remove gcloud
-      shell: bash
-      run: sudo apt-get remove google-cloud-cli
-
-    - name: same as 'large-packages' but without 'google-cloud-sdk'
-      shell: bash
-      run: | 
-        sudo apt-get remove -y '^dotnet-.*'
-        sudo apt-get remove -y '^llvm-.*'
-        sudo apt-get remove -y 'php.*'
-        sudo apt-get remove -y '^mongodb-.*'
-        sudo apt-get remove -y '^mysql-.*'
-        sudo apt-get remove -y azure-cli google-chrome-stable firefox powershell mono-devel libgl1-mesa-dri
-        sudo apt-get autoremove -y
-        sudo apt-get clean
-
     - name: Free Disk Space
       uses: jlumbroso/free-disk-space@main
       with:
@@ -30,5 +11,5 @@ runs:
         android: true
         dotnet: true
         haskell: true
-        large-packages: false
+        large-packages: true
         swap-storage: true

From 0515920476866923c1b6bfb0a9cc4257490f0452 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Fri, 29 Sep 2023 12:18:07 +0300
Subject: [PATCH 132/151] fix

---
 .../composites/pre-test-actions/action.yaml   |  2 +-
 .../action.yaml                               |  3 ++-
 .../action.yaml                               |  3 ++-
 pom.xml                                       | 13 +++++++++--
 .../pom.xml                                   | 23 -------------------
 5 files changed, 16 insertions(+), 28 deletions(-)

diff --git a/.github/workflows/composites/pre-test-actions/action.yaml b/.github/workflows/composites/pre-test-actions/action.yaml
index 657c55e886..3fd401e81f 100644
--- a/.github/workflows/composites/pre-test-actions/action.yaml
+++ b/.github/workflows/composites/pre-test-actions/action.yaml
@@ -25,7 +25,7 @@ runs:
     - name: build project
       shell: bash
       run: |
-        ./mvnw clean install -Dskip.build.image=true -DskipITs -DskipTests -T1C -U -B -q  
+        ./mvnw clean install -DCURRENT_INSTANCE=${CURRENT_INDEX} -Dskip.build.image=true -DskipITs -DskipTests -T1C -U -B -q  
 
     - name: build controllers project
       uses: ./.github/workflows/composites/build-controllers-project
diff --git a/.github/workflows/composites/run-and-save-test-times-when-cache-missing/action.yaml b/.github/workflows/composites/run-and-save-test-times-when-cache-missing/action.yaml
index b1d18fef80..d262d89bbd 100644
--- a/.github/workflows/composites/run-and-save-test-times-when-cache-missing/action.yaml
+++ b/.github/workflows/composites/run-and-save-test-times-when-cache-missing/action.yaml
@@ -60,8 +60,9 @@ runs:
         
            ./mvnw -s .settings.xml \
            -DtestsToRun=${TEST_ARG[@]} \
+           -DCURRENT_INSTANCE=${CURRENT_INDEX} \
            -e clean install \
-           -P 'sonar, run-on-github-actions'  -nsu --batch-mode \
+           -P sonar -nsu --batch-mode \
            -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn \
            -Dhttp.keepAlive=false \
            -Dmaven.wagon.http.pool=false \
diff --git a/.github/workflows/composites/run-and-save-test-times-when-cache-present/action.yaml b/.github/workflows/composites/run-and-save-test-times-when-cache-present/action.yaml
index 7130a907c9..ce2242c3fc 100644
--- a/.github/workflows/composites/run-and-save-test-times-when-cache-present/action.yaml
+++ b/.github/workflows/composites/run-and-save-test-times-when-cache-present/action.yaml
@@ -149,8 +149,9 @@ runs:
         
         ./mvnw -s .settings.xml \
               -DtestsToRun=${tests_to_run_in_current_index} \
+              -DCURRENT_INSTANCE=${CURRENT_INDEX} \
               -e clean install \
-              -P 'sonar, run-on-github-actions' -nsu --batch-mode \
+              -P sonar -nsu --batch-mode \
               -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn \
               -Dhttp.keepAlive=false \
               -Dmaven.wagon.http.pool=false \
diff --git a/pom.xml b/pom.xml
index 2f693f6818..199db284b2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -62,6 +62,7 @@
 	
 
 	
+		one
 		
 		4.8.1
 		4.0.5-SNAPSHOT
@@ -69,8 +70,6 @@
 		4.0.1
 		4.0.5-SNAPSHOT
 
-		3.1.0
-
 		true
 		true
 		
@@ -205,8 +204,18 @@
 					
 						${testsToRun}
 					
+					${project.build.directory}/surefire-reports/${CURRENT_INSTANCE}
+				
+			
+
+			
+				org.apache.maven.plugins
+				maven-failsafe-plugin
+				
+					${project.build.directory}/failsafe-reports/${CURRENT_INSTANCE}
 				
 			
+
 			
 				org.apache.maven.plugins
 				maven-checkstyle-plugin
diff --git a/spring-cloud-kubernetes-integration-tests/pom.xml b/spring-cloud-kubernetes-integration-tests/pom.xml
index 1dae169f19..03363f509a 100644
--- a/spring-cloud-kubernetes-integration-tests/pom.xml
+++ b/spring-cloud-kubernetes-integration-tests/pom.xml
@@ -35,29 +35,6 @@
 
 	
 
-	
-		
-			run-on-github-actions
-			
-				
-					
-						
-							org.apache.maven.plugins
-							maven-failsafe-plugin
-							3.1.2
-						
-
-						
-							org.apache.maven.plugins
-							maven-surefire-plugin
-							3.1.2
-						
-					
-				
-			
-		
-	
-
 	
 		
 			

From 565679c21b8e39d15cd6208669e341d6184b65ab Mon Sep 17 00:00:00 2001
From: wind57 
Date: Fri, 29 Sep 2023 12:24:12 +0300
Subject: [PATCH 133/151] test

---
 .../composites/build-controllers-project/action.yaml        | 6 +++++-
 .github/workflows/composites/pre-test-actions/action.yaml   | 2 +-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/.github/workflows/composites/build-controllers-project/action.yaml b/.github/workflows/composites/build-controllers-project/action.yaml
index 307451c8f5..df34f3c443 100644
--- a/.github/workflows/composites/build-controllers-project/action.yaml
+++ b/.github/workflows/composites/build-controllers-project/action.yaml
@@ -7,5 +7,9 @@ runs:
       shell: bash
       run: |
         cd spring-cloud-kubernetes-controllers
-        .././mvnw -T 1C -U clean install
+        .././mvnw -DCURRENT_INSTANCE=${CURRENT_INDEX} -T 1C -U clean install
         cd ..
+
+    - name: show target path
+      shell: bash
+      run: ls spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configuration-watcher/target/surefire-reports
diff --git a/.github/workflows/composites/pre-test-actions/action.yaml b/.github/workflows/composites/pre-test-actions/action.yaml
index 3fd401e81f..657c55e886 100644
--- a/.github/workflows/composites/pre-test-actions/action.yaml
+++ b/.github/workflows/composites/pre-test-actions/action.yaml
@@ -25,7 +25,7 @@ runs:
     - name: build project
       shell: bash
       run: |
-        ./mvnw clean install -DCURRENT_INSTANCE=${CURRENT_INDEX} -Dskip.build.image=true -DskipITs -DskipTests -T1C -U -B -q  
+        ./mvnw clean install -Dskip.build.image=true -DskipITs -DskipTests -T1C -U -B -q  
 
     - name: build controllers project
       uses: ./.github/workflows/composites/build-controllers-project

From 3a869235fd3a1df0ea440725b3bfaabb0c9d929f Mon Sep 17 00:00:00 2001
From: wind57 
Date: Fri, 29 Sep 2023 15:27:10 +0300
Subject: [PATCH 134/151] test

---
 .../workflows/composites/build-controllers-project/action.yaml  | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/.github/workflows/composites/build-controllers-project/action.yaml b/.github/workflows/composites/build-controllers-project/action.yaml
index df34f3c443..f9df2c519d 100644
--- a/.github/workflows/composites/build-controllers-project/action.yaml
+++ b/.github/workflows/composites/build-controllers-project/action.yaml
@@ -5,6 +5,8 @@ runs:
   steps:
     - name: build controllers project
       shell: bash
+      env:
+        CURRENT_INDEX: ${{ matrix.current_index }}
       run: |
         cd spring-cloud-kubernetes-controllers
         .././mvnw -DCURRENT_INSTANCE=${CURRENT_INDEX} -T 1C -U clean install

From 03274168fa2133c0277350d84598264a5ccd0ec5 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Mon, 2 Oct 2023 15:49:34 +0300
Subject: [PATCH 135/151] review comments

---
 .../composites/build-controllers-project/action.yaml          | 4 ----
 pom.xml                                                       | 4 ++++
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/.github/workflows/composites/build-controllers-project/action.yaml b/.github/workflows/composites/build-controllers-project/action.yaml
index f9df2c519d..dff8da1648 100644
--- a/.github/workflows/composites/build-controllers-project/action.yaml
+++ b/.github/workflows/composites/build-controllers-project/action.yaml
@@ -11,7 +11,3 @@ runs:
         cd spring-cloud-kubernetes-controllers
         .././mvnw -DCURRENT_INSTANCE=${CURRENT_INDEX} -T 1C -U clean install
         cd ..
-
-    - name: show target path
-      shell: bash
-      run: ls spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configuration-watcher/target/surefire-reports
diff --git a/pom.xml b/pom.xml
index 199db284b2..271e4616b0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -62,6 +62,10 @@
 	
 
 	
+		
+		
+		
+		
 		one
 		
 		4.8.1

From a8c478f6968e3094d74048d0ae0b4eace20e334e Mon Sep 17 00:00:00 2001
From: wind57 
Date: Fri, 13 Oct 2023 21:43:35 +0300
Subject: [PATCH 136/151] dirty

---
 .../discovery/Fabric8DiscoveryController.java |   2 +-
 .../pom.xml                                   | 105 ----------------
 .../kubernetes/fabric8/core/SimpleCoreIT.java | 116 ------------------
 3 files changed, 1 insertion(+), 222 deletions(-)
 delete mode 100644 spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-simple-core/pom.xml
 delete mode 100644 spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-simple-core/src/test/java/org/springframework/cloud/kubernetes/fabric8/core/SimpleCoreIT.java

diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/client/discovery/Fabric8DiscoveryController.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/client/discovery/Fabric8DiscoveryController.java
index 2960fcf592..363f574423 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/client/discovery/Fabric8DiscoveryController.java
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/client/discovery/Fabric8DiscoveryController.java
@@ -22,10 +22,10 @@
 
 import org.springframework.beans.factory.ObjectProvider;
 import org.springframework.cloud.client.ServiceInstance;
-import org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClient;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RestController;
+import org.springframework.cloud.kubernetes.fabric8.discovery.Fabric8KubernetesDiscoveryClient;
 
 /**
  * @author wind57
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-simple-core/pom.xml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-simple-core/pom.xml
deleted file mode 100644
index 5ee2a45a27..0000000000
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-simple-core/pom.xml
+++ /dev/null
@@ -1,105 +0,0 @@
-
-
-	
-		org.springframework.cloud
-		spring-cloud-kubernetes-integration-tests
-		3.1.0-SNAPSHOT
-	
-	4.0.0
-
-	spring-cloud-kubernetes-fabric8-client-simple-core
-
-	
-		
-			org.springframework.cloud
-			spring-cloud-starter-kubernetes-fabric8-all
-		
-		
-			org.springframework.boot
-			spring-boot-starter-webflux
-		
-		
-			org.springframework.boot
-			spring-boot-starter-actuator
-		
-
-		
-			org.springframework.cloud
-			spring-cloud-kubernetes-test-support
-		
-
-	
-	
-		
-			
-				../src/main/resources
-				true
-			
-			
-				src/main/resources
-				true
-			
-		
-
-		
-			
-			
-			
-				org.springframework.boot
-				spring-boot-maven-plugin
-				
-					docker.io/springcloud/${project.artifactId}:${project.version}
-				
-				
-					
-						build-image
-						
-							${skip.build.image}
-						
-						package
-						
-							build-image
-						
-					
-					
-						repackage
-						package
-						
-							repackage
-						
-					
-				
-			
-
-			
-			
-				org.apache.maven.plugins
-				maven-surefire-plugin
-				
-					true
-				
-			
-
-			
-			
-				org.apache.maven.plugins
-				maven-failsafe-plugin
-				
-					
-						
-							integration-test
-						
-					
-				
-				
-					
-						${testsToRun}
-					
-				
-			
-		
-	
-
-
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-simple-core/src/test/java/org/springframework/cloud/kubernetes/fabric8/core/SimpleCoreIT.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-simple-core/src/test/java/org/springframework/cloud/kubernetes/fabric8/core/SimpleCoreIT.java
deleted file mode 100644
index 7a810b3b2a..0000000000
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-simple-core/src/test/java/org/springframework/cloud/kubernetes/fabric8/core/SimpleCoreIT.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * Copyright 2013-2021 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.core;
-
-import java.io.InputStream;
-import java.time.Duration;
-import java.util.Objects;
-
-import io.fabric8.kubernetes.api.model.Service;
-import io.fabric8.kubernetes.api.model.apps.Deployment;
-import io.fabric8.kubernetes.api.model.networking.v1.Ingress;
-import io.fabric8.kubernetes.client.KubernetesClient;
-import io.fabric8.kubernetes.client.utils.Serialization;
-import org.junit.jupiter.api.AfterAll;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Test;
-import org.testcontainers.k3s.K3sContainer;
-import reactor.netty.http.client.HttpClient;
-import reactor.util.retry.Retry;
-import reactor.util.retry.RetryBackoffSpec;
-
-import org.springframework.cloud.kubernetes.integration.tests.commons.Commons;
-import org.springframework.cloud.kubernetes.integration.tests.commons.Phase;
-import org.springframework.cloud.kubernetes.integration.tests.commons.fabric8_client.Util;
-import org.springframework.http.HttpMethod;
-import org.springframework.http.client.reactive.ReactorClientHttpConnector;
-import org.springframework.web.reactive.function.client.WebClient;
-
-/**
- * @author wind57
- */
-class SimpleCoreIT {
-
-	private static final String NAMESPACE = "default";
-
-	private static final String IMAGE_NAME = "spring-cloud-kubernetes-fabric8-client-simple-core";
-
-	private static KubernetesClient client;
-
-	private static Util util;
-
-	private static final K3sContainer K3S = Commons.container();
-
-	@BeforeAll
-	static void beforeAll() throws Exception {
-		K3S.start();
-		Commons.validateImage(IMAGE_NAME, K3S);
-		Commons.loadSpringCloudKubernetesImage(IMAGE_NAME, K3S);
-
-		util = new Util(K3S);
-		client = util.client();
-		util.setUp(NAMESPACE);
-
-		manifests(Phase.CREATE);
-	}
-
-	@AfterAll
-	static void after() throws Exception {
-		manifests(Phase.DELETE);
-		Commons.cleanUp(IMAGE_NAME, K3S);
-		Commons.systemPrune();
-	}
-
-	@Test
-	void test() {
-		WebClient client = builder().baseUrl("http://localhost/message").build();
-
-		String result = client.method(HttpMethod.GET).retrieve().bodyToMono(String.class).retryWhen(retrySpec())
-				.block();
-
-		// value must come from application-kubernetes.yml
-		Assertions.assertEquals("Hello from k8s profile", result);
-	}
-
-	private static void manifests(Phase phase) {
-
-		InputStream deploymentStream = util.inputStream("simple-core-deployment.yaml");
-		InputStream serviceStream = util.inputStream("simple-core-service.yaml");
-		InputStream ingressStream = util.inputStream("simple-core-ingress.yaml");
-		Deployment deployment = Serialization.unmarshal(deploymentStream, Deployment.class);
-		Service service = Serialization.unmarshal(serviceStream, Service.class);
-		Ingress ingress = Serialization.unmarshal(ingressStream, Ingress.class);
-
-		if (phase.equals(Phase.CREATE)) {
-			util.createAndWait(NAMESPACE, null, deployment, service, ingress, true);
-		}
-		else {
-			util.deleteAndWait(NAMESPACE, deployment, service, ingress);
-		}
-
-	}
-
-	private WebClient.Builder builder() {
-		return WebClient.builder().clientConnector(new ReactorClientHttpConnector(HttpClient.create()));
-	}
-
-	private RetryBackoffSpec retrySpec() {
-		return Retry.fixedDelay(15, Duration.ofSeconds(1)).filter(Objects::nonNull);
-	}
-
-}

From df2d07e8979cca4c6b9f631f835c06f860559ae5 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Fri, 13 Oct 2023 21:47:22 +0300
Subject: [PATCH 137/151] fix

---
 .github/workflows/maven.yaml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/.github/workflows/maven.yaml b/.github/workflows/maven.yaml
index 4fcc70635b..fd2779105d 100644
--- a/.github/workflows/maven.yaml
+++ b/.github/workflows/maven.yaml
@@ -98,7 +98,7 @@ jobs:
       SEGMENT_DOWNLOAD_TIMEOUT_MINS: 30
     # only run this one if there is a previous cache of test times
     if: needs.build.outputs.test_times_cache_present == 'true'
-    timeout-minutes: 60
+    timeout-minutes: 120
 
     strategy:
       fail-fast: true
@@ -145,7 +145,7 @@ jobs:
     runs-on: ubuntu-latest
     env:
       SEGMENT_DOWNLOAD_TIMEOUT_MINS: 30
-    timeout-minutes: 60
+    timeout-minutes: 120
     # only run this one if there is no previous cache of test times
     if: needs.build.outputs.test_times_cache_present == 'false'
 

From 014e12d98171ec8b4a534560253309e52d2fde37 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Fri, 13 Oct 2023 22:08:39 +0300
Subject: [PATCH 138/151] fix

---
 .../fabric8/{client/discovery => }/Fabric8DiscoveryApp.java     | 2 +-
 .../discovery/Fabric8ReactiveDiscoveryController.java           | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
 rename spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/{client/discovery => }/Fabric8DiscoveryApp.java (92%)
 rename spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/{client => }/discovery/Fabric8ReactiveDiscoveryController.java (96%)

diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/client/discovery/Fabric8DiscoveryApp.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/Fabric8DiscoveryApp.java
similarity index 92%
rename from spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/client/discovery/Fabric8DiscoveryApp.java
rename to spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/Fabric8DiscoveryApp.java
index 1ef7ea1a55..f85591eba3 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/client/discovery/Fabric8DiscoveryApp.java
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/Fabric8DiscoveryApp.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package org.springframework.cloud.kubernetes.fabric8.client.discovery;
+package org.springframework.cloud.kubernetes.fabric8;
 
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/client/discovery/Fabric8ReactiveDiscoveryController.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8ReactiveDiscoveryController.java
similarity index 96%
rename from spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/client/discovery/Fabric8ReactiveDiscoveryController.java
rename to spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8ReactiveDiscoveryController.java
index 4f1a2ae2c6..a6bfe8531f 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/client/discovery/Fabric8ReactiveDiscoveryController.java
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8ReactiveDiscoveryController.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package org.springframework.cloud.kubernetes.fabric8.client.discovery;
+package org.springframework.cloud.kubernetes.fabric8.discovery;
 
 import java.util.List;
 

From 877f18288268cc73ef0551c38b56cfa5b8ac340b Mon Sep 17 00:00:00 2001
From: wind57 
Date: Fri, 13 Oct 2023 22:33:33 +0300
Subject: [PATCH 139/151] checkstyle

---
 .../fabric8/client/discovery/Fabric8DiscoveryController.java    | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/client/discovery/Fabric8DiscoveryController.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/client/discovery/Fabric8DiscoveryController.java
index 363f574423..1b433234fe 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/client/discovery/Fabric8DiscoveryController.java
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/client/discovery/Fabric8DiscoveryController.java
@@ -22,10 +22,10 @@
 
 import org.springframework.beans.factory.ObjectProvider;
 import org.springframework.cloud.client.ServiceInstance;
+import org.springframework.cloud.kubernetes.fabric8.discovery.Fabric8KubernetesDiscoveryClient;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RestController;
-import org.springframework.cloud.kubernetes.fabric8.discovery.Fabric8KubernetesDiscoveryClient;
 
 /**
  * @author wind57

From bdf6114f1f267f94923e1fc9924b3e5e6cdae55d Mon Sep 17 00:00:00 2001
From: wind57 
Date: Sat, 14 Oct 2023 21:54:11 +0200
Subject: [PATCH 140/151] trigger


From cf68b2a4b571383e5df031b351f47981454d7d20 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Tue, 14 Nov 2023 22:28:32 +0200
Subject: [PATCH 141/151] fix issues

---
 .../discovery/SharedInformerFactoryStub.java  |  4 ---
 .../Fabric8KubernetesDiscoveryClient.java     |  4 +--
 ...Fabric8KubernetesDiscoveryClientUtils.java | 29 +++++++++++++++++++
 ...c8KubernetesDiscoveryClientUtilsTests.java | 28 ------------------
 4 files changed, 31 insertions(+), 34 deletions(-)

diff --git a/spring-cloud-kubernetes-client-discovery/src/test/java/org/springframework/cloud/kubernetes/client/discovery/SharedInformerFactoryStub.java b/spring-cloud-kubernetes-client-discovery/src/test/java/org/springframework/cloud/kubernetes/client/discovery/SharedInformerFactoryStub.java
index 60c968be40..cae63d6ece 100644
--- a/spring-cloud-kubernetes-client-discovery/src/test/java/org/springframework/cloud/kubernetes/client/discovery/SharedInformerFactoryStub.java
+++ b/spring-cloud-kubernetes-client-discovery/src/test/java/org/springframework/cloud/kubernetes/client/discovery/SharedInformerFactoryStub.java
@@ -1,9 +1,5 @@
 /*
-<<<<<<< HEAD:spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/EndpointSubsetNS.java
- * Copyright 2012-2023 the original author or authors.
-=======
  * Copyright 2013-2023 the original author or authors.
->>>>>>> main:spring-cloud-kubernetes-client-discovery/src/test/java/org/springframework/cloud/kubernetes/client/discovery/SharedInformerFactoryStub.java
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClient.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClient.java
index 0d3df6a032..c4293939d0 100644
--- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClient.java
+++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClient.java
@@ -166,8 +166,8 @@ private List serviceInstances(Endpoints endpoints, String servi
 
 	@Override
 	public List getServices() {
-		List services = services(properties, client, namespaceProvider, predicate, null, "fabric8 discovery").stream()
-				.map(service -> service.getMetadata().getName()).distinct().toList();
+		List services = services(properties, client, namespaceProvider, predicate, null, "fabric8 discovery")
+				.stream().map(service -> service.getMetadata().getName()).distinct().toList();
 		LOG.debug(() -> "will return services : " + services);
 		return services;
 	}
diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtils.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtils.java
index 5098afd1f1..bf21f2f6be 100644
--- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtils.java
+++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtils.java
@@ -67,6 +67,35 @@ private Fabric8KubernetesDiscoveryClientUtils() {
 
 	}
 
+	static List endpointSlices(KubernetesDiscoveryProperties properties, KubernetesClient client,
+			KubernetesNamespaceProvider namespaceProvider, String target) {
+
+		List endpointSlices;
+
+		if (properties.allNamespaces()) {
+			LOG.debug(() -> "discovering endpoint slices in all namespaces");
+			endpointSlices = filteredEndpointSlices(
+					client.discovery().v1().endpointSlices().inAnyNamespace().withNewFilter(), properties);
+		}
+		else if (!properties.namespaces().isEmpty()) {
+			LOG.debug(() -> "discovering endpoint slices in namespaces : " + properties.namespaces());
+			List inner = new ArrayList<>(properties.namespaces().size());
+			properties.namespaces()
+					.forEach(namespace -> inner.addAll(filteredEndpointSlices(
+							client.discovery().v1().endpointSlices().inNamespace(namespace).withNewFilter(),
+							properties)));
+			endpointSlices = inner;
+		}
+		else {
+			String namespace = Fabric8Utils.getApplicationNamespace(client, null, target, namespaceProvider);
+			LOG.debug(() -> "discovering endpoint slices in namespace : " + namespace);
+			endpointSlices = filteredEndpointSlices(
+					client.discovery().v1().endpointSlices().inNamespace(namespace).withNewFilter(), properties);
+		}
+
+		return endpointSlices;
+	}
+
 	static List endpoints(KubernetesDiscoveryProperties properties, KubernetesClient client,
 			KubernetesNamespaceProvider namespaceProvider, String target, @Nullable String serviceName,
 			Predicate filter) {
diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtilsTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtilsTests.java
index 8032beec8b..a2edcb00a1 100644
--- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtilsTests.java
+++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtilsTests.java
@@ -25,9 +25,6 @@
 import io.fabric8.kubernetes.api.model.EndpointPortBuilder;
 import io.fabric8.kubernetes.api.model.EndpointSubset;
 import io.fabric8.kubernetes.api.model.EndpointSubsetBuilder;
-import io.fabric8.kubernetes.api.model.Endpoints;
-import io.fabric8.kubernetes.api.model.EndpointsBuilder;
-import io.fabric8.kubernetes.api.model.ObjectMetaBuilder;
 import io.fabric8.kubernetes.api.model.Service;
 import io.fabric8.kubernetes.api.model.ServiceBuilder;
 import io.fabric8.kubernetes.api.model.ServiceSpecBuilder;
@@ -60,31 +57,6 @@ void afterEach() {
 		client.services().inAnyNamespace().delete();
 	}
 
-	@Test
-	void testSubsetsFromEndpointsEmptySubsets() {
-		Endpoints endpoints = new EndpointsBuilder()
-				.withMetadata(new ObjectMetaBuilder().withNamespace("non-default").build()).build();
-		EndpointSubsetNS result = Fabric8KubernetesDiscoveryClientUtils.subsetsFromEndpoints(endpoints);
-		Assertions.assertNotNull(result);
-		Assertions.assertEquals(result.endpointSubset(), List.of());
-		Assertions.assertEquals(result.namespace(), "non-default");
-	}
-
-	@Test
-	void testSubsetsFromEndpointsNonEmptySubsets() {
-		Endpoints endpoints = new EndpointsBuilder().withSubsets((List) null)
-				.withMetadata(new ObjectMetaBuilder().withNamespace("default").build())
-				.withSubsets(
-						new EndpointSubsetBuilder().withPorts(new EndpointPortBuilder().withPort(8080).build()).build())
-				.build();
-		EndpointSubsetNS result = Fabric8KubernetesDiscoveryClientUtils.subsetsFromEndpoints(endpoints);
-		Assertions.assertNotNull(result);
-		Assertions.assertEquals(result.endpointSubset().size(), 1);
-		Assertions.assertEquals(result.endpointSubset().get(0).getPorts().get(0).getPort(), 8080);
-		Assertions.assertEquals(result.namespace(), "default");
-
-	}
-
 	/*
 	 * 
 - all-namespaces = true - serviceA present in namespace "A" - serviceB
 	 * present in namespace "B" - no filters are applied, so both are present 
From 288a096f4cb7e168e7ee4cd1cb8ffb64c542daa9 Mon Sep 17 00:00:00 2001 From: wind57 Date: Wed, 15 Nov 2023 10:04:43 +0200 Subject: [PATCH 142/151] fix test --- .../discovery/Fabric8KubernetesCatalogWatchEndpointsTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchEndpointsTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchEndpointsTests.java index 043f51e300..4585bb81c3 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchEndpointsTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchEndpointsTests.java @@ -145,7 +145,7 @@ void testInAllNamespacesWithoutServiceLabels() { void testAllNamespacesTrueOtherBranchesNotCalled() { Fabric8KubernetesCatalogWatch watch = createWatcherInAllNamespacesWithLabels(Map.of("color", "blue"), - Set.of("B"), ENDPOINT_SLICES); + Set.of(), ENDPOINT_SLICES); endpoints("namespaceA", Map.of(), "podA"); endpoints("namespaceA", Map.of("color", "blue"), "podB"); From 43679c8493c79a3c848139ec8f5a4c67ab1b0112 Mon Sep 17 00:00:00 2001 From: wind57 Date: Tue, 16 Jan 2024 22:02:50 +0000 Subject: [PATCH 143/151] merge main --- .../discovery/ConditionalOnBlockingOrReactiveEnabled.java | 1 - 1 file changed, 1 deletion(-) diff --git a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/ConditionalOnBlockingOrReactiveEnabled.java b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/ConditionalOnBlockingOrReactiveEnabled.java index d88e990675..d256ea4cd0 100644 --- a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/ConditionalOnBlockingOrReactiveEnabled.java +++ b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/ConditionalOnBlockingOrReactiveEnabled.java @@ -26,7 +26,6 @@ import org.springframework.boot.autoconfigure.condition.AnyNestedCondition; import org.springframework.cloud.client.ConditionalOnBlockingDiscoveryEnabled; import org.springframework.cloud.client.ConditionalOnReactiveDiscoveryEnabled; -import org.springframework.cloud.kubernetes.commons.discovery.ConditionalOnBlockingOrReactiveDiscoveryEnabled; import org.springframework.context.annotation.Conditional; /** From 6dcd5d6feb020724a7cfcfdc463fbfadd6ba80a2 Mon Sep 17 00:00:00 2001 From: wind57 Date: Sun, 4 Feb 2024 10:54:12 +0200 Subject: [PATCH 144/151] fix compilation --- .../discovery/Fabric8ConfigServerBootstrapper.java | 10 +++++----- ...gWatchAutoConfigurationApplicationContextTests.java | 3 ++- .../Fabric8KubernetesCatalogWatchEndpointsTests.java | 4 ++-- ...etesDiscoveryClientServiceWithoutPortNameTests.java | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8ConfigServerBootstrapper.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8ConfigServerBootstrapper.java index 8bb92e15c7..76d11c2c5e 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8ConfigServerBootstrapper.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8ConfigServerBootstrapper.java @@ -69,14 +69,14 @@ public void initialize(BootstrapRegistry registry) { PropertyResolver propertyResolver = getPropertyResolver(context); Fabric8AutoConfiguration fabric8AutoConfiguration = new Fabric8AutoConfiguration(); Config config = fabric8AutoConfiguration - .kubernetesClientConfig(context.get(KubernetesClientProperties.class)); + .kubernetesClientConfig(context.get(KubernetesClientProperties.class)); KubernetesClient kubernetesClient = fabric8AutoConfiguration.kubernetesClient(config); KubernetesDiscoveryProperties discoveryProperties = context.get(KubernetesDiscoveryProperties.class); Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient( - kubernetesClient, discoveryProperties, new ServicePortSecureResolver(discoveryProperties), - new KubernetesNamespaceProvider(propertyResolver - .get(KubernetesNamespaceProvider.NAMESPACE_PROPERTY, String.class, null)), - new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(discoveryProperties)); + kubernetesClient, discoveryProperties, new ServicePortSecureResolver(discoveryProperties), + new KubernetesNamespaceProvider(propertyResolver + .get(KubernetesNamespaceProvider.NAMESPACE_PROPERTY, String.class, null)), + new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(discoveryProperties)); return discoveryClient::getInstances; } }); diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchAutoConfigurationApplicationContextTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchAutoConfigurationApplicationContextTests.java index 1db92681df..0d10def057 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchAutoConfigurationApplicationContextTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchAutoConfigurationApplicationContextTests.java @@ -66,7 +66,8 @@ void kubernetesDiscoveryEnabled() { void kubernetesDiscoveryDisabled() { setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", "spring.cloud.kubernetes.discovery.enabled=false"); - applicationContextRunner.run(context -> assertThat(context).doesNotHaveBean(Fabric8KubernetesCatalogWatch.class)); + applicationContextRunner + .run(context -> assertThat(context).doesNotHaveBean(Fabric8KubernetesCatalogWatch.class)); } /** diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchEndpointsTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchEndpointsTests.java index 4585bb81c3..c966d4ac61 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchEndpointsTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchEndpointsTests.java @@ -144,8 +144,8 @@ void testInAllNamespacesWithoutServiceLabels() { @Override void testAllNamespacesTrueOtherBranchesNotCalled() { - Fabric8KubernetesCatalogWatch watch = createWatcherInAllNamespacesWithLabels(Map.of("color", "blue"), - Set.of(), ENDPOINT_SLICES); + Fabric8KubernetesCatalogWatch watch = createWatcherInAllNamespacesWithLabels(Map.of("color", "blue"), Set.of(), + ENDPOINT_SLICES); endpoints("namespaceA", Map.of(), "podA"); endpoints("namespaceA", Map.of("color", "blue"), "podB"); diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientServiceWithoutPortNameTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientServiceWithoutPortNameTests.java index 2971d5db0a..0541a09d44 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientServiceWithoutPortNameTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientServiceWithoutPortNameTests.java @@ -70,7 +70,7 @@ void testDiscoveryWithoutAServicePortName() { true, 60, false, null, Set.of(), Map.of(), null, KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, true); Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, properties, - new ServicePortSecureResolver(properties), new KubernetesNamespaceProvider(null), a -> true); + new ServicePortSecureResolver(properties), new KubernetesNamespaceProvider((String) null), a -> true); List serviceInstances = discoveryClient.getInstances("no-port-name-service"); Assertions.assertEquals(serviceInstances.size(), 1); From ada0d26380afa009aa823bccddd56e76bb6c629a Mon Sep 17 00:00:00 2001 From: wind57 Date: Sun, 4 Feb 2024 11:38:56 +0200 Subject: [PATCH 145/151] fix test --- ...tesCatalogWatchAutoConfigurationApplicationContextTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchAutoConfigurationApplicationContextTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchAutoConfigurationApplicationContextTests.java index 0d10def057..626f7b8eef 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchAutoConfigurationApplicationContextTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchAutoConfigurationApplicationContextTests.java @@ -78,7 +78,7 @@ void disableBlockingAndReactive() { setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", "spring.cloud.discovery.blocking.enabled=false", "spring.cloud.discovery.reactive.enabled=false"); applicationContextRunner.run(context -> { - assertThat(context).hasSingleBean(Fabric8KubernetesCatalogWatch.class); + assertThat(context).doesNotHaveBean(Fabric8KubernetesCatalogWatch.class); assertThat(context).doesNotHaveBean(Fabric8KubernetesDiscoveryClient.class); assertThat(context).doesNotHaveBean(Fabric8KubernetesReactiveDiscoveryClient.class); }); From 78834cdd7a9bebef341c6c1c2d3b35d3587290ac Mon Sep 17 00:00:00 2001 From: wind57 Date: Sat, 9 Mar 2024 14:08:38 +0200 Subject: [PATCH 146/151] placeholder commit From 2f3c5b7fc9b8834943f7c27525b725e97995f2e5 Mon Sep 17 00:00:00 2001 From: wind57 Date: Sun, 31 Mar 2024 10:26:39 +0300 Subject: [PATCH 147/151] fix test --- .../loadbalancer/Fabric8ServiceInstanceMapperTests.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-cloud-kubernetes-fabric8-loadbalancer/src/test/java/org/springframework/cloud/kubernetes/fabric8/loadbalancer/Fabric8ServiceInstanceMapperTests.java b/spring-cloud-kubernetes-fabric8-loadbalancer/src/test/java/org/springframework/cloud/kubernetes/fabric8/loadbalancer/Fabric8ServiceInstanceMapperTests.java index 7ebb9064e6..4f1d193ba0 100644 --- a/spring-cloud-kubernetes-fabric8-loadbalancer/src/test/java/org/springframework/cloud/kubernetes/fabric8/loadbalancer/Fabric8ServiceInstanceMapperTests.java +++ b/spring-cloud-kubernetes-fabric8-loadbalancer/src/test/java/org/springframework/cloud/kubernetes/fabric8/loadbalancer/Fabric8ServiceInstanceMapperTests.java @@ -83,8 +83,8 @@ void testMapperSecure() { void testMapperSecureNullLabelsAndAnnotations() { KubernetesLoadBalancerProperties properties = new KubernetesLoadBalancerProperties(); KubernetesDiscoveryProperties discoveryProperties = new KubernetesDiscoveryProperties(true, true, Set.of(), - true, 60, false, null, Set.of(), Map.of(), null, KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, - false, false); + true, 60, false, null, Set.of(443, 8443), Map.of(), null, + KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, false, false); List ports = new ArrayList<>(); ports.add(new ServicePortBuilder().withPort(443).build()); Service service = buildService("test", "test-namespace", "abc", ports, null, null); From 7b7b8b6c67d8fd90d203ad6ad0983e2ba2a03e31 Mon Sep 17 00:00:00 2001 From: wind57 Date: Thu, 18 Apr 2024 16:45:38 +0300 Subject: [PATCH 148/151] cleanup --- ...onditionalOnBlockingOrReactiveEnabled.java | 65 ------------------- ...overyClientPredicateAutoConfiguration.java | 4 +- .../Fabric8KubernetesCatalogWatch.java | 2 +- ...netesDiscoveryClientAutoConfiguration.java | 2 +- ...ctiveDiscoveryClientAutoConfiguration.java | 2 +- ...esDiscoveryClientAddressesUtilsTests.java} | 2 +- 6 files changed, 6 insertions(+), 71 deletions(-) delete mode 100644 spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/ConditionalOnBlockingOrReactiveEnabled.java rename spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/{KubernetesDiscoveryClientUtilsTests.java => Fabric8KubernetesDiscoveryClientAddressesUtilsTests.java} (98%) diff --git a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/ConditionalOnBlockingOrReactiveEnabled.java b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/ConditionalOnBlockingOrReactiveEnabled.java deleted file mode 100644 index d256ea4cd0..0000000000 --- a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/ConditionalOnBlockingOrReactiveEnabled.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2013-2023 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.commons.discovery; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Inherited; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import org.springframework.boot.autoconfigure.condition.AnyNestedCondition; -import org.springframework.cloud.client.ConditionalOnBlockingDiscoveryEnabled; -import org.springframework.cloud.client.ConditionalOnReactiveDiscoveryEnabled; -import org.springframework.context.annotation.Conditional; - -/** - * Conditional that is resolved to active when either - * {@link ConditionalOnBlockingDiscoveryEnabled} or - * {@link ConditionalOnReactiveDiscoveryEnabled} matches. - * @deprecated in favor of {@link ConditionalOnBlockingOrReactiveDiscoveryEnabled} - * - * @author wind57 - */ -@Target({ ElementType.TYPE, ElementType.METHOD }) -@Retention(RetentionPolicy.RUNTIME) -@Documented -@Inherited -@Conditional(ConditionalOnBlockingOrReactiveEnabled.OnBlockingOrReactiveEnabled.class) -@Deprecated(forRemoval = true) -public @interface ConditionalOnBlockingOrReactiveEnabled { - - class OnBlockingOrReactiveEnabled extends AnyNestedCondition { - - OnBlockingOrReactiveEnabled() { - super(ConfigurationPhase.REGISTER_BEAN); - } - - @ConditionalOnBlockingDiscoveryEnabled - static class OnBlockingEnabled { - - } - - @ConditionalOnReactiveDiscoveryEnabled - static class OnReactiveEnabled { - - } - - } - -} diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryClientPredicateAutoConfiguration.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryClientPredicateAutoConfiguration.java index 5d7182eb6f..2c94841701 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryClientPredicateAutoConfiguration.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryClientPredicateAutoConfiguration.java @@ -26,7 +26,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.cloud.CloudPlatform; import org.springframework.cloud.client.ConditionalOnDiscoveryEnabled; -import org.springframework.cloud.kubernetes.commons.discovery.ConditionalOnBlockingOrReactiveEnabled; +import org.springframework.cloud.kubernetes.commons.discovery.ConditionalOnBlockingOrReactiveDiscoveryEnabled; import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryPropertiesAutoConfiguration; import org.springframework.context.annotation.Bean; @@ -40,7 +40,7 @@ */ @Configuration(proxyBeanMethods = false) @ConditionalOnDiscoveryEnabled -@ConditionalOnBlockingOrReactiveEnabled +@ConditionalOnBlockingOrReactiveDiscoveryEnabled @ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES) @AutoConfigureAfter(KubernetesDiscoveryPropertiesAutoConfiguration.class) class Fabric8DiscoveryClientPredicateAutoConfiguration { diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatch.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatch.java index 580a680aa6..3b323fc678 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatch.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatch.java @@ -68,7 +68,7 @@ public void setApplicationEventPublisher(ApplicationEventPublisher publisher) { } @Scheduled(fixedDelayString = "${" + CATALOG_WATCH_PROPERTY_WITH_DEFAULT_VALUE + "}") - public void catalogServicesWatch() { + void catalogServicesWatch() { try { List currentState = stateGenerator.apply(context); diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAutoConfiguration.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAutoConfiguration.java index 5f3943656a..6437ea18bd 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAutoConfiguration.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAutoConfiguration.java @@ -70,7 +70,7 @@ Fabric8KubernetesDiscoveryClient kubernetesDiscoveryClient(KubernetesClient clie @Bean @ConditionalOnSpringCloudKubernetesBlockingDiscoveryHealthInitializer - public KubernetesDiscoveryClientHealthIndicatorInitializer indicatorInitializer( + KubernetesDiscoveryClientHealthIndicatorInitializer indicatorInitializer( ApplicationEventPublisher applicationEventPublisher, PodUtils podUtils) { LOG.debug(() -> "Will publish InstanceRegisteredEvent from blocking implementation"); return new KubernetesDiscoveryClientHealthIndicatorInitializer(podUtils, applicationEventPublisher); diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientAutoConfiguration.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientAutoConfiguration.java index 6a82589261..5b11befd76 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientAutoConfiguration.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientAutoConfiguration.java @@ -88,7 +88,7 @@ KubernetesDiscoveryClientHealthIndicatorInitializer reactiveIndicatorInitializer @Bean @ConditionalOnSpringCloudKubernetesReactiveDiscoveryHealthInitializer - public ReactiveDiscoveryClientHealthIndicator kubernetesReactiveDiscoveryClientHealthIndicator( + ReactiveDiscoveryClientHealthIndicator kubernetesReactiveDiscoveryClientHealthIndicator( Fabric8KubernetesReactiveDiscoveryClient client, DiscoveryClientHealthIndicatorProperties properties) { return new ReactiveDiscoveryClientHealthIndicator(client, properties); } diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAddressesUtilsTests.java similarity index 98% rename from spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java rename to spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAddressesUtilsTests.java index f7abe74f7c..9798ab5c27 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesDiscoveryClientUtilsTests.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAddressesUtilsTests.java @@ -32,7 +32,7 @@ /** * @author wind57 */ -class KubernetesDiscoveryClientUtilsTests { +class Fabric8KubernetesDiscoveryClientAddressesUtilsTests { /** *

From a3197b49b3f4c53f83353f23b9b70232646a0a93 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Fri, 6 Sep 2024 09:20:22 +0300
Subject: [PATCH 149/151] formatting

---
 .../Fabric8ConfigServerBootstrapper.java      |   2 +-
 ...overyClientPredicateAutoConfiguration.java |   3 +-
 .../Fabric8DiscoveryServicesAdapter.java      | 106 ------------------
 .../Fabric8KubernetesDiscoveryClient.java     |   5 +-
 ...Fabric8KubernetesDiscoveryClientUtils.java |   7 +-
 ...ric8KubernetesReactiveDiscoveryClient.java |   4 +-
 ...CatalogServicesWatchConfigurationTest.java |   6 +-
 ...oConfigurationApplicationContextTests.java |  14 +--
 ...oConfigurationApplicationContextTests.java |  21 ++--
 ...lientAutoConfigurationPropertiesTests.java |   6 +-
 ...DiscoveryClientAutoConfigurationTests.java |   2 +-
 ...c8KubernetesDiscoveryClientFilterTest.java |   4 +-
 ...c8KubernetesDiscoveryClientUtilsTests.java |  20 ++--
 ...oConfigurationApplicationContextTests.java |  91 +++++++--------
 ...DiscoveryClientAutoConfigurationTests.java |  31 ++---
 ...ubernetesReactiveDiscoveryClientTests.java |  29 ++++-
 16 files changed, 137 insertions(+), 214 deletions(-)
 delete mode 100644 spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryServicesAdapter.java

diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8ConfigServerBootstrapper.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8ConfigServerBootstrapper.java
index 76e9c30fb9..67b5314b8f 100644
--- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8ConfigServerBootstrapper.java
+++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8ConfigServerBootstrapper.java
@@ -75,7 +75,7 @@ public void initialize(BootstrapRegistry registry) {
 				Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(
 						kubernetesClient, discoveryProperties, new ServicePortSecureResolver(discoveryProperties),
 						new KubernetesNamespaceProvider(propertyResolver
-								.get(KubernetesNamespaceProvider.NAMESPACE_PROPERTY, String.class, null)),
+							.get(KubernetesNamespaceProvider.NAMESPACE_PROPERTY, String.class, null)),
 						new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(discoveryProperties));
 				return discoveryClient::getInstances;
 			}
diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryClientPredicateAutoConfiguration.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryClientPredicateAutoConfiguration.java
index 2c94841701..a9bf4a463c 100644
--- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryClientPredicateAutoConfiguration.java
+++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryClientPredicateAutoConfiguration.java
@@ -50,7 +50,8 @@ class Fabric8DiscoveryClientPredicateAutoConfiguration {
 	Predicate predicate(KubernetesDiscoveryProperties properties) {
 		SpelExpressionParser parser = new SpelExpressionParser();
 		SimpleEvaluationContext evaluationContext = SimpleEvaluationContext.forReadOnlyDataBinding()
-				.withInstanceMethods().build();
+			.withInstanceMethods()
+			.build();
 
 		String spelExpression = properties.filter();
 		Predicate predicate;
diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryServicesAdapter.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryServicesAdapter.java
deleted file mode 100644
index 25bd6a2ef7..0000000000
--- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryServicesAdapter.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Copyright 2012-2022 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.discovery;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Optional;
-import java.util.function.Function;
-import java.util.function.Predicate;
-
-import io.fabric8.kubernetes.api.model.Service;
-import io.fabric8.kubernetes.client.KubernetesClient;
-import org.apache.commons.logging.LogFactory;
-
-import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
-import org.springframework.core.log.LogAccessor;
-import org.springframework.expression.Expression;
-import org.springframework.expression.spel.standard.SpelExpressionParser;
-import org.springframework.expression.spel.support.SimpleEvaluationContext;
-
-/**
- * Adapts a {@link KubernetesClientServicesFunction} to a Function that takes a
- * KubernetesClient as input and returns a List of Services(s), plus adds functionality
- * not supported by it.
- *
- * @author wind57
- */
-final class Fabric8DiscoveryServicesAdapter implements Function> {
-
-	private static final LogAccessor LOG = new LogAccessor(LogFactory.getLog(Fabric8DiscoveryServicesAdapter.class));
-
-	private static final SpelExpressionParser PARSER = new SpelExpressionParser();
-
-	private static final SimpleEvaluationContext EVALUATION_CONTEXT = SimpleEvaluationContext.forReadOnlyDataBinding()
-		.withInstanceMethods()
-		.build();
-
-	private final KubernetesClientServicesFunction function;
-
-	private final KubernetesDiscoveryProperties properties;
-
-	private final Predicate filter;
-
-	Fabric8DiscoveryServicesAdapter(KubernetesClientServicesFunction function, KubernetesDiscoveryProperties properties,
-			Predicate filter) {
-		this.function = function;
-		this.properties = properties;
-		if (filter == null) {
-			this.filter = filter();
-		}
-		else {
-			this.filter = filter;
-		}
-	}
-
-	@Override
-	public List apply(KubernetesClient client) {
-		if (!properties.namespaces().isEmpty()) {
-			LOG.debug(() -> "searching in namespaces : " + properties.namespaces() + " with filter : "
-					+ properties.filter());
-			List services = new ArrayList<>();
-			properties.namespaces()
-				.forEach(namespace -> services.addAll(client.services()
-					.inNamespace(namespace)
-					.withLabels(properties.serviceLabels())
-					.list()
-					.getItems()
-					.stream()
-					.filter(filter)
-					.toList()));
-			return services;
-		}
-		return function.apply(client).list().getItems().stream().filter(filter).toList();
-	}
-
-	Predicate filter() {
-		String spelExpression = properties.filter();
-		Predicate predicate;
-		if (spelExpression == null || spelExpression.isEmpty()) {
-			predicate = service -> true;
-		}
-		else {
-			Expression filterExpr = PARSER.parseExpression(spelExpression);
-			predicate = service -> {
-				Boolean include = filterExpr.getValue(EVALUATION_CONTEXT, service, Boolean.class);
-				return Optional.ofNullable(include).orElse(false);
-			};
-		}
-		return predicate;
-	}
-
-}
diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClient.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClient.java
index 8cb70e4e44..df5b5e6aec 100644
--- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClient.java
+++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClient.java
@@ -167,7 +167,10 @@ private List serviceInstances(Endpoints endpoints, String servi
 	@Override
 	public List getServices() {
 		List services = services(properties, client, namespaceProvider, predicate, null, "fabric8 discovery")
-				.stream().map(service -> service.getMetadata().getName()).distinct().toList();
+			.stream()
+			.map(service -> service.getMetadata().getName())
+			.distinct()
+			.toList();
 		LOG.debug(() -> "will return services : " + services);
 		return services;
 	}
diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtils.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtils.java
index 8daa2eca8c..e5e4f09255 100644
--- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtils.java
+++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtils.java
@@ -78,9 +78,8 @@ else if (!properties.namespaces().isEmpty()) {
 			LOG.debug(() -> "discovering endpoint slices in namespaces : " + properties.namespaces());
 			List inner = new ArrayList<>(properties.namespaces().size());
 			properties.namespaces()
-					.forEach(namespace -> inner.addAll(filteredEndpointSlices(
-							client.discovery().v1().endpointSlices().inNamespace(namespace).withNewFilter(),
-							properties)));
+				.forEach(namespace -> inner.addAll(filteredEndpointSlices(
+						client.discovery().v1().endpointSlices().inNamespace(namespace).withNewFilter(), properties)));
 			endpointSlices = inner;
 		}
 		else {
@@ -262,7 +261,7 @@ private static List filteredEndpointSlices(
 			KubernetesDiscoveryProperties properties) {
 
 		FilterNested>> partial = filterNested
-				.withLabels(properties.serviceLabels());
+			.withLabels(properties.serviceLabels());
 
 		return partial.endFilter().list().getItems();
 
diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClient.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClient.java
index 12a59751bb..0e7c1e21bb 100644
--- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClient.java
+++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClient.java
@@ -46,13 +46,13 @@ public String description() {
 	public Flux getInstances(String serviceId) {
 		Assert.notNull(serviceId, "[Assertion failed] - the object argument must not be null");
 		return Flux.defer(() -> Flux.fromIterable(fabric8KubernetesDiscoveryClient.getInstances(serviceId)))
-				.subscribeOn(Schedulers.boundedElastic());
+			.subscribeOn(Schedulers.boundedElastic());
 	}
 
 	@Override
 	public Flux getServices() {
 		return Flux.defer(() -> Flux.fromIterable(fabric8KubernetesDiscoveryClient.getServices()))
-				.subscribeOn(Schedulers.boundedElastic());
+			.subscribeOn(Schedulers.boundedElastic());
 	}
 
 }
diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogServicesWatchConfigurationTest.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogServicesWatchConfigurationTest.java
index 755ea25a43..4e0baf267e 100644
--- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogServicesWatchConfigurationTest.java
+++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogServicesWatchConfigurationTest.java
@@ -84,8 +84,10 @@ private void setup(String... env) {
 				KubernetesClientTestConfiguration.class, Fabric8KubernetesCatalogWatchAutoConfiguration.class,
 				Fabric8KubernetesDiscoveryClientAutoConfiguration.class,
 				KubernetesDiscoveryPropertiesAutoConfiguration.class,
-				Fabric8DiscoveryClientPredicateAutoConfiguration.class).web(WebApplicationType.NONE)
-						.properties(envList.toArray(new String[0])).run();
+				Fabric8DiscoveryClientPredicateAutoConfiguration.class)
+			.web(WebApplicationType.NONE)
+			.properties(envList.toArray(new String[0]))
+			.run();
 	}
 
 	@Configuration(proxyBeanMethods = false)
diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchAutoConfigurationApplicationContextTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchAutoConfigurationApplicationContextTests.java
index 626f7b8eef..7dee7c2d3b 100644
--- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchAutoConfigurationApplicationContextTests.java
+++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchAutoConfigurationApplicationContextTests.java
@@ -51,7 +51,7 @@ void discoveryDisabled() {
 		setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false",
 				"spring.cloud.discovery.enabled=false");
 		applicationContextRunner
-				.run(context -> assertThat(context).doesNotHaveBean(Fabric8KubernetesCatalogWatch.class));
+			.run(context -> assertThat(context).doesNotHaveBean(Fabric8KubernetesCatalogWatch.class));
 	}
 
 	@Test
@@ -67,7 +67,7 @@ void kubernetesDiscoveryDisabled() {
 		setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false",
 				"spring.cloud.kubernetes.discovery.enabled=false");
 		applicationContextRunner
-				.run(context -> assertThat(context).doesNotHaveBean(Fabric8KubernetesCatalogWatch.class));
+			.run(context -> assertThat(context).doesNotHaveBean(Fabric8KubernetesCatalogWatch.class));
 	}
 
 	/**
@@ -129,11 +129,11 @@ void disableKubernetesDiscovery() {
 
 	private void setup(String... properties) {
 		applicationContextRunner = new ApplicationContextRunner()
-				.withConfiguration(AutoConfigurations.of(Fabric8KubernetesCatalogWatchAutoConfiguration.class,
-						Fabric8AutoConfiguration.class, KubernetesCommonsAutoConfiguration.class,
-						KubernetesDiscoveryPropertiesAutoConfiguration.class,
-						Fabric8DiscoveryClientPredicateAutoConfiguration.class))
-				.withPropertyValues(properties);
+			.withConfiguration(AutoConfigurations.of(Fabric8KubernetesCatalogWatchAutoConfiguration.class,
+					Fabric8AutoConfiguration.class, KubernetesCommonsAutoConfiguration.class,
+					KubernetesDiscoveryPropertiesAutoConfiguration.class,
+					Fabric8DiscoveryClientPredicateAutoConfiguration.class))
+			.withPropertyValues(properties);
 	}
 
 }
diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAutoConfigurationApplicationContextTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAutoConfigurationApplicationContextTests.java
index 6afb639dd9..5f27413e92 100644
--- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAutoConfigurationApplicationContextTests.java
+++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAutoConfigurationApplicationContextTests.java
@@ -152,20 +152,21 @@ void reactiveDisabled() {
 
 	private void setup(String... properties) {
 		applicationContextRunner = new ApplicationContextRunner()
-				.withConfiguration(AutoConfigurations.of(Fabric8KubernetesDiscoveryClientAutoConfiguration.class,
-						Fabric8AutoConfiguration.class, KubernetesCommonsAutoConfiguration.class,
-						KubernetesDiscoveryPropertiesAutoConfiguration.class,
-						Fabric8DiscoveryClientPredicateAutoConfiguration.class))
-				.withPropertyValues(properties);
+			.withConfiguration(AutoConfigurations.of(Fabric8KubernetesDiscoveryClientAutoConfiguration.class,
+					Fabric8AutoConfiguration.class, KubernetesCommonsAutoConfiguration.class,
+					KubernetesDiscoveryPropertiesAutoConfiguration.class,
+					Fabric8DiscoveryClientPredicateAutoConfiguration.class))
+			.withPropertyValues(properties);
 	}
 
 	private void setupWithFilteredClassLoader(Class cls, String... properties) {
 		applicationContextRunner = new ApplicationContextRunner()
-				.withConfiguration(AutoConfigurations.of(Fabric8KubernetesDiscoveryClientAutoConfiguration.class,
-						Fabric8AutoConfiguration.class, KubernetesCommonsAutoConfiguration.class,
-						KubernetesDiscoveryPropertiesAutoConfiguration.class,
-						Fabric8DiscoveryClientPredicateAutoConfiguration.class))
-				.withClassLoader(new FilteredClassLoader(cls)).withPropertyValues(properties);
+			.withConfiguration(AutoConfigurations.of(Fabric8KubernetesDiscoveryClientAutoConfiguration.class,
+					Fabric8AutoConfiguration.class, KubernetesCommonsAutoConfiguration.class,
+					KubernetesDiscoveryPropertiesAutoConfiguration.class,
+					Fabric8DiscoveryClientPredicateAutoConfiguration.class))
+			.withClassLoader(new FilteredClassLoader(cls))
+			.withPropertyValues(properties);
 	}
 
 }
diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAutoConfigurationPropertiesTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAutoConfigurationPropertiesTests.java
index 2fe7368933..f951f6f732 100644
--- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAutoConfigurationPropertiesTests.java
+++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAutoConfigurationPropertiesTests.java
@@ -84,8 +84,10 @@ private void setup(String... env) {
 		context = new SpringApplicationBuilder(PropertyPlaceholderAutoConfiguration.class,
 				KubernetesClientTestConfiguration.class, Fabric8KubernetesDiscoveryClientAutoConfiguration.class,
 				KubernetesDiscoveryPropertiesAutoConfiguration.class,
-				Fabric8DiscoveryClientPredicateAutoConfiguration.class).web(WebApplicationType.NONE)
-						.properties(envList.toArray(new String[0])).run();
+				Fabric8DiscoveryClientPredicateAutoConfiguration.class)
+			.web(WebApplicationType.NONE)
+			.properties(envList.toArray(new String[0]))
+			.run();
 	}
 
 	@Configuration(proxyBeanMethods = false)
diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAutoConfigurationTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAutoConfigurationTests.java
index 980d2b78b3..4de1233d6d 100644
--- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAutoConfigurationTests.java
+++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAutoConfigurationTests.java
@@ -41,7 +41,7 @@ void kubernetesDiscoveryClientCreated() {
 		CompositeDiscoveryClient composite = (CompositeDiscoveryClient) this.discoveryClient;
 		assertThat(
 				composite.getDiscoveryClients().stream().anyMatch(dc -> dc instanceof Fabric8KubernetesDiscoveryClient))
-						.isTrue();
+			.isTrue();
 	}
 
 	@SpringBootApplication
diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientFilterTest.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientFilterTest.java
index e8830b97bd..71a2218215 100644
--- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientFilterTest.java
+++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientFilterTest.java
@@ -57,10 +57,10 @@ class Fabric8KubernetesDiscoveryClientFilterTest {
 		.mock(MixedOperation.class);
 
 	private final FilterNested>> filterNested = Mockito
-			.mock(FilterNested.class);
+		.mock(FilterNested.class);
 
 	private final FilterWatchListDeletable> filter = Mockito
-			.mock(FilterWatchListDeletable.class);
+		.mock(FilterWatchListDeletable.class);
 
 	@Test
 	void testFilteredServices() {
diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtilsTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtilsTests.java
index 031579d6ac..140bf773c2 100644
--- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtilsTests.java
+++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientUtilsTests.java
@@ -122,9 +122,9 @@ void testReadyAddressesOnly() {
 		KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L,
 				includeNotReadyAddresses, "", Set.of(), Map.of(), "", null, 0, false, false);
 		EndpointSubset endpointSubset = new EndpointSubsetBuilder()
-				.withAddresses(new EndpointAddressBuilder().withHostname("one").build(),
-						new EndpointAddressBuilder().withHostname("two").build())
-				.build();
+			.withAddresses(new EndpointAddressBuilder().withHostname("one").build(),
+					new EndpointAddressBuilder().withHostname("two").build())
+			.build();
 		List addresses = Fabric8KubernetesDiscoveryClientUtils.addresses(endpointSubset, properties);
 		Assertions.assertEquals(addresses.size(), 2);
 	}
@@ -141,9 +141,10 @@ void testReadyAddressesTakenNotReadyAddressesNotTaken() {
 		KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L,
 				includeNotReadyAddresses, "", Set.of(), Map.of(), "", null, 0, false, false);
 		EndpointSubset endpointSubset = new EndpointSubsetBuilder()
-				.withAddresses(new EndpointAddressBuilder().withHostname("one").build(),
-						new EndpointAddressBuilder().withHostname("two").build())
-				.withNotReadyAddresses(new EndpointAddressBuilder().withHostname("three").build()).build();
+			.withAddresses(new EndpointAddressBuilder().withHostname("one").build(),
+					new EndpointAddressBuilder().withHostname("two").build())
+			.withNotReadyAddresses(new EndpointAddressBuilder().withHostname("three").build())
+			.build();
 		List addresses = Fabric8KubernetesDiscoveryClientUtils.addresses(endpointSubset, properties);
 		Assertions.assertEquals(addresses.size(), 2);
 		List hostNames = addresses.stream().map(EndpointAddress::getHostname).sorted().toList();
@@ -162,9 +163,10 @@ void testBothAddressesTaken() {
 		KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L,
 				includeNotReadyAddresses, "", Set.of(), Map.of(), "", null, 0, false, false);
 		EndpointSubset endpointSubset = new EndpointSubsetBuilder()
-				.withAddresses(new EndpointAddressBuilder().withHostname("one").build(),
-						new EndpointAddressBuilder().withHostname("two").build())
-				.withNotReadyAddresses(new EndpointAddressBuilder().withHostname("three").build()).build();
+			.withAddresses(new EndpointAddressBuilder().withHostname("one").build(),
+					new EndpointAddressBuilder().withHostname("two").build())
+			.withNotReadyAddresses(new EndpointAddressBuilder().withHostname("three").build())
+			.build();
 		List addresses = Fabric8KubernetesDiscoveryClientUtils.addresses(endpointSubset, properties);
 		Assertions.assertEquals(addresses.size(), 3);
 		List hostNames = addresses.stream().map(EndpointAddress::getHostname).sorted().toList();
diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientAutoConfigurationApplicationContextTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientAutoConfigurationApplicationContextTests.java
index 7db6f91244..1c690c2a92 100644
--- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientAutoConfigurationApplicationContextTests.java
+++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientAutoConfigurationApplicationContextTests.java
@@ -44,11 +44,11 @@ class Fabric8KubernetesReactiveDiscoveryClientAutoConfigurationApplicationContex
 	void discoveryEnabledDefault() {
 		setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false");
 		applicationContextRunner
-				.withConfiguration(AutoConfigurations.of(Fabric8DiscoveryClientPredicateAutoConfiguration.class))
-				.run(context -> {
-					assertThat(context).hasSingleBean(Fabric8KubernetesReactiveDiscoveryClient.class);
-					assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class);
-				});
+			.withConfiguration(AutoConfigurations.of(Fabric8DiscoveryClientPredicateAutoConfiguration.class))
+			.run(context -> {
+				assertThat(context).hasSingleBean(Fabric8KubernetesReactiveDiscoveryClient.class);
+				assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class);
+			});
 	}
 
 	@Test
@@ -56,11 +56,11 @@ void discoveryEnabled() {
 		setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false",
 				"spring.cloud.discovery.enabled=true");
 		applicationContextRunner
-				.withConfiguration(AutoConfigurations.of(Fabric8DiscoveryClientPredicateAutoConfiguration.class))
-				.run(context -> {
-					assertThat(context).hasSingleBean(Fabric8KubernetesReactiveDiscoveryClient.class);
-					assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class);
-				});
+			.withConfiguration(AutoConfigurations.of(Fabric8DiscoveryClientPredicateAutoConfiguration.class))
+			.run(context -> {
+				assertThat(context).hasSingleBean(Fabric8KubernetesReactiveDiscoveryClient.class);
+				assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class);
+			});
 	}
 
 	@Test
@@ -78,11 +78,11 @@ void kubernetesDiscoveryEnabled() {
 		setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false",
 				"spring.cloud.kubernetes.discovery.enabled=true");
 		applicationContextRunner
-				.withConfiguration(AutoConfigurations.of(Fabric8DiscoveryClientPredicateAutoConfiguration.class))
-				.run(context -> {
-					assertThat(context).hasSingleBean(Fabric8KubernetesReactiveDiscoveryClient.class);
-					assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class);
-				});
+			.withConfiguration(AutoConfigurations.of(Fabric8DiscoveryClientPredicateAutoConfiguration.class))
+			.run(context -> {
+				assertThat(context).hasSingleBean(Fabric8KubernetesReactiveDiscoveryClient.class);
+				assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class);
+			});
 	}
 
 	@Test
@@ -100,11 +100,11 @@ void kubernetesReactiveDiscoveryEnabled() {
 		setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false",
 				"spring.cloud.discovery.reactive.enabled=true");
 		applicationContextRunner
-				.withConfiguration(AutoConfigurations.of(Fabric8DiscoveryClientPredicateAutoConfiguration.class))
-				.run(context -> {
-					assertThat(context).hasSingleBean(Fabric8KubernetesReactiveDiscoveryClient.class);
-					assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class);
-				});
+			.withConfiguration(AutoConfigurations.of(Fabric8DiscoveryClientPredicateAutoConfiguration.class))
+			.run(context -> {
+				assertThat(context).hasSingleBean(Fabric8KubernetesReactiveDiscoveryClient.class);
+				assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class);
+			});
 	}
 
 	@Test
@@ -125,11 +125,11 @@ void blockingDisabled() {
 		setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false",
 				"spring.cloud.discovery.blocking.enabled=false");
 		applicationContextRunner
-				.withConfiguration(AutoConfigurations.of(Fabric8DiscoveryClientPredicateAutoConfiguration.class))
-				.run(context -> {
-					assertThat(context).hasSingleBean(Fabric8KubernetesReactiveDiscoveryClient.class);
-					assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class);
-				});
+			.withConfiguration(AutoConfigurations.of(Fabric8DiscoveryClientPredicateAutoConfiguration.class))
+			.run(context -> {
+				assertThat(context).hasSingleBean(Fabric8KubernetesReactiveDiscoveryClient.class);
+				assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class);
+			});
 	}
 
 	@Test
@@ -137,11 +137,11 @@ void healthDisabled() {
 		setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false",
 				"spring.cloud.discovery.client.health-indicator.enabled=false");
 		applicationContextRunner
-				.withConfiguration(AutoConfigurations.of(Fabric8DiscoveryClientPredicateAutoConfiguration.class))
-				.run(context -> {
-					assertThat(context).hasSingleBean(Fabric8KubernetesReactiveDiscoveryClient.class);
-					assertThat(context).doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class);
-				});
+			.withConfiguration(AutoConfigurations.of(Fabric8DiscoveryClientPredicateAutoConfiguration.class))
+			.run(context -> {
+				assertThat(context).hasSingleBean(Fabric8KubernetesReactiveDiscoveryClient.class);
+				assertThat(context).doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class);
+			});
 	}
 
 	@Test
@@ -150,29 +150,30 @@ void healthEnabledClassNotPresent() {
 				"spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false",
 				"spring.cloud.discovery.client.health-indicator.enabled=false");
 		applicationContextRunner
-				.withConfiguration(AutoConfigurations.of(Fabric8DiscoveryClientPredicateAutoConfiguration.class))
-				.run(context -> {
-					assertThat(context).hasSingleBean(Fabric8KubernetesReactiveDiscoveryClient.class);
-					assertThat(context).doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class);
-				});
+			.withConfiguration(AutoConfigurations.of(Fabric8DiscoveryClientPredicateAutoConfiguration.class))
+			.run(context -> {
+				assertThat(context).hasSingleBean(Fabric8KubernetesReactiveDiscoveryClient.class);
+				assertThat(context).doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class);
+			});
 	}
 
 	private void setup(String... properties) {
 		applicationContextRunner = new ApplicationContextRunner()
-				.withConfiguration(AutoConfigurations.of(UtilAutoConfiguration.class,
-						ReactiveCommonsClientAutoConfiguration.class, KubernetesCommonsAutoConfiguration.class,
-						Fabric8AutoConfiguration.class, Fabric8KubernetesReactiveDiscoveryClientAutoConfiguration.class,
-						KubernetesDiscoveryPropertiesAutoConfiguration.class))
-				.withPropertyValues(properties);
+			.withConfiguration(AutoConfigurations.of(UtilAutoConfiguration.class,
+					ReactiveCommonsClientAutoConfiguration.class, KubernetesCommonsAutoConfiguration.class,
+					Fabric8AutoConfiguration.class, Fabric8KubernetesReactiveDiscoveryClientAutoConfiguration.class,
+					KubernetesDiscoveryPropertiesAutoConfiguration.class))
+			.withPropertyValues(properties);
 	}
 
 	private void setupWithFilteredClassLoader(String name, String... properties) {
 		applicationContextRunner = new ApplicationContextRunner()
-				.withConfiguration(AutoConfigurations.of(UtilAutoConfiguration.class,
-						ReactiveCommonsClientAutoConfiguration.class, KubernetesCommonsAutoConfiguration.class,
-						Fabric8AutoConfiguration.class, Fabric8KubernetesReactiveDiscoveryClientAutoConfiguration.class,
-						KubernetesDiscoveryPropertiesAutoConfiguration.class))
-				.withClassLoader(new FilteredClassLoader(name)).withPropertyValues(properties);
+			.withConfiguration(AutoConfigurations.of(UtilAutoConfiguration.class,
+					ReactiveCommonsClientAutoConfiguration.class, KubernetesCommonsAutoConfiguration.class,
+					Fabric8AutoConfiguration.class, Fabric8KubernetesReactiveDiscoveryClientAutoConfiguration.class,
+					KubernetesDiscoveryPropertiesAutoConfiguration.class))
+			.withClassLoader(new FilteredClassLoader(name))
+			.withPropertyValues(properties);
 	}
 
 }
diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientAutoConfigurationTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientAutoConfigurationTests.java
index eb2a9cd170..7c10a1e280 100644
--- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientAutoConfigurationTests.java
+++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientAutoConfigurationTests.java
@@ -37,20 +37,20 @@
 class Fabric8KubernetesReactiveDiscoveryClientAutoConfigurationTests {
 
 	private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
-			.withConfiguration(AutoConfigurations.of(UtilAutoConfiguration.class,
-					ReactiveCommonsClientAutoConfiguration.class, KubernetesCommonsAutoConfiguration.class,
-					Fabric8AutoConfiguration.class, Fabric8KubernetesDiscoveryClientAutoConfiguration.class,
-					Fabric8KubernetesReactiveDiscoveryClientAutoConfiguration.class,
-					KubernetesDiscoveryPropertiesAutoConfiguration.class));
+		.withConfiguration(AutoConfigurations.of(UtilAutoConfiguration.class,
+				ReactiveCommonsClientAutoConfiguration.class, KubernetesCommonsAutoConfiguration.class,
+				Fabric8AutoConfiguration.class, Fabric8KubernetesDiscoveryClientAutoConfiguration.class,
+				Fabric8KubernetesReactiveDiscoveryClientAutoConfiguration.class,
+				KubernetesDiscoveryPropertiesAutoConfiguration.class));
 
 	@Test
 	void shouldWorkWithDefaults() {
 		contextRunner.withPropertyValues("spring.main.cloud-platform=KUBERNETES")
-				.withConfiguration(AutoConfigurations.of(Fabric8DiscoveryClientPredicateAutoConfiguration.class))
-				.run(context -> {
-					assertThat(context).hasSingleBean(ReactiveDiscoveryClient.class);
-					assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class);
-				});
+			.withConfiguration(AutoConfigurations.of(Fabric8DiscoveryClientPredicateAutoConfiguration.class))
+			.run(context -> {
+				assertThat(context).hasSingleBean(ReactiveDiscoveryClient.class);
+				assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class);
+			});
 	}
 
 	@Test
@@ -100,11 +100,12 @@ void worksWithoutWebflux() {
 	@Test
 	void worksWithoutActuator() {
 		contextRunner.withPropertyValues("spring.main.cloud-platform=KUBERNETES")
-				.withConfiguration(AutoConfigurations.of(Fabric8DiscoveryClientPredicateAutoConfiguration.class))
-				.withClassLoader(new FilteredClassLoader("org.springframework.boot.actuate")).run(context -> {
-					assertThat(context).hasSingleBean(ReactiveDiscoveryClient.class);
-					assertThat(context).doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class);
-				});
+			.withConfiguration(AutoConfigurations.of(Fabric8DiscoveryClientPredicateAutoConfiguration.class))
+			.withClassLoader(new FilteredClassLoader("org.springframework.boot.actuate"))
+			.run(context -> {
+				assertThat(context).hasSingleBean(ReactiveDiscoveryClient.class);
+				assertThat(context).doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class);
+			});
 	}
 
 }
diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientTests.java
index d2c4e16ffc..1dc534b766 100644
--- a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientTests.java
+++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientTests.java
@@ -94,12 +94,29 @@ void verifyDefaults() {
 
 	@Test
 	void shouldReturnFluxOfServices() {
-		kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services")
-				.andReturn(200, new ServiceListBuilder().addNewItem().withNewMetadata().withName("s1")
-						.withLabels(Map.of("label", "value")).endMetadata().endItem().addNewItem().withNewMetadata()
-						.withName("s2").withLabels(Map.of("label", "value", "label2", "value2")).endMetadata().endItem()
-						.addNewItem().withNewMetadata().withName("s3").endMetadata().endItem().build())
-				.once();
+		kubernetesServer.expect()
+			.get()
+			.withPath("/api/v1/namespaces/test/services")
+			.andReturn(200,
+					new ServiceListBuilder().addNewItem()
+						.withNewMetadata()
+						.withName("s1")
+						.withLabels(Map.of("label", "value"))
+						.endMetadata()
+						.endItem()
+						.addNewItem()
+						.withNewMetadata()
+						.withName("s2")
+						.withLabels(Map.of("label", "value", "label2", "value2"))
+						.endMetadata()
+						.endItem()
+						.addNewItem()
+						.withNewMetadata()
+						.withName("s3")
+						.endMetadata()
+						.endItem()
+						.build())
+			.once();
 		Fabric8KubernetesDiscoveryClient fabric8KubernetesDiscoveryClient = new Fabric8KubernetesDiscoveryClient(
 				kubernetesClient, KubernetesDiscoveryProperties.DEFAULT, SERVICE_PORT_SECURE_RESOLVER,
 				NAMESPACE_PROVIDER, x -> true);

From 9daba67ef31775acfe386e6b6554f0cd12f3feb0 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Fri, 25 Oct 2024 07:28:06 +0300
Subject: [PATCH 150/151] fix test

---
 .../Fabric8KubernetesCatalogWatchAutoConfiguration.java       | 2 +-
 ...ic8CatalogWatchWithEndpointSlicesAndNamespaceFilterIT.java | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchAutoConfiguration.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchAutoConfiguration.java
index 0768eb557d..2b5a7ff76c 100644
--- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchAutoConfiguration.java
+++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchAutoConfiguration.java
@@ -37,7 +37,7 @@
 @Configuration(proxyBeanMethods = false)
 @ConditionalOnKubernetesCatalogWatcherEnabled
 @AutoConfigureAfter({ Fabric8AutoConfiguration.class, KubernetesDiscoveryPropertiesAutoConfiguration.class })
-class Fabric8KubernetesCatalogWatchAutoConfiguration {
+public class Fabric8KubernetesCatalogWatchAutoConfiguration {
 
 	@Bean
 	@ConditionalOnMissingBean
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..e1ea91b4b1 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
@@ -28,7 +28,7 @@
 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.fabric8.discovery.Fabric8KubernetesCatalogWatchAutoConfiguration;
 import org.springframework.cloud.kubernetes.integration.tests.commons.Images;
 import org.springframework.cloud.kubernetes.integration.tests.commons.Phase;
 import org.springframework.context.annotation.Bean;
@@ -41,7 +41,7 @@
 /**
  * @author wind57
  */
-@SpringBootTest(classes = { KubernetesCatalogWatchAutoConfiguration.class, TestConfig.class, Application.class },
+@SpringBootTest(classes = { Fabric8KubernetesCatalogWatchAutoConfiguration.class, TestConfig.class, Application.class },
 		webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
 class Fabric8CatalogWatchWithEndpointSlicesAndNamespaceFilterIT extends Fabric8CatalogWatchBase {
 

From 9719028912709a22d0379923282c5e9babf8ede9 Mon Sep 17 00:00:00 2001
From: wind57 
Date: Fri, 25 Oct 2024 07:39:01 +0300
Subject: [PATCH 151/151] fix test

---
 .../watch/Fabric8CatalogWatchWithEndpointSlicesIT.java        | 4 ++--
 .../Fabric8CatalogWatchWithEndpointsAndNamespaceFilterIT.java | 4 ++--
 .../catalog/watch/Fabric8CatalogWatchWithEndpointsIT.java     | 4 ++--
 3 files changed, 6 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/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..58e431a90b 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
@@ -28,7 +28,7 @@
 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.fabric8.discovery.Fabric8KubernetesCatalogWatchAutoConfiguration;
 import org.springframework.cloud.kubernetes.integration.tests.commons.Images;
 import org.springframework.cloud.kubernetes.integration.tests.commons.Phase;
 import org.springframework.context.annotation.Bean;
@@ -41,7 +41,7 @@
 /**
  * @author wind57
  */
-@SpringBootTest(classes = { KubernetesCatalogWatchAutoConfiguration.class, TestConfig.class, Application.class },
+@SpringBootTest(classes = { Fabric8KubernetesCatalogWatchAutoConfiguration.class, TestConfig.class, Application.class },
 		webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
 class Fabric8CatalogWatchWithEndpointSlicesIT extends Fabric8CatalogWatchBase {
 
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..87f73980e6 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
@@ -28,7 +28,7 @@
 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.fabric8.discovery.Fabric8KubernetesCatalogWatchAutoConfiguration;
 import org.springframework.cloud.kubernetes.integration.tests.commons.Images;
 import org.springframework.cloud.kubernetes.integration.tests.commons.Phase;
 import org.springframework.context.annotation.Bean;
@@ -41,7 +41,7 @@
 /**
  * @author wind57
  */
-@SpringBootTest(classes = { KubernetesCatalogWatchAutoConfiguration.class, TestConfig.class, Application.class },
+@SpringBootTest(classes = { Fabric8KubernetesCatalogWatchAutoConfiguration.class, TestConfig.class, Application.class },
 		webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
 class Fabric8CatalogWatchWithEndpointsAndNamespaceFilterIT extends Fabric8CatalogWatchBase {
 
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..9f11388d4b 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
@@ -28,7 +28,7 @@
 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.fabric8.discovery.Fabric8KubernetesCatalogWatchAutoConfiguration;
 import org.springframework.cloud.kubernetes.integration.tests.commons.Images;
 import org.springframework.cloud.kubernetes.integration.tests.commons.Phase;
 import org.springframework.context.annotation.Bean;
@@ -41,7 +41,7 @@
 /**
  * @author wind57
  */
-@SpringBootTest(classes = { KubernetesCatalogWatchAutoConfiguration.class, TestConfig.class, Application.class },
+@SpringBootTest(classes = { Fabric8KubernetesCatalogWatchAutoConfiguration.class, TestConfig.class, Application.class },
 		webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
 class Fabric8CatalogWatchWithEndpointsIT extends Fabric8CatalogWatchBase {