fix (#1230)
This commit is contained in:
@@ -104,7 +104,7 @@ public class KubernetesDiscoveryClient implements DiscoveryClient {
|
||||
Objects.requireNonNull(serviceId);
|
||||
|
||||
List<EndpointSubsetNS> subsetsNS = getEndPointsList(serviceId).stream()
|
||||
.map(x -> subsetsFromEndpoints(x, () -> client.getNamespace())).toList();
|
||||
.map(KubernetesDiscoveryClientUtils::subsetsFromEndpoints).toList();
|
||||
|
||||
List<ServiceInstance> instances = new ArrayList<>();
|
||||
if (!subsetsNS.isEmpty()) {
|
||||
@@ -131,7 +131,7 @@ public class KubernetesDiscoveryClient implements DiscoveryClient {
|
||||
private List<Endpoints> findEndPointsFilteredByNamespaces(String serviceId) {
|
||||
List<Endpoints> endpoints = new ArrayList<>();
|
||||
for (String ns : properties.namespaces()) {
|
||||
endpoints.addAll(getClient().endpoints().inNamespace(ns).withField("metadata.name", serviceId)
|
||||
endpoints.addAll(client.endpoints().inNamespace(ns).withField("metadata.name", serviceId)
|
||||
.withLabels(properties.serviceLabels()).list().getItems());
|
||||
}
|
||||
return endpoints;
|
||||
|
||||
@@ -20,7 +20,6 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import io.fabric8.kubernetes.api.model.EndpointPort;
|
||||
@@ -49,11 +48,8 @@ final class KubernetesDiscoveryClientUtils {
|
||||
|
||||
}
|
||||
|
||||
static EndpointSubsetNS subsetsFromEndpoints(Endpoints endpoints, Supplier<String> clientNamespace) {
|
||||
if (endpoints != null && endpoints.getSubsets() != null) {
|
||||
return new EndpointSubsetNS(endpoints.getMetadata().getNamespace(), endpoints.getSubsets());
|
||||
}
|
||||
return new EndpointSubsetNS(clientNamespace.get(), List.of());
|
||||
static EndpointSubsetNS subsetsFromEndpoints(Endpoints endpoints) {
|
||||
return new EndpointSubsetNS(endpoints.getMetadata().getNamespace(), endpoints.getSubsets());
|
||||
}
|
||||
|
||||
static int endpointsPort(EndpointSubset endpointSubset, String serviceId, KubernetesDiscoveryProperties properties,
|
||||
|
||||
@@ -46,31 +46,26 @@ import static org.springframework.cloud.kubernetes.commons.discovery.KubernetesD
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
class KubernetesDiscoveryClientUtilsTests {
|
||||
|
||||
@Test
|
||||
void testSubsetsFromEndpointsNullEndpoints() {
|
||||
EndpointSubsetNS result = KubernetesDiscoveryClientUtils.subsetsFromEndpoints(null, () -> "default");
|
||||
Assertions.assertNotNull(result);
|
||||
Assertions.assertEquals(result.endpointSubset(), List.of());
|
||||
Assertions.assertEquals(result.namespace(), "default");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSubsetsFromEndpointsEmptySubsets() {
|
||||
Endpoints endpoints = new EndpointsBuilder()
|
||||
.withMetadata(new ObjectMetaBuilder().withNamespace("non-default").build()).build();
|
||||
EndpointSubsetNS result = KubernetesDiscoveryClientUtils.subsetsFromEndpoints(endpoints, () -> "default");
|
||||
EndpointSubsetNS result = KubernetesDiscoveryClientUtils.subsetsFromEndpoints(endpoints);
|
||||
Assertions.assertNotNull(result);
|
||||
Assertions.assertEquals(result.endpointSubset(), List.of());
|
||||
Assertions.assertEquals(result.namespace(), "non-default");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSubsetsFromEndpointsNullSubsets() {
|
||||
void testSubsetsFromEndpointsNonEmptySubsets() {
|
||||
Endpoints endpoints = new EndpointsBuilder().withSubsets((List<EndpointSubset>) null)
|
||||
.withMetadata(new ObjectMetaBuilder().withNamespace("non-default").build()).build();
|
||||
EndpointSubsetNS result = KubernetesDiscoveryClientUtils.subsetsFromEndpoints(endpoints, () -> "default");
|
||||
.withMetadata(new ObjectMetaBuilder().withNamespace("default").build())
|
||||
.withSubsets(new EndpointSubsetBuilder().withPorts(new EndpointPortBuilder().withPort(8080).build()).build())
|
||||
.build();
|
||||
EndpointSubsetNS result = KubernetesDiscoveryClientUtils.subsetsFromEndpoints(endpoints);
|
||||
Assertions.assertNotNull(result);
|
||||
Assertions.assertEquals(result.endpointSubset(), List.of());
|
||||
Assertions.assertEquals(result.endpointSubset().size(), 1);
|
||||
Assertions.assertEquals(result.endpointSubset().get(0).getPorts().get(0).getPort(), 8080);
|
||||
Assertions.assertEquals(result.namespace(), "default");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user