diff --git a/.github/workflows/composites/build-integration-tests-project/action.yaml b/.github/workflows/composites/build-integration-tests-project/action.yaml index 23fbb33aa8..a42969ede4 100644 --- a/.github/workflows/composites/build-integration-tests-project/action.yaml +++ b/.github/workflows/composites/build-integration-tests-project/action.yaml @@ -3,6 +3,7 @@ description: build integration tests project without tests runs: using: "composite" steps: + - name: build integration tests project without tests shell: bash run: | 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 19e0a15e6f..55eafe1754 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 @@ -68,7 +68,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); @@ -89,7 +89,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(); @@ -113,7 +113,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(); @@ -137,7 +137,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(); @@ -161,7 +161,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 0eefaeed8c..b743d0729d 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 @@ -687,7 +687,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 ae3715891c..2f172d5902 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()) @@ -131,7 +131,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()); @@ -145,7 +145,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 0fa40fd936..14552c3e7e 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-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 new file mode 100644 index 0000000000..559dcdfba4 --- /dev/null +++ b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/KubernetesExternalNameServiceInstance.java @@ -0,0 +1,71 @@ +/* + * 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=ExternalName". + * + * @author wind57 + */ +public record KubernetesExternalNameServiceInstance(String serviceId, String host, String instanceId, + Map metadata) implements ServiceInstance { + + @Override + public String getServiceId() { + return serviceId; + } + + @Override + public String getHost() { + return host; + } + + @Override + public int getPort() { + return -1; + } + + @Override + public boolean isSecure() { + return false; + } + + @Override + public URI getUri() { + return URI.create(host); + } + + @Override + public Map getMetadata() { + return metadata; + } + + public String getInstanceId() { + return instanceId; + } + + public String type() { + return "ExternalName"; + } + +} diff --git a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/ServicePortSecureResolver.java b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/ServicePortSecureResolver.java index bf49e18cc8..6c62436e98 100644 --- a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/ServicePortSecureResolver.java +++ b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/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-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..3a8e1f8a05 --- /dev/null +++ b/spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/discovery/KubernetesExternalNameServiceInstanceTests.java @@ -0,0 +1,43 @@ +/* + * 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"); + Assertions.assertEquals(instance.type(), "ExternalName"); + } + +} diff --git a/spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/discovery/ServicePortSecureResolverTest.java b/spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/discovery/ServicePortSecureResolverTest.java index 6a38edab0e..553c9a5f70 100644 --- a/spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/discovery/ServicePortSecureResolverTest.java +++ b/spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/discovery/ServicePortSecureResolverTest.java @@ -56,7 +56,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/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 6a14e61253..2c43588bb8 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/Fabric8ConfigServerBootstrapper.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8ConfigServerBootstrapper.java index 3b65c87750..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 @@ -61,8 +61,8 @@ public void initialize(BootstrapRegistry registry) { if (!getDiscoveryEnabled(context)) { return (id) -> Collections.emptyList(); } - 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 { @@ -72,12 +72,11 @@ public void initialize(BootstrapRegistry registry) { .kubernetesClientConfig(context.get(KubernetesClientProperties.class)); KubernetesClient kubernetesClient = fabric8AutoConfiguration.kubernetesClient(config); KubernetesDiscoveryProperties discoveryProperties = context.get(KubernetesDiscoveryProperties.class); - KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(kubernetesClient, - discoveryProperties, - KubernetesClientServicesFunctionProvider.servicesFunction(discoveryProperties, - new KubernetesNamespaceProvider(propertyResolver - .get(KubernetesNamespaceProvider.NAMESPACE_PROPERTY, String.class, null))), - null, new ServicePortSecureResolver(discoveryProperties)); + Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient( + 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/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..a9bf4a463c --- /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 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.ConditionalOnDiscoveryEnabled; +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; +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; + +/** + * @author wind57 + */ +@Configuration(proxyBeanMethods = false) +@ConditionalOnDiscoveryEnabled +@ConditionalOnBlockingOrReactiveDiscoveryEnabled +@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 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/Fabric8EndpointSliceV1CatalogWatch.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8EndpointSliceV1CatalogWatch.java index 22f4d88f05..29bd5f7057 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. @@ -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,10 @@ 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,38 +36,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) @@ -81,15 +50,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 2e7791c2cf..37a1a78690 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/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 d6a84fb7b7..dd27067b3b 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 @@ -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. @@ -43,21 +43,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, + Fabric8KubernetesCatalogWatch(KubernetesClient kubernetesClient, KubernetesDiscoveryProperties properties, KubernetesNamespaceProvider namespaceProvider) { context = new Fabric8CatalogWatchContext(kubernetesClient, properties, namespaceProvider); } @@ -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/KubernetesCatalogWatchAutoConfiguration.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchAutoConfiguration.java similarity index 86% 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 1c7080f29b..2b5a7ff76c 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 @@ -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. @@ -37,13 +37,13 @@ @Configuration(proxyBeanMethods = false) @ConditionalOnKubernetesCatalogWatcherEnabled @AutoConfigureAfter({ Fabric8AutoConfiguration.class, KubernetesDiscoveryPropertiesAutoConfiguration.class }) -public class KubernetesCatalogWatchAutoConfiguration { +public class Fabric8KubernetesCatalogWatchAutoConfiguration { @Bean @ConditionalOnMissingBean - public KubernetesCatalogWatch kubernetesCatalogWatch(KubernetesClient client, + Fabric8KubernetesCatalogWatch kubernetesCatalogWatch(KubernetesClient client, KubernetesDiscoveryProperties properties, Environment environment) { - return new KubernetesCatalogWatch(client, properties, new KubernetesNamespaceProvider(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 78% 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 79ca695870..df5b5e6aec 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 @@ -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. @@ -36,8 +36,6 @@ import org.springframework.cloud.kubernetes.commons.discovery.ServiceMetadata; import org.springframework.cloud.kubernetes.commons.discovery.ServicePortNameAndNumber; import org.springframework.cloud.kubernetes.commons.discovery.ServicePortSecureResolver; -import org.springframework.context.EnvironmentAware; -import org.springframework.core.env.Environment; import org.springframework.core.log.LogAccessor; import static org.springframework.cloud.kubernetes.commons.discovery.DiscoveryClientUtils.endpointsPort; @@ -60,48 +58,30 @@ * @author Ioannis Canellos * @author Tim Ysewyn */ -public class KubernetesDiscoveryClient implements DiscoveryClient, EnvironmentAware { +public 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 @@ -144,7 +124,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 serviceInstances(Endpoints endpoints, String serviceId) { @@ -186,18 +166,13 @@ private List serviceInstances(Endpoints endpoints, String servi @Override public List getServices() { - List services = adapter.apply(client).stream().map(s -> s.getMetadata().getName()).distinct().toList(); - LOG.debug(() -> "will return services : " + services); - return services; - } - - @Deprecated(forRemoval = true) - public List getServices(Predicate filter) { - return new Fabric8DiscoveryServicesAdapter(kubernetesClientServicesFunction, properties, filter).apply(client) + List services = services(properties, client, namespaceProvider, predicate, null, "fabric8 discovery") .stream() - .map(s -> s.getMetadata().getName()) + .map(service -> service.getMetadata().getName()) .distinct() .toList(); + LOG.debug(() -> "will return services : " + services); + return services; } @Override @@ -205,10 +180,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 74% 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 fdf7d7b90b..6437ea18bd 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 @@ -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. @@ -16,6 +16,9 @@ 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; import org.apache.commons.logging.LogFactory; @@ -24,6 +27,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.cloud.client.CommonsClientAutoConfiguration; 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.ConditionalOnSpringCloudKubernetesBlockingDiscovery; import org.springframework.cloud.kubernetes.commons.discovery.ConditionalOnSpringCloudKubernetesBlockingDiscoveryHealthInitializer; @@ -47,31 +51,26 @@ @Configuration(proxyBeanMethods = false) @ConditionalOnSpringCloudKubernetesBlockingDiscovery @AutoConfigureBefore({ SimpleDiscoveryClientAutoConfiguration.class, CommonsClientAutoConfiguration.class }) -@AutoConfigureAfter({ Fabric8AutoConfiguration.class, KubernetesDiscoveryPropertiesAutoConfiguration.class }) -public class KubernetesDiscoveryClientAutoConfiguration { +@AutoConfigureAfter({ Fabric8AutoConfiguration.class, KubernetesDiscoveryPropertiesAutoConfiguration.class, + Fabric8DiscoveryClientPredicateAutoConfiguration.class }) +class Fabric8KubernetesDiscoveryClientAutoConfiguration { private static final LogAccessor LOG = new LogAccessor( - LogFactory.getLog(KubernetesDiscoveryClientAutoConfiguration.class)); - - @Bean - @ConditionalOnMissingBean - public KubernetesClientServicesFunction servicesFunction(KubernetesDiscoveryProperties properties, - Environment environment) { - return KubernetesClientServicesFunctionProvider.servicesFunction(properties, environment); - } + LogFactory.getLog(Fabric8KubernetesDiscoveryClientAutoConfiguration.class)); @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 @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/KubernetesDiscoveryClientConfigClientBootstrapConfiguration.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientConfigClientBootstrapConfiguration.java similarity index 84% 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 8cd5e7f55c..d6a4b451b5 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 @@ -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. @@ -31,8 +31,9 @@ */ @Configuration(proxyBeanMethods = false) @ConditionalOnProperty("spring.cloud.config.discovery.enabled") -@Import({ Fabric8AutoConfiguration.class, KubernetesDiscoveryClientAutoConfiguration.class }) +@Import({ Fabric8AutoConfiguration.class, Fabric8KubernetesDiscoveryClientAutoConfiguration.class, + Fabric8DiscoveryClientPredicateAutoConfiguration.class }) @EnableConfigurationProperties({ KubernetesDiscoveryProperties.class, KubernetesClientProperties.class }) -public class KubernetesDiscoveryClientConfigClientBootstrapConfiguration { +class Fabric8KubernetesDiscoveryClientConfigClientBootstrapConfiguration { } 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 eb3a264cd9..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 @@ -31,6 +31,8 @@ import io.fabric8.kubernetes.api.model.EndpointsList; 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; @@ -62,6 +64,34 @@ 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) { @@ -226,4 +256,15 @@ private static List filteredServices( } + private static List filteredEndpointSlices( + FilterNested>> filterNested, + KubernetesDiscoveryProperties properties) { + + FilterNested>> partial = filterNested + .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/reactive/KubernetesReactiveDiscoveryClient.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClient.java similarity index 54% 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 e86791b75e..0e7c1e21bb 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 @@ -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. @@ -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 bed427f010..5b11befd76 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 @@ -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. @@ -14,8 +14,11 @@ * limitations under the License. */ -package org.springframework.cloud.kubernetes.fabric8.discovery.reactive; +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; import org.apache.commons.logging.LogFactory; @@ -29,15 +32,14 @@ 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.PodUtils; import org.springframework.cloud.kubernetes.commons.discovery.ConditionalOnSpringCloudKubernetesReactiveDiscovery; import org.springframework.cloud.kubernetes.commons.discovery.ConditionalOnSpringCloudKubernetesReactiveDiscoveryHealthInitializer; import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryClientHealthIndicatorInitializer; 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.cloud.kubernetes.commons.discovery.ServicePortSecureResolver; import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -54,25 +56,22 @@ @AutoConfigureBefore({ SimpleReactiveDiscoveryClientAutoConfiguration.class, ReactiveCommonsClientAutoConfiguration.class }) @AutoConfigureAfter({ ReactiveCompositeDiscoveryClientAutoConfiguration.class, - KubernetesDiscoveryClientAutoConfiguration.class, KubernetesDiscoveryPropertiesAutoConfiguration.class }) -public class KubernetesReactiveDiscoveryClientAutoConfiguration { + Fabric8KubernetesDiscoveryClientAutoConfiguration.class, KubernetesDiscoveryPropertiesAutoConfiguration.class, + Fabric8DiscoveryClientPredicateAutoConfiguration.class }) +class Fabric8KubernetesReactiveDiscoveryClientAutoConfiguration { private static final LogAccessor LOG = new LogAccessor( - LogFactory.getLog(KubernetesReactiveDiscoveryClientAutoConfiguration.class)); - - @Bean - @ConditionalOnMissingBean - public KubernetesClientServicesFunction servicesFunction(KubernetesDiscoveryProperties properties, - Environment environment) { - return KubernetesClientServicesFunctionProvider.servicesFunction(properties, environment); - } + LogFactory.getLog(Fabric8KubernetesReactiveDiscoveryClientAutoConfiguration.class)); @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); } /** @@ -89,8 +88,8 @@ KubernetesDiscoveryClientHealthIndicatorInitializer reactiveIndicatorInitializer @Bean @ConditionalOnSpringCloudKubernetesReactiveDiscoveryHealthInitializer - 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 2a65d110dc..0000000000 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/KubernetesClientServicesFunctionProvider.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2013-2024 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.kubernetes.fabric8.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()); - }; - - } - - @Deprecated(forRemoval = true) - public static KubernetesClientServicesFunction servicesFunction(KubernetesDiscoveryProperties properties, - Binder binder, BindHandler bindHandler) { - return servicesFunction(properties, new KubernetesNamespaceProvider(binder, bindHandler)); - } - - public static KubernetesClientServicesFunction servicesFunction(KubernetesDiscoveryProperties properties, - KubernetesNamespaceProvider namespaceProvider) { - - if (properties.allNamespaces()) { - return (client) -> client.services().inAnyNamespace().withLabels(properties.serviceLabels()); - } - - return client -> { - String namespace = Fabric8Utils.getApplicationNamespace(client, null, "discovery-service", - namespaceProvider); - return client.services().inNamespace(namespace).withLabels(properties.serviceLabels()); - }; - - } - -} 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 d1cfd5572f..c3a27aaa48 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,4 +1,4 @@ org.springframework.cloud.bootstrap.BootstrapConfiguration=\ -org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientConfigClientBootstrapConfiguration +org.springframework.cloud.kubernetes.fabric8.discovery.Fabric8KubernetesDiscoveryClientConfigClientBootstrapConfiguration org.springframework.boot.BootstrapRegistryInitializer=\ org.springframework.cloud.kubernetes.fabric8.discovery.Fabric8ConfigServerBootstrapper 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/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 9ed841106d..8ceaa1e851 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.Fabric8KubernetesDiscoveryClientUtils.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); - - 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 Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties), 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,14 @@ 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); - - 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 Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties), 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 +147,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); - - 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 Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties), 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 +182,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); - - 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 Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties), 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,17 +214,9 @@ 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); - - 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"); @@ -248,7 +224,8 @@ void testSpecificNamespaceWithoutLabelsWithoutFilter() { 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 Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties), 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,16 +249,9 @@ 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); - - 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))) @@ -291,7 +261,8 @@ void testSpecificNamespaceWithLabelsWithoutFilter() { 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 Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties), 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,14 +292,8 @@ 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); - - 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))) @@ -338,7 +303,8 @@ void testSpecificNamespaceWithoutLabelsWithFilter() { 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 Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties), 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 +330,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); - - 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 Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties), 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 +369,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); - - 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 Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties), 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 +406,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); - - 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 Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties), null, "dummy-target"); Assertions.assertEquals(result.size(), 1); Assertions.assertEquals(result.get(0).getMetadata().getName(), "serviceA"); Assertions.assertEquals(result.get(0).getMetadata().getNamespace(), "namespaceA"); @@ -477,4 +427,10 @@ private void service(String namespace, String name, Map labels) .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/Fabric8EndpointsAndEndpointSlicesTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8EndpointsAndEndpointSlicesTests.java index 4f4a55144f..face61dc58 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 @@ -235,13 +235,14 @@ 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); + true, 60, false, "", Set.of(), labels, "", null, 0, endpointSlices, false); + Fabric8KubernetesCatalogWatch watch = new Fabric8KubernetesCatalogWatch(mockClient(), properties, + NAMESPACE_PROVIDER); if (endpointSlices) { watch = Mockito.spy(watch); @@ -254,15 +255,16 @@ 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); + Set.of(namespace), true, 60, false, "", Set.of(), labels, "", null, 0, endpointSlices, false); + Fabric8KubernetesCatalogWatch watch = new Fabric8KubernetesCatalogWatch(mockClient(), properties, + NAMESPACE_PROVIDER); if (endpointSlices) { watch = Mockito.spy(watch); @@ -275,13 +277,14 @@ KubernetesCatalogWatch createWatcherInSpecificNamespaceWithLabels(String namespa } - KubernetesCatalogWatch createWatcherInSpecificNamespacesWithLabels(Set namespaces, + 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); + false, "", Set.of(), labels, "", null, 0, false, false); + Fabric8KubernetesCatalogWatch watch = new Fabric8KubernetesCatalogWatch(mockClient(), properties, + NAMESPACE_PROVIDER); if (endpointSlices) { watch = Mockito.spy(watch); @@ -335,7 +338,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, Mockito.atLeastOnce()) 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 90% 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 21f0aae386..4e0baf267e 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; @@ -81,8 +81,10 @@ 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, + 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/Fabric8KubernetesCatalogWatchAutoConfigurationApplicationContextTests.java similarity index 68% 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 859fa8ed91..7dee7c2d3b 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 @@ -23,42 +23,42 @@ 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; /** * @author wind57 */ -class KubernetesCatalogWatchAutoConfigurationApplicationContextTests { +class Fabric8KubernetesCatalogWatchAutoConfigurationApplicationContextTests { private ApplicationContextRunner applicationContextRunner; @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 should disable catalog watcher. @@ -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(KubernetesCatalogWatch.class)); + applicationContextRunner + .run(context -> assertThat(context).doesNotHaveBean(Fabric8KubernetesCatalogWatch.class)); } /** @@ -77,10 +78,9 @@ 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).doesNotHaveBean(KubernetesCatalogWatch.class); - assertThat(context).doesNotHaveBean(KubernetesClientServicesFunction.class); - assertThat(context).doesNotHaveBean(KubernetesDiscoveryClient.class); - assertThat(context).doesNotHaveBean(KubernetesReactiveDiscoveryClient.class); + assertThat(context).doesNotHaveBean(Fabric8KubernetesCatalogWatch.class); + assertThat(context).doesNotHaveBean(Fabric8KubernetesDiscoveryClient.class); + assertThat(context).doesNotHaveBean(Fabric8KubernetesReactiveDiscoveryClient.class); }); } @@ -92,10 +92,9 @@ void disableBlockingEnableReactive() { setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", "spring.cloud.discovery.blocking.enabled=false", "spring.cloud.discovery.reactive.enabled=true"); applicationContextRunner.run(context -> { - assertThat(context).hasSingleBean(KubernetesCatalogWatch.class); - assertThat(context).doesNotHaveBean(KubernetesClientServicesFunction.class); - assertThat(context).doesNotHaveBean(KubernetesDiscoveryClient.class); - assertThat(context).doesNotHaveBean(KubernetesReactiveDiscoveryClient.class); + assertThat(context).hasSingleBean(Fabric8KubernetesCatalogWatch.class); + assertThat(context).doesNotHaveBean(Fabric8KubernetesDiscoveryClient.class); + assertThat(context).doesNotHaveBean(Fabric8KubernetesReactiveDiscoveryClient.class); }); } @@ -107,10 +106,9 @@ void enableBlockingDisableReactive() { setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", "spring.cloud.discovery.blocking.enabled=true", "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); + assertThat(context).hasSingleBean(Fabric8KubernetesCatalogWatch.class); + assertThat(context).doesNotHaveBean(Fabric8KubernetesDiscoveryClient.class); + assertThat(context).doesNotHaveBean(Fabric8KubernetesReactiveDiscoveryClient.class); }); } @@ -123,18 +121,18 @@ void disableKubernetesDiscovery() { setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false", "spring.cloud.kubernetes.discovery.enabled=false"); applicationContextRunner.run(context -> { - assertThat(context).doesNotHaveBean(KubernetesCatalogWatch.class); - assertThat(context).doesNotHaveBean(KubernetesClientServicesFunction.class); - assertThat(context).doesNotHaveBean(KubernetesDiscoveryClient.class); - assertThat(context).doesNotHaveBean(KubernetesReactiveDiscoveryClient.class); + assertThat(context).doesNotHaveBean(Fabric8KubernetesCatalogWatch.class); + assertThat(context).doesNotHaveBean(Fabric8KubernetesDiscoveryClient.class); + assertThat(context).doesNotHaveBean(Fabric8KubernetesReactiveDiscoveryClient.class); }); } private void setup(String... properties) { applicationContextRunner = new ApplicationContextRunner() - .withConfiguration(AutoConfigurations.of(KubernetesCatalogWatchAutoConfiguration.class, + .withConfiguration(AutoConfigurations.of(Fabric8KubernetesCatalogWatchAutoConfiguration.class, Fabric8AutoConfiguration.class, KubernetesCommonsAutoConfiguration.class, - KubernetesDiscoveryPropertiesAutoConfiguration.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 3a965e9630..c0bbde72b7 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,12 +63,13 @@ 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(); - 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()); } @@ -83,7 +84,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") @@ -95,7 +96,8 @@ 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,8 +109,9 @@ void testEndpointSlicesEnabledButNotSupportedViaApiVersions() { @Test 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); + false, "", Set.of(), Map.of(), "", null, 0, false, false); + Fabric8KubernetesCatalogWatch watch = new Fabric8KubernetesCatalogWatch(mockClient, properties, + NAMESPACE_PROVIDER); Assertions.assertEquals(Fabric8EndpointsCatalogWatch.class, watch.stateGenerator().getClass()); } @@ -120,8 +123,9 @@ void testEndpointsSupport() { @Test 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); + false, "", Set.of(), Map.of(), "", null, 0, true, false); + Fabric8KubernetesCatalogWatch watch = new Fabric8KubernetesCatalogWatch(mockClient, properties, + NAMESPACE_PROVIDER); GroupVersionForDiscovery forDiscovery = new GroupVersionForDiscoveryBuilder() .withGroupVersion("discovery.k8s.io/v1") 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..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() { - KubernetesCatalogWatch 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"); @@ -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,8 @@ 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,8 +113,8 @@ void testInAllNamespacesWithoutServiceLabels() { @Override void testAllNamespacesTrueOtherBranchesNotCalled() { - KubernetesCatalogWatch 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"); @@ -129,7 +130,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,8 +146,8 @@ void testAllNamespacesFalseNamespacesPresent() { @Override void testAllNamespacesFalseNamespacesNotPresent() { - KubernetesCatalogWatch 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() { - KubernetesCatalogWatch 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 07267b4031..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 @@ -49,8 +49,8 @@ void afterEach() { @Override void testInSpecificNamespaceWithServiceLabels() { - KubernetesCatalogWatch 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"); @@ -71,7 +71,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"); @@ -96,7 +96,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"); @@ -119,7 +119,8 @@ 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"); @@ -143,7 +144,7 @@ void testInAllNamespacesWithoutServiceLabels() { @Override void testAllNamespacesTrueOtherBranchesNotCalled() { - 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"); @@ -166,7 +167,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"); @@ -188,8 +189,8 @@ void testAllNamespacesFalseNamespacesPresent() { @Override void testAllNamespacesFalseNamespacesNotPresent() { - KubernetesCatalogWatch 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"); @@ -210,8 +211,8 @@ void testAllNamespacesFalseNamespacesNotPresent() { @Override void testTwoNamespacesOutOfThree() { - KubernetesCatalogWatch 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/KubernetesCatalogWatchTest.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesCatalogWatchTest.java similarity index 97% 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 aebc177073..0cdb696952 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 @@ -60,13 +60,13 @@ * @author Oleg Vyukov */ @SuppressWarnings({ "unchecked" }) -class KubernetesCatalogWatchTest { +class Fabric8KubernetesCatalogWatchTest { private static final KubernetesClient CLIENT = Mockito.mock(KubernetesClient.class); 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); @@ -403,9 +403,9 @@ 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 = new Fabric8KubernetesCatalogWatch(CLIENT, properties, namespaceProvider); kubernetesCatalogWatch.setApplicationEventPublisher(APPLICATION_EVENT_PUBLISHER); kubernetesCatalogWatch.postConstruct(); @@ -422,9 +422,9 @@ 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 = 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/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 b84acb9b67..1f8ac454cc 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 { /** *
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 73%
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 d45f677d37..5f27413e92 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
@@ -30,11 +30,11 @@
 import static org.assertj.core.api.Assertions.assertThat;
 
 /**
- * Test various conditionals for {@link KubernetesDiscoveryClientAutoConfiguration}
+ * Test various conditionals for {@link Fabric8KubernetesDiscoveryClientAutoConfiguration}
  *
  * @author wind57
  */
-class KubernetesDiscoveryClientAutoConfigurationApplicationContextTests {
+class Fabric8KubernetesDiscoveryClientAutoConfigurationApplicationContextTests {
 
 	private ApplicationContextRunner applicationContextRunner;
 
@@ -42,8 +42,7 @@ class KubernetesDiscoveryClientAutoConfigurationApplicationContextTests {
 	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(Fabric8KubernetesDiscoveryClient.class);
 			assertThat(context).hasSingleBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class);
 		});
 	}
@@ -53,8 +52,7 @@ 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(Fabric8KubernetesDiscoveryClient.class);
 			assertThat(context).hasSingleBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class);
 		});
 	}
@@ -64,8 +62,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(KubernetesClientServicesFunction.class);
-			assertThat(context).doesNotHaveBean(KubernetesDiscoveryClient.class);
+			assertThat(context).doesNotHaveBean(Fabric8KubernetesDiscoveryClient.class);
 			assertThat(context).doesNotHaveBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class);
 		});
 	}
@@ -75,8 +72,7 @@ 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(Fabric8KubernetesDiscoveryClient.class);
 			assertThat(context).hasSingleBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class);
 		});
 	}
