Skip to content

Fix scheduled discovery when allNamespaces property is true #544

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,16 @@ public class KubernetesCatalogWatch implements ApplicationEventPublisherAware {

private final KubernetesClient kubernetesClient;

private final KubernetesDiscoveryProperties properties;

private final AtomicReference<List<String>> catalogEndpointsState = new AtomicReference<>();

private ApplicationEventPublisher publisher;

public KubernetesCatalogWatch(KubernetesClient kubernetesClient) {
public KubernetesCatalogWatch(KubernetesClient kubernetesClient,
KubernetesDiscoveryProperties properties) {
this.kubernetesClient = kubernetesClient;
this.properties = properties;
}

@Override
Expand All @@ -66,8 +70,11 @@ public void catalogServicesWatch() {

// not all pods participate in the service discovery. only those that have
// endpoints.
List<Endpoints> endpoints = this.kubernetesClient.endpoints().list()
.getItems();
List<Endpoints> endpoints = this.properties
.isAllNamespaces()
? this.kubernetesClient.endpoints().inAnyNamespace().list()
.getItems()
: this.kubernetesClient.endpoints().list().getItems();
List<String> endpointsPodNames = endpoints.stream().map(Endpoints::getSubsets)
.filter(Objects::nonNull).flatMap(Collection::stream)
.map(EndpointSubset::getAddresses).filter(Objects::nonNull)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ public class KubernetesCatalogWatchAutoConfiguration {
@ConditionalOnProperty(
name = "spring.cloud.kubernetes.discovery.catalog-services-watch.enabled",
matchIfMissing = true)
public KubernetesCatalogWatch kubernetesCatalogWatch(KubernetesClient client) {
return new KubernetesCatalogWatch(client);
public KubernetesCatalogWatch kubernetesCatalogWatch(KubernetesClient client,
KubernetesDiscoveryProperties properties) {
return new KubernetesCatalogWatch(client, properties);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ public class KubernetesCatalogWatchTest {
@Mock
private KubernetesClient kubernetesClient;

@Mock
private KubernetesDiscoveryProperties kubernetesDiscoveryProperties;

@Mock
private ApplicationEventPublisher applicationEventPublisher;

Expand Down