Skip to content

Commit d691f13

Browse files
tzorattoThomas Zoratto
and
Thomas Zoratto
authored
Fix scheduled discovery when allNamespaces property is true (spring-cloud#544)
Co-authored-by: Thomas Zoratto <[email protected]>
1 parent 7d78d64 commit d691f13

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

spring-cloud-kubernetes-discovery/src/main/java/org/springframework/cloud/kubernetes/discovery/KubernetesCatalogWatch.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,16 @@ public class KubernetesCatalogWatch implements ApplicationEventPublisherAware {
4545

4646
private final KubernetesClient kubernetesClient;
4747

48+
private final KubernetesDiscoveryProperties properties;
49+
4850
private final AtomicReference<List<String>> catalogEndpointsState = new AtomicReference<>();
4951

5052
private ApplicationEventPublisher publisher;
5153

52-
public KubernetesCatalogWatch(KubernetesClient kubernetesClient) {
54+
public KubernetesCatalogWatch(KubernetesClient kubernetesClient,
55+
KubernetesDiscoveryProperties properties) {
5356
this.kubernetesClient = kubernetesClient;
57+
this.properties = properties;
5458
}
5559

5660
@Override
@@ -66,8 +70,11 @@ public void catalogServicesWatch() {
6670

6771
// not all pods participate in the service discovery. only those that have
6872
// endpoints.
69-
List<Endpoints> endpoints = this.kubernetesClient.endpoints().list()
70-
.getItems();
73+
List<Endpoints> endpoints = this.properties
74+
.isAllNamespaces()
75+
? this.kubernetesClient.endpoints().inAnyNamespace().list()
76+
.getItems()
77+
: this.kubernetesClient.endpoints().list().getItems();
7178
List<String> endpointsPodNames = endpoints.stream().map(Endpoints::getSubsets)
7279
.filter(Objects::nonNull).flatMap(Collection::stream)
7380
.map(EndpointSubset::getAddresses).filter(Objects::nonNull)

spring-cloud-kubernetes-discovery/src/main/java/org/springframework/cloud/kubernetes/discovery/KubernetesCatalogWatchAutoConfiguration.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ public class KubernetesCatalogWatchAutoConfiguration {
4242
@ConditionalOnProperty(
4343
name = "spring.cloud.kubernetes.discovery.catalog-services-watch.enabled",
4444
matchIfMissing = true)
45-
public KubernetesCatalogWatch kubernetesCatalogWatch(KubernetesClient client) {
46-
return new KubernetesCatalogWatch(client);
45+
public KubernetesCatalogWatch kubernetesCatalogWatch(KubernetesClient client,
46+
KubernetesDiscoveryProperties properties) {
47+
return new KubernetesCatalogWatch(client, properties);
4748
}
4849

4950
}

spring-cloud-kubernetes-discovery/src/test/java/org/springframework/cloud/kubernetes/discovery/KubernetesCatalogWatchTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ public class KubernetesCatalogWatchTest {
5757
@Mock
5858
private KubernetesClient kubernetesClient;
5959

60+
@Mock
61+
private KubernetesDiscoveryProperties kubernetesDiscoveryProperties;
62+
6063
@Mock
6164
private ApplicationEventPublisher applicationEventPublisher;
6265

0 commit comments

Comments
 (0)