@@ -86,8 +82,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(KubernetesClientServicesFunction.class);
-			assertThat(context).doesNotHaveBean(KubernetesDiscoveryClient.class);
+			assertThat(context).doesNotHaveBean(Fabric8KubernetesDiscoveryClient.class);
 			assertThat(context).doesNotHaveBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class);
 		});
 	}
@@ -97,8 +92,7 @@ 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(Fabric8KubernetesDiscoveryClient.class);
 			assertThat(context).hasSingleBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class);
 		});
 	}
@@ -108,8 +102,7 @@ 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(Fabric8KubernetesDiscoveryClient.class);
 			assertThat(context).doesNotHaveBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class);
 		});
 	}
@@ -119,8 +112,7 @@ 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(Fabric8KubernetesDiscoveryClient.class);
 			assertThat(context).hasSingleBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class);
 		});
 	}
@@ -130,8 +122,7 @@ 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).hasSingleBean(Fabric8KubernetesDiscoveryClient.class);
 			assertThat(context).doesNotHaveBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class);
 		});
 	}
@@ -141,8 +132,7 @@ 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).hasSingleBean(Fabric8KubernetesDiscoveryClient.class);
 			assertThat(context).doesNotHaveBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class);
 		});
 	}
@@ -155,25 +145,26 @@ 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(Fabric8KubernetesDiscoveryClient.class);
 			assertThat(context).hasSingleBean(KubernetesDiscoveryClientHealthIndicatorInitializer.class);
 		});
 	}
 
 	private void setup(String... properties) {
 		applicationContextRunner = new ApplicationContextRunner()
-			.withConfiguration(AutoConfigurations.of(KubernetesDiscoveryClientAutoConfiguration.class,
+			.withConfiguration(AutoConfigurations.of(Fabric8KubernetesDiscoveryClientAutoConfiguration.class,
 					Fabric8AutoConfiguration.class, KubernetesCommonsAutoConfiguration.class,
-					KubernetesDiscoveryPropertiesAutoConfiguration.class))
+					KubernetesDiscoveryPropertiesAutoConfiguration.class,
+					Fabric8DiscoveryClientPredicateAutoConfiguration.class))
 			.withPropertyValues(properties);
 	}
 
 	private void setupWithFilteredClassLoader(Class cls, String... properties) {
 		applicationContextRunner = new ApplicationContextRunner()
-			.withConfiguration(AutoConfigurations.of(KubernetesDiscoveryClientAutoConfiguration.class,
+			.withConfiguration(AutoConfigurations.of(Fabric8KubernetesDiscoveryClientAutoConfiguration.class,
 					Fabric8AutoConfiguration.class, KubernetesCommonsAutoConfiguration.class,
-					KubernetesDiscoveryPropertiesAutoConfiguration.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/Fabric8KubernetesDiscoveryClientAutoConfigurationPropertiesTests.java
similarity index 79%
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 9a2299cf6b..f951f6f732 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
@@ -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;
@@ -41,7 +42,7 @@
  * @author Ryan Dawson
  * @author Tim Ysewyn
  */
-class KubernetesDiscoveryClientAutoConfigurationPropertiesTests {
+class Fabric8KubernetesDiscoveryClientAutoConfigurationPropertiesTests {
 
 	private ConfigurableApplicationContext context;
 
@@ -56,34 +57,35 @@ 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,
-				KubernetesDiscoveryPropertiesAutoConfiguration.class)
-			.web(org.springframework.boot.WebApplicationType.NONE)
+				KubernetesClientTestConfiguration.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/KubernetesDiscoveryClientAutoConfigurationTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientAutoConfigurationTests.java
similarity index 90%
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 a538788316..4de1233d6d 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;
@@ -39,7 +39,8 @@ 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/Fabric8KubernetesDiscoveryClientConfigClientBootstrapConfigurationTests.java
similarity index 90%
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 b153dd0386..aa294e6209 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;
 
@@ -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/Fabric8KubernetesDiscoveryClientFilterMetadataTest.java
similarity index 74%
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 ad8d2c84b2..769988aee9 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
@@ -45,7 +45,9 @@
 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.cloud.kubernetes.commons.discovery.ServicePortSecureResolver;
 import org.springframework.core.env.Environment;
 import org.springframework.mock.env.MockEnvironment;
 
@@ -59,7 +61,13 @@
 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);
+
+	private static final KubernetesNamespaceProvider NAMESPACE_PROVIDER = new KubernetesNamespaceProvider(
+			mockEnvironment());
 
 	private static final KubernetesClient CLIENT = Mockito.mock(KubernetesClient.class);
 
@@ -83,15 +91,16 @@ 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());
+		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 = discoveryClient.getInstances(serviceId);
+		List instances = client.getInstances(serviceId);
 		assertThat(instances).hasSize(1);
 		assertThat(instances.get(0).getMetadata()).isEqualTo(Map.of("k8s_namespace", "ns", "type", "ClusterIP"));
 	}
@@ -102,15 +111,16 @@ 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());
+		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 = discoveryClient.getInstances(serviceId);
+		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"), entry("type", "ClusterIP"));
@@ -122,15 +132,16 @@ 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());
+		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 = discoveryClient.getInstances(serviceId);
+		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"), entry("type", "ClusterIP"));
@@ -142,15 +153,16 @@ 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());
+		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 = discoveryClient.getInstances(serviceId);
+		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"), entry("type", "ClusterIP"));
@@ -162,15 +174,16 @@ 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());
+		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 = discoveryClient.getInstances(serviceId);
+		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"), entry("type", "ClusterIP"));
@@ -182,15 +195,16 @@ 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());
+		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 = discoveryClient.getInstances(serviceId);
+		List instances = client.getInstances(serviceId);
 		assertThat(instances).hasSize(1);
 		assertThat(instances.get(0).getMetadata()).containsOnly(entry("http", "80"), entry("k8s_namespace", "test"),
 				entry("", "5555"), entry("type", "ClusterIP"));
