-
Notifications
You must be signed in to change notification settings - Fork 1k
move ports metadata computation to the dedicated method #1231
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
Changes from 2 commits
0c3ec3e
f143df6
7fc0bb9
01596ee
5cad385
2d2152a
f09961d
164c0a1
436fd0c
0f4d015
3ef6fa1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,9 +42,9 @@ | |
import static java.util.stream.Collectors.toMap; | ||
import static org.springframework.cloud.kubernetes.commons.config.ConfigUtils.keysWithPrefix; | ||
import static org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryConstants.NAMESPACE_METADATA_KEY; | ||
import static org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientUtils.endpoints; | ||
import static org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientUtils.endpointsPort; | ||
import static org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientUtils.serviceMetadata; | ||
import static org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientUtils.subsetsFromEndpoints; | ||
|
||
/** | ||
* Kubernetes implementation of {@link DiscoveryClient}. | ||
|
@@ -104,37 +104,34 @@ public List<ServiceInstance> getInstances(String serviceId) { | |
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()) { | ||
for (EndpointSubsetNS es : subsetsNS) { | ||
instances.addAll(getNamespaceServiceInstances(es, serviceId)); | ||
} | ||
for (EndpointSubsetNS es : subsetsNS) { | ||
instances.addAll(getNamespaceServiceInstances(es, serviceId)); | ||
} | ||
|
||
return instances; | ||
} | ||
|
||
public List<Endpoints> getEndPointsList(String serviceId) { | ||
if (properties.allNamespaces()) { | ||
return client.endpoints().inAnyNamespace().withField("metadata.name", serviceId) | ||
.withLabels(properties.serviceLabels()).list().getItems(); | ||
LOG.debug(() -> "searching for endpoints in all namespaces"); | ||
return endpoints(client.endpoints().inAnyNamespace().withNewFilter(), properties, serviceId); | ||
} | ||
if (properties.namespaces().isEmpty()) { | ||
return client.endpoints().withField("metadata.name", serviceId).withLabels(properties.serviceLabels()) | ||
.list().getItems(); | ||
else if (properties.namespaces().isEmpty()) { | ||
LOG.debug(() -> "searching for endpoints in namespace : " + client.getNamespace()); | ||
return endpoints(client.endpoints().withNewFilter(), properties, serviceId); | ||
} | ||
return findEndPointsFilteredByNamespaces(serviceId); | ||
} | ||
|
||
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) | ||
.withLabels(properties.serviceLabels()).list().getItems()); | ||
else { | ||
LOG.debug(() -> "searching for endpoints in namespaces : " + properties.namespaces()); | ||
List<Endpoints> endpoints = new ArrayList<>(); | ||
for (String namespace : properties.namespaces()) { | ||
endpoints.addAll( | ||
endpoints(client.endpoints().inNamespace(namespace).withNewFilter(), properties, serviceId)); | ||
} | ||
return endpoints; | ||
} | ||
return endpoints; | ||
} | ||
|
||
private List<ServiceInstance> getNamespaceServiceInstances(EndpointSubsetNS es, String serviceId) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot to update this documentation a while ago, as it is re-used in other places as well, and will be used in discovery also at some point in time, its on my TODO list