238: Fix issue with nullable subsets in endpoints (#239)

This commit is contained in:
Roberto Tassi
2018-09-17 21:57:05 +02:00
committed by Spencer Gibb
parent a12eef989a
commit 0aae2cb68c
2 changed files with 26 additions and 1 deletions

View File

@@ -66,7 +66,9 @@ public class KubernetesCatalogWatch implements ApplicationEventPublisherAware {
List<Endpoints> endpoints = kubernetesClient.endpoints().list().getItems();
List<String> endpointsPodNames =
endpoints.stream()
.flatMap(endpoint -> endpoint.getSubsets().stream())
.map(Endpoints::getSubsets)
.filter(Objects::nonNull)
.flatMap(Collection::stream)
.map(EndpointSubset::getAddresses)
.filter(Objects::nonNull)
.flatMap(Collection::stream)

View File

@@ -114,6 +114,21 @@ public class KubernetesCatalogWatchTest {
assertEquals(expectedPodsList, event.getValue());
}
@Test
public void testEndpointsWithoutSubsets() {
EndpointsList endpoints = createSingleEndpointEndpointListWithoutSubsets();
when(endpointsOperation.list()).thenReturn(endpoints);
when(kubernetesClient.endpoints()).thenReturn(endpointsOperation);
underTest.catalogServicesWatch();
// second execution on shuffleServices
underTest.catalogServicesWatch();
verify(applicationEventPublisher).publishEvent(any(HeartbeatEvent.class));
}
@Test
public void testEndpointsWithoutAddresses() {
@@ -157,6 +172,14 @@ public class KubernetesCatalogWatchTest {
return endpointsList;
}
private EndpointsList createSingleEndpointEndpointListWithoutSubsets() {
Endpoints endpoints = new Endpoints();
EndpointsList endpointsList = new EndpointsList();
endpointsList.setItems(Collections.singletonList(endpoints));
return endpointsList;
}
private EndpointsList createSingleEndpointEndpointListByPodName(String... podNames) {
Endpoints endpoints = new Endpoints();
endpoints.setSubsets(createSubsetsByPodName(podNames));