@@ -202,15 +216,16 @@ 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());
+		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 = discoveryClient.getInstances(serviceId);
+		List instances = client.getInstances(serviceId);
 		assertThat(instances).hasSize(1);
 		assertThat(instances.get(0).getMetadata()).containsOnly(entry("p_http", "80"), entry("k8s_namespace", "ns"),
 				entry("p_", "5555"), entry("type", "ClusterIP"));
@@ -222,15 +237,16 @@ 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());
+		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 = discoveryClient.getInstances(serviceId);
+		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"), entry("type", "ClusterIP"),
@@ -307,10 +323,10 @@ private List getEndpointPorts(Map ports) {
 		}).collect(toList());
 	}
 
-	private static Environment withClientNamespace() {
-		MockEnvironment mockEnvironment = new MockEnvironment();
-		mockEnvironment.setProperty("spring.cloud.kubernetes.client.namespace", "test");
-		return mockEnvironment;
+	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/Fabric8KubernetesDiscoveryClientFilterTest.java
similarity index 56%
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 a004aabdb0..71a2218215 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
@@ -26,25 +26,42 @@
 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.cloud.kubernetes.commons.discovery.ServicePortSecureResolver;
+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;
 
-class KubernetesDiscoveryClientFilterTest {
+@SuppressWarnings("unchecked")
+class Fabric8KubernetesDiscoveryClientFilterTest {
 
-	private final KubernetesClient kubernetesClient = Mockito.mock(KubernetesClient.class);
+	private static final ServicePortSecureResolver SERVICE_PORT_SECURE_RESOLVER = new ServicePortSecureResolver(
+			KubernetesDiscoveryProperties.DEFAULT);
+
+	private static final KubernetesNamespaceProvider NAMESPACE_PROVIDER = new KubernetesNamespaceProvider(
+			mockEnvironment());
 
-	private final KubernetesClientServicesFunction kubernetesClientServicesFunction = KubernetesClient::services;
+	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");
@@ -59,15 +76,19 @@ 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);
-		KubernetesDiscoveryClient client = new KubernetesDiscoveryClient(this.kubernetesClient, properties,
-				this.kubernetesClientServicesFunction);
-
+				KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, true, false);
+		Fabric8KubernetesDiscoveryClient client = new Fabric8KubernetesDiscoveryClient(kubernetesClient, properties,
+				SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER,
+				new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties));
 		List filteredServices = client.getServices();
 		assertThat(filteredServices).isEqualTo(springBootServiceNames);
 
