use of io.fabric8.kubernetes.api.model.EndpointPort in project camel by apache.
the class KubernetesClientServiceDiscovery method getServices.
@Override
public List<ServiceDefinition> getServices(String name) {
LOG.debug("Discovering endpoints from namespace: {} with name: {}", getNamespace(), name);
Endpoints endpoints = client.endpoints().inNamespace(getNamespace()).withName(name).get();
List<ServiceDefinition> result = new ArrayList<>();
if (endpoints != null) {
if (LOG.isDebugEnabled()) {
LOG.debug("Found {} endpoints in namespace: {} for name: {} and portName: {}", endpoints.getSubsets().size(), getNamespace(), name, getPortName());
}
for (EndpointSubset subset : endpoints.getSubsets()) {
if (subset.getPorts().size() == 1) {
addServers(name, result, subset.getPorts().get(FIRST), subset);
} else {
final List<EndpointPort> ports = subset.getPorts();
final int portSize = ports.size();
EndpointPort port;
for (int p = 0; p < portSize; p++) {
port = ports.get(p);
if (ObjectHelper.isEmpty(getPortName()) || getPortName().endsWith(port.getName())) {
addServers(name, result, port, subset);
}
}
}
}
}
return result;
}
use of io.fabric8.kubernetes.api.model.EndpointPort in project camel by apache.
the class KubernetesClientServiceDiscovery method addServers.
protected void addServers(String name, List<ServiceDefinition> servers, EndpointPort port, EndpointSubset subset) {
final List<EndpointAddress> addresses = subset.getAddresses();
final int size = addresses.size();
for (int i = 0; i < size; i++) {
servers.add(new DefaultServiceDefinition(name, addresses.get(i).getIp(), port.getPort()));
}
}
Aggregations