static Integer findServicePort(List<ServicePort> ports, String name) { if (ports.isEmpty()) { throw new IllegalArgumentException("Empty ports!"); } if (ports.size() == 1) { return ports.get(0).getPort(); } for (ServicePort port : ports) { if (name.equals(port.getName())) { return port.getPort(); } } throw new IllegalArgumentException("No such port: " + name); }
/** * Returns the {@link ServicePort} of the {@link Service} that matches the qualifiers * * @param service * The target service. * @param qualifiers * The qualifiers. */ private static ServicePort findQualifiedServicePort(Service service, Annotation... qualifiers) { Port port = null; for (Annotation q : qualifiers) { if (q instanceof Port) { port = (Port) q; } } if (service.getSpec() != null && service.getSpec().getPorts() != null) { for (ServicePort servicePort : service.getSpec().getPorts()) { //if no port name is specified we will use the first. if (port == null) { return servicePort; } if (servicePort.getName() != null && servicePort.getName().equals(port.name())) { return servicePort; } } } return null; }
/** * Returns the {@link ServicePort} of the {@link Service} that matches the qualifiers * * @param service * The target service. * @param qualifiers * The qualifiers. */ private static ServicePort findQualifiedServicePort(Service service, Annotation... qualifiers) { Port port = null; for (Annotation q : qualifiers) { if (q instanceof Port) { port = (Port) q; } } if (service.getSpec() != null && service.getSpec().getPorts() != null) { for (ServicePort servicePort : service.getSpec().getPorts()) { //if no port name is specified we will use the first. if (port == null) { return servicePort; } if (servicePort.getName() != null && servicePort.getName().equals(port.name())) { return servicePort; } } } return null; }