@@ -87,15 +108,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);
-		KubernetesDiscoveryClient client = new KubernetesDiscoveryClient(this.kubernetesClient, properties,
-				this.kubernetesClientServicesFunction);
-
+				KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, true, false);
+		Fabric8KubernetesDiscoveryClient client = new Fabric8KubernetesDiscoveryClient(kubernetesClient, properties,
+				SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER,
+				new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties));
 		List filteredServices = client.getServices();
 		assertThat(filteredServices).isEqualTo(springBootServiceNames);
 
@@ -108,13 +133,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);
-		KubernetesDiscoveryClient client = new KubernetesDiscoveryClient(this.kubernetesClient, properties,
-				this.kubernetesClientServicesFunction);
+				false, "", Set.of(), Map.of(), null, KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, true, false);
+		Fabric8KubernetesDiscoveryClient client = new Fabric8KubernetesDiscoveryClient(kubernetesClient, properties,
+				SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER,
+				new Fabric8DiscoveryClientPredicateAutoConfiguration().predicate(properties));
 
 		List filteredServices = client.getServices();
 
@@ -135,4 +165,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;
+	}
+
 }
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 38424e88df..a06b79a536 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
@@ -69,7 +71,8 @@ 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((String) null), a -> true);
 
 		List serviceInstances = discoveryClient.getInstances("no-port-name-service");
 		Assertions.assertEquals(serviceInstances.size(), 1);
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 1c6cdf14a6..c7c3263fee 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
@@ -37,9 +37,12 @@
 
 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.cloud.kubernetes.commons.discovery.ServicePortSecureResolver;
+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;
@@ -47,6 +50,12 @@
 @EnableKubernetesMockClient(crud = true, https = false)
 class Fabric8KubernetesDiscoveryClientTest {
 
+	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
@@ -97,9 +106,8 @@ void getInstancesShouldBeAbleToHandleEndpointsSingleAddress() {
 
 		mockClient.services().inNamespace("test").resource(service).create();
 
-		DiscoveryClient discoveryClient = new KubernetesDiscoveryClient(mockClient,
-				KubernetesDiscoveryProperties.DEFAULT, KubernetesClient::services, null,
-				new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT));
+		DiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient,
+				KubernetesDiscoveryProperties.DEFAULT, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true);
 
 		List instances = discoveryClient.getInstances("endpoint");
 
@@ -145,10 +153,10 @@ 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));
+		DiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, properties,
+				SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true);
 
 		List instances = discoveryClient.getInstances("endpoint");
 
@@ -189,9 +197,11 @@ void getEndPointsListTest() {
 		mockClient.endpoints().inNamespace("test").resource(endPoint).create();
 		mockClient.services().inNamespace("test").resource(service).create();
 
-		KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(mockClient,
-				KubernetesDiscoveryProperties.DEFAULT, KubernetesClient::services, null,
-				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);
 
 		List result_endpoints = discoveryClient.getEndPointsList("endpoint");
 
@@ -232,10 +242,10 @@ void getEndPointsListTestAllNamespaces() {
 		mockClient.services().inNamespace(namespace2).resource(service2).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, x -> true, new ServicePortSecureResolver(properties));
+		Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, properties,
+				SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true);
 
 		List result_endpoints = discoveryClient.getEndPointsList("endpoint");
 
@@ -290,10 +300,10 @@ 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));
+		Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, properties,
+				SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true);
 
 		List result_endpoints = discoveryClient.getEndPointsList("endpoint");
 
@@ -342,10 +352,10 @@ 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));
+		Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, properties,
+				new ServicePortSecureResolver(properties), NAMESPACE_PROVIDER, x -> true);
 
 		List instances = discoveryClient.getInstances("endpoint");
 
@@ -383,9 +393,8 @@ void getServicesShouldReturnAllServicesWhenNoLabelsAreAppliedToTheClient() {
 		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));
+		Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient,
+				KubernetesDiscoveryProperties.DEFAULT, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true);
 
 		List services = discoveryClient.getServices();
 
@@ -414,10 +423,8 @@ void getServicesShouldReturnOnlyMatchingServicesWhenLabelsAreAppliedToTheClient(
 		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));
+		Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient,
+				KubernetesDiscoveryProperties.DEFAULT, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true);
 
 		List services = discoveryClient.getServices();
 
@@ -455,10 +462,10 @@ 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));
+		Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, properties,
+				SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true);
 
 		List services = discoveryClient.getServices();
 
@@ -520,10 +527,10 @@ 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));
+		Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, properties,
+				SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true);
 
 		List instances = discoveryClient.getInstances("endpoint");
 
@@ -553,9 +560,8 @@ void instanceWithoutSubsetsShouldBeSkipped() {
 
 		mockClient.endpoints().inNamespace("test").resource(endPoint).create();
 
-		KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(mockClient,
-				KubernetesDiscoveryProperties.DEFAULT, KubernetesClient::services, null,
-				new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT));
+		Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient,
+				KubernetesDiscoveryProperties.DEFAULT, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true);
 
 		List instances = discoveryClient.getInstances("endpoint1");
 
@@ -597,10 +603,10 @@ 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));
+		Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, properties,
+				new ServicePortSecureResolver(properties), NAMESPACE_PROVIDER, x -> true);
 
 		List instances = discoveryClient.getInstances("endpoint2");
 
@@ -650,10 +656,10 @@ 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));
+		Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, properties,
+				new ServicePortSecureResolver(properties), NAMESPACE_PROVIDER, x -> true);
 
 		List instances = discoveryClient.getInstances("endpoint3");
 
@@ -702,10 +708,10 @@ 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));
+		Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, properties,
+				new ServicePortSecureResolver(properties), NAMESPACE_PROVIDER, x -> true);
 
 		List instances = discoveryClient.getInstances("endpoint4");
 
@@ -752,10 +758,10 @@ 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));
+		Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, properties,
+				new ServicePortSecureResolver(properties), NAMESPACE_PROVIDER, x -> true);
 
 		List instances = discoveryClient.getInstances("endpoint5");
 
@@ -803,9 +809,8 @@ void instanceWithMultiplePortsAndWithoutPrimaryPortNameSpecifiedOrHttpsPortShoul
 
 		mockClient.services().inNamespace("test").resource(service).create();
 
-		DiscoveryClient discoveryClient = new KubernetesDiscoveryClient(mockClient,
-				KubernetesDiscoveryProperties.DEFAULT, KubernetesClient::services, null,
-				new ServicePortSecureResolver(KubernetesDiscoveryProperties.DEFAULT));
+		Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient,
+				KubernetesDiscoveryProperties.DEFAULT, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true);
 
 		List instances = discoveryClient.getInstances("endpoint5");
 
@@ -853,10 +858,10 @@ 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));
+		Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, properties,
+				new ServicePortSecureResolver(properties), NAMESPACE_PROVIDER, x -> true);
 
 		List instances = discoveryClient.getInstances("endpoint5");
 
@@ -904,8 +909,8 @@ public void instanceWithoutPorts() {
 
 		final KubernetesDiscoveryProperties properties = KubernetesDiscoveryProperties.DEFAULT;
 
-		final DiscoveryClient discoveryClient = new KubernetesDiscoveryClient(mockClient, properties,
-				KubernetesClient::services, null, new ServicePortSecureResolver(properties));
+		final DiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(mockClient, properties,
+				new ServicePortSecureResolver(properties), NAMESPACE_PROVIDER, x -> true);
 
 		final List instances = discoveryClient.getInstances("endpoint5");
 
@@ -920,4 +925,10 @@ public void instanceWithoutPorts() {
 			.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/Fabric8KubernetesDiscoveryClientTests.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesDiscoveryClientTests.java
index 41aee5673a..2c5cb1181b 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
@@ -73,9 +73,10 @@ 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);
+		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"));
@@ -99,9 +100,10 @@ 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);
+		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"));
@@ -125,9 +127,10 @@ 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);
+		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"));
@@ -150,9 +153,10 @@ 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);
+		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"));
@@ -179,9 +183,10 @@ 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);
+		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"));
@@ -208,9 +213,10 @@ 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);
+		Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties,
+				null, null, null);
 		List result = discoveryClient.getEndPointsList("service-one");
 		Assertions.assertEquals(result.size(), 2);
 		Assertions.assertEquals(
@@ -234,7 +240,8 @@ void testClientNamespaceEmpty(CapturedOutput output) {
 		KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces,
 				true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false, 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"));
@@ -258,9 +265,10 @@ 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);
+		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"));
@@ -286,7 +294,8 @@ void testClientNamespaceSingleEndpointsMatchPartialLabels(CapturedOutput output)
 		KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces,
 				true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false, 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"));
@@ -309,9 +318,10 @@ 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);
+		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"));
@@ -340,7 +350,8 @@ void testClientNamespaceTwoEndpointsOneMatches(CapturedOutput output) {
 		KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces,
 				true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false, 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"));
@@ -367,9 +378,10 @@ 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);
+		Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties,
+				null, null, null);
 		List result = discoveryClient.getEndPointsList("service-one");
 		Assertions.assertEquals(result.size(), 1);
 		Assertions.assertEquals(
@@ -393,7 +405,8 @@ void testSelectiveNamespacesEmpty(CapturedOutput output) {
 		KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces,
 				true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false, 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]"));
@@ -417,10 +430,10 @@ 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, x -> true,
-				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]"));
@@ -448,9 +461,10 @@ 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);
+		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"));
@@ -483,7 +497,8 @@ void testSelectiveNamespacesMultipleNamespacesAllMatch(CapturedOutput output) {
 		KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, allNamespaces, namespaces,
 				true, 60L, false, "", Set.of(), serviceLabels, "", null, 0, false, 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));
@@ -515,11 +530,11 @@ void testGetServicesWithExternalNameService() {
 			.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);
+				60L, false, "", Set.of(), Map.of(), "", KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, false, true);
 
-		KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(client, properties, null, null, null);
+		Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties,
+				null, null, x -> true);
 		List result = discoveryClient.getServices();
 		Assertions.assertEquals(result.size(), 1);
 		Assertions.assertEquals(result.get(0), "blue-service");
@@ -543,7 +558,8 @@ void testExternalNameService() {
 		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);
+		Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties,
+				null, null, null);
 		List result = discoveryClient.getInstances("blue-service");
 		Assertions.assertEquals(result.size(), 1);
 		DefaultKubernetesServiceInstance externalNameServiceInstance = (DefaultKubernetesServiceInstance) result.get(0);
@@ -593,7 +609,8 @@ void testPodMetadata() {
 		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);
+		Fabric8KubernetesDiscoveryClient discoveryClient = new Fabric8KubernetesDiscoveryClient(client, properties,
+				null, null, null);
 		List result = discoveryClient.getInstances("blue-service");
 		Assertions.assertEquals(result.size(), 1);
 		DefaultKubernetesServiceInstance serviceInstance = (DefaultKubernetesServiceInstance) result.get(0);
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 30e0ae52ba..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
@@ -20,6 +20,8 @@
 import java.util.Map;
 import java.util.Set;
 
+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;
@@ -31,7 +33,9 @@
 import org.junit.jupiter.api.AfterEach;
 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.OutputCaptureExtension;
 import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider;
 import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
 import org.springframework.mock.env.MockEnvironment;
@@ -42,6 +46,7 @@
 /**
  * @author wind57
  */
+@ExtendWith(OutputCaptureExtension.class)
 @EnableKubernetesMockClient(crud = true, https = false)
 class Fabric8KubernetesDiscoveryClientUtilsTests {
 
@@ -52,13 +57,9 @@ 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
-	 * 
+ /* + *
 - all-namespaces = true - serviceA present in namespace "A" - serviceB
+	 * present in namespace "B" - no filters are applied, so both are present 
*/ @Test void testServicesAllNamespacesNoFilters() { @@ -74,13 +75,10 @@ void testServicesAllNamespacesNoFilters() { 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
-	 * 
+ /* + *
 - 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() { @@ -98,13 +96,89 @@ void testServicesAllNamespacesNameFilter() { /** *
-	 *     - 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
+	 *      - 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, 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, 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")); + } + + /* + *
 - 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(), 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/Fabric8KubernetesReactiveDiscoveryClientAutoConfigurationApplicationContextTests.java similarity index 61% rename from spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/reactive/KubernetesReactiveDiscoveryClientAutoConfigurationApplicationContextTests.java rename to spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientAutoConfigurationApplicationContextTests.java index a4a36d6e72..1c690c2a92 100644 --- 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/Fabric8KubernetesReactiveDiscoveryClientAutoConfigurationApplicationContextTests.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; @@ -27,39 +27,40 @@ 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} + * {@link Fabric8KubernetesReactiveDiscoveryClientAutoConfiguration} * * @author wind57 */ -class KubernetesReactiveDiscoveryClientAutoConfigurationApplicationContextTests { +class Fabric8KubernetesReactiveDiscoveryClientAutoConfigurationApplicationContextTests { 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); - }); + 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.run(context -> { - assertThat(context).hasSingleBean(KubernetesReactiveDiscoveryClient.class); - assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class); - assertThat(context).hasSingleBean(KubernetesClientServicesFunction.class); - }); + applicationContextRunner + .withConfiguration(AutoConfigurations.of(Fabric8DiscoveryClientPredicateAutoConfiguration.class)) + .run(context -> { + assertThat(context).hasSingleBean(Fabric8KubernetesReactiveDiscoveryClient.class); + assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class); + }); } @Test @@ -67,9 +68,8 @@ 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(Fabric8KubernetesReactiveDiscoveryClient.class); assertThat(context).doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class); - assertThat(context).doesNotHaveBean(KubernetesClientServicesFunction.class); }); } @@ -77,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.run(context -> { - assertThat(context).hasSingleBean(KubernetesReactiveDiscoveryClient.class); - assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class); - assertThat(context).hasSingleBean(KubernetesClientServicesFunction.class); - }); + applicationContextRunner + .withConfiguration(AutoConfigurations.of(Fabric8DiscoveryClientPredicateAutoConfiguration.class)) + .run(context -> { + assertThat(context).hasSingleBean(Fabric8KubernetesReactiveDiscoveryClient.class); + assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class); + }); } @Test @@ -89,9 +90,8 @@ 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(Fabric8KubernetesReactiveDiscoveryClient.class); assertThat(context).doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class); - assertThat(context).doesNotHaveBean(KubernetesClientServicesFunction.class); }); } @@ -99,11 +99,12 @@ void kubernetesDiscoveryDisabled() { 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); - }); + applicationContextRunner + .withConfiguration(AutoConfigurations.of(Fabric8DiscoveryClientPredicateAutoConfiguration.class)) + .run(context -> { + assertThat(context).hasSingleBean(Fabric8KubernetesReactiveDiscoveryClient.class); + assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class); + }); } @Test @@ -111,9 +112,8 @@ 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(Fabric8KubernetesReactiveDiscoveryClient.class); assertThat(context).doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class); - assertThat(context).doesNotHaveBean(KubernetesClientServicesFunction.class); }); } @@ -124,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.run(context -> { - assertThat(context).hasSingleBean(KubernetesReactiveDiscoveryClient.class); - assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class); - assertThat(context).hasSingleBean(KubernetesClientServicesFunction.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.run(context -> { - assertThat(context).hasSingleBean(KubernetesReactiveDiscoveryClient.class); - assertThat(context).doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class); - assertThat(context).hasSingleBean(KubernetesClientServicesFunction.class); - }); + applicationContextRunner + .withConfiguration(AutoConfigurations.of(Fabric8DiscoveryClientPredicateAutoConfiguration.class)) + .run(context -> { + assertThat(context).hasSingleBean(Fabric8KubernetesReactiveDiscoveryClient.class); + assertThat(context).doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class); + }); } @Test @@ -147,18 +149,19 @@ 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); - }); + 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, KubernetesReactiveDiscoveryClientAutoConfiguration.class, + Fabric8AutoConfiguration.class, Fabric8KubernetesReactiveDiscoveryClientAutoConfiguration.class, KubernetesDiscoveryPropertiesAutoConfiguration.class)) .withPropertyValues(properties); } @@ -167,7 +170,7 @@ private void setupWithFilteredClassLoader(String name, String... properties) { applicationContextRunner = new ApplicationContextRunner() .withConfiguration(AutoConfigurations.of(UtilAutoConfiguration.class, ReactiveCommonsClientAutoConfiguration.class, KubernetesCommonsAutoConfiguration.class, - Fabric8AutoConfiguration.class, KubernetesReactiveDiscoveryClientAutoConfiguration.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/Fabric8KubernetesReactiveDiscoveryClientAutoConfigurationTests.java similarity index 86% 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/Fabric8KubernetesReactiveDiscoveryClientAutoConfigurationTests.java index fd18eb7845..7c10a1e280 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/Fabric8KubernetesReactiveDiscoveryClientAutoConfigurationTests.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,28 +28,29 @@ 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 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, ReactiveCommonsClientAutoConfiguration.class, KubernetesCommonsAutoConfiguration.class, - Fabric8AutoConfiguration.class, KubernetesDiscoveryClientAutoConfiguration.class, - KubernetesReactiveDiscoveryClientAutoConfiguration.class, + Fabric8AutoConfiguration.class, Fabric8KubernetesDiscoveryClientAutoConfiguration.class, + Fabric8KubernetesReactiveDiscoveryClientAutoConfiguration.class, KubernetesDiscoveryPropertiesAutoConfiguration.class)); @Test void shouldWorkWithDefaults() { - contextRunner.withPropertyValues("spring.main.cloud-platform=KUBERNETES").run(context -> { - assertThat(context).hasSingleBean(ReactiveDiscoveryClient.class); - assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class); - }); + contextRunner.withPropertyValues("spring.main.cloud-platform=KUBERNETES") + .withConfiguration(AutoConfigurations.of(Fabric8DiscoveryClientPredicateAutoConfiguration.class)) + .run(context -> { + assertThat(context).hasSingleBean(ReactiveDiscoveryClient.class); + assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class); + }); } @Test @@ -99,6 +100,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); 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/Fabric8KubernetesReactiveDiscoveryClientTests.java similarity index 74% rename from spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/reactive/KubernetesReactiveDiscoveryClientTests.java rename to spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8KubernetesReactiveDiscoveryClientTests.java index f2241b1e47..1dc534b766 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/Fabric8KubernetesReactiveDiscoveryClientTests.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 java.util.ArrayList; import java.util.List; @@ -40,7 +40,11 @@ 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.cloud.kubernetes.commons.discovery.ServicePortSecureResolver; +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; @@ -50,7 +54,13 @@ * @author Tim Ysewyn */ @EnableKubernetesMockClient(crud = true, https = false) -class KubernetesReactiveDiscoveryClientTests { +class Fabric8KubernetesReactiveDiscoveryClientTests { + + 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; @@ -74,8 +84,10 @@ void afterEach() { @Test void verifyDefaults() { - ReactiveDiscoveryClient client = new KubernetesReactiveDiscoveryClient(kubernetesClient, - KubernetesDiscoveryProperties.DEFAULT, KubernetesClient::services); + Fabric8KubernetesDiscoveryClient fabric8KubernetesDiscoveryClient = new Fabric8KubernetesDiscoveryClient( + 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); } @@ -105,8 +117,10 @@ void shouldReturnFluxOfServices() { .endItem() .build()) .once(); - ReactiveDiscoveryClient client = new KubernetesReactiveDiscoveryClient(kubernetesClient, - KubernetesDiscoveryProperties.DEFAULT, KubernetesClient::services); + Fabric8KubernetesDiscoveryClient fabric8KubernetesDiscoveryClient = new Fabric8KubernetesDiscoveryClient( + 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(); } @@ -119,8 +133,10 @@ void shouldReturnEmptyFluxOfServicesWhenNoInstancesFound() { .andReturn(200, new ServiceListBuilder().build()) .once(); - ReactiveDiscoveryClient client = new KubernetesReactiveDiscoveryClient(kubernetesClient, - KubernetesDiscoveryProperties.DEFAULT, KubernetesClient::services); + Fabric8KubernetesDiscoveryClient fabric8KubernetesDiscoveryClient = new Fabric8KubernetesDiscoveryClient( + 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(); } @@ -133,8 +149,11 @@ void shouldReturnEmptyFluxForNonExistingService() { .andReturn(200, new EndpointsBuilder().build()) .once(); - ReactiveDiscoveryClient client = new KubernetesReactiveDiscoveryClient(kubernetesClient, - KubernetesDiscoveryProperties.DEFAULT, KubernetesClient::services); + Fabric8KubernetesDiscoveryClient fabric8KubernetesDiscoveryClient = new Fabric8KubernetesDiscoveryClient( + kubernetesClient, KubernetesDiscoveryProperties.DEFAULT, SERVICE_PORT_SECURE_RESOLVER, + NAMESPACE_PROVIDER, x -> true); + + ReactiveDiscoveryClient client = new Fabric8KubernetesReactiveDiscoveryClient(fabric8KubernetesDiscoveryClient); Flux instances = client.getInstances("nonexistent-service"); StepVerifier.create(instances).expectNextCount(0).expectComplete().verify(); } @@ -160,8 +179,11 @@ void shouldReturnEmptyFluxWhenServiceHasNoSubsets() { .andReturn(200, new EndpointsBuilder().build()) .once(); - ReactiveDiscoveryClient client = new KubernetesReactiveDiscoveryClient(kubernetesClient, - KubernetesDiscoveryProperties.DEFAULT, KubernetesClient::services); + Fabric8KubernetesDiscoveryClient fabric8KubernetesDiscoveryClient = new Fabric8KubernetesDiscoveryClient( + kubernetesClient, KubernetesDiscoveryProperties.DEFAULT, SERVICE_PORT_SECURE_RESOLVER, + NAMESPACE_PROVIDER, x -> true); + + ReactiveDiscoveryClient client = new Fabric8KubernetesReactiveDiscoveryClient(fabric8KubernetesDiscoveryClient); Flux instances = client.getInstances("existing-service"); StepVerifier.create(instances).expectNextCount(0).expectComplete().verify(); } @@ -212,10 +234,12 @@ void shouldReturnFlux() { .andReturn(200, services.getItems().get(0)) .once(); - kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services").andReturn(200, services).once(); + Fabric8KubernetesDiscoveryClient fabric8KubernetesDiscoveryClient = new Fabric8KubernetesDiscoveryClient( + kubernetesClient, KubernetesDiscoveryProperties.DEFAULT, SERVICE_PORT_SECURE_RESOLVER, + NAMESPACE_PROVIDER, x -> true); - ReactiveDiscoveryClient client = new KubernetesReactiveDiscoveryClient(kubernetesClient, - KubernetesDiscoveryProperties.DEFAULT, KubernetesClient::services); + // 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(); } @@ -275,8 +299,11 @@ void shouldReturnFluxWithPrefixedMetadata() { .build()) .once(); - ReactiveDiscoveryClient client = new KubernetesReactiveDiscoveryClient(kubernetesClient, - KubernetesDiscoveryProperties.DEFAULT, KubernetesClient::services); + Fabric8KubernetesDiscoveryClient fabric8KubernetesDiscoveryClient = new Fabric8KubernetesDiscoveryClient( + kubernetesClient, KubernetesDiscoveryProperties.DEFAULT, SERVICE_PORT_SECURE_RESOLVER, + NAMESPACE_PROVIDER, x -> true); + + ReactiveDiscoveryClient client = new Fabric8KubernetesReactiveDiscoveryClient(fabric8KubernetesDiscoveryClient); Flux instances = client.getInstances("existing-service"); StepVerifier.create(instances).expectNextCount(1).expectComplete().verify(); } @@ -337,8 +364,11 @@ void shouldReturnFluxWhenServiceHasMultiplePortsAndPrimaryPortNameIsSet() { .build()) .once(); - ReactiveDiscoveryClient client = new KubernetesReactiveDiscoveryClient(kubernetesClient, - KubernetesDiscoveryProperties.DEFAULT, KubernetesClient::services); + Fabric8KubernetesDiscoveryClient fabric8KubernetesDiscoveryClient = new Fabric8KubernetesDiscoveryClient( + kubernetesClient, KubernetesDiscoveryProperties.DEFAULT, SERVICE_PORT_SECURE_RESOLVER, + NAMESPACE_PROVIDER, x -> true); + + ReactiveDiscoveryClient client = new Fabric8KubernetesReactiveDiscoveryClient(fabric8KubernetesDiscoveryClient); Flux instances = client.getInstances("existing-service"); StepVerifier.create(instances).expectNextCount(1).expectComplete().verify(); } @@ -397,11 +427,19 @@ 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); - ReactiveDiscoveryClient client = new KubernetesReactiveDiscoveryClient(kubernetesClient, properties, - KubernetesClient::services); + false, null, Set.of(), Map.of(), "https_tcp", Metadata.DEFAULT, 0, true, false); + Fabric8KubernetesDiscoveryClient fabric8KubernetesDiscoveryClient = new Fabric8KubernetesDiscoveryClient( + kubernetesClient, properties, SERVICE_PORT_SECURE_RESOLVER, NAMESPACE_PROVIDER, x -> true); + + ReactiveDiscoveryClient client = new Fabric8KubernetesReactiveDiscoveryClient(fabric8KubernetesDiscoveryClient); Flux instances = client.getInstances("existing-service"); StepVerifier.create(instances).expectNextCount(1).expectComplete().verify(); } + private static Environment mockEnvironment() { + MockEnvironment mockEnvironment = new MockEnvironment(); + mockEnvironment.setProperty("spring.cloud.kubernetes.client.namespace", "test"); + return mockEnvironment; + } + } 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 8bc9394126..cc8d26ad2e 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 @@ -90,7 +90,7 @@ void testMapperSecureNullLabelsAndAnnotations() { KubernetesLoadBalancerProperties properties = new KubernetesLoadBalancerProperties(); KubernetesDiscoveryProperties discoveryProperties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60, false, null, Set.of(443, 8443), Map.of(), null, - KubernetesDiscoveryProperties.Metadata.DEFAULT, 0, false); + 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); 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 { 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 { 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 90% 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 751b2b8e0b..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; @@ -23,7 +23,7 @@ * @author wind57 */ @SpringBootApplication -class Fabric8DiscoveryApp { +public class Fabric8DiscoveryApp { public static void main(String[] args) { SpringApplication.run(Fabric8DiscoveryApp.class, args); diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/discovery/Fabric8DiscoveryBase.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/discovery/Fabric8DiscoveryBase.java index 0b385736e3..aabb6b28f2 100644 --- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/discovery/Fabric8DiscoveryBase.java +++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/discovery/Fabric8DiscoveryBase.java @@ -26,6 +26,7 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.TestConfiguration; import org.springframework.boot.test.system.OutputCaptureExtension; +import org.springframework.cloud.kubernetes.fabric8.Fabric8DiscoveryApp; import org.springframework.cloud.kubernetes.integration.tests.commons.Commons; import org.springframework.cloud.kubernetes.integration.tests.commons.fabric8_client.Util; import org.springframework.context.annotation.Bean;