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); }
public PortBindings() { this.mappedPorts = new HashMap<Integer, PortAddress>(); this.containerPorts = new LinkedHashSet<Integer>(); for (ServicePort servicePort : resource.getSpec().getPorts()) { final int port = servicePort.getPort(); final Integer nodePort = servicePort.getNodePort(); containerPorts.add(port); if (nodePort != null) { mappedPorts.put(port, new PortAddressImpl(containerIP, nodePort)); } } }
/** * Find the the qualified container port of the target service * Uses java annotations first or returns the container port. * * @param service * The target service. * @param qualifiers * The set of qualifiers. * * @return Returns the resolved containerPort of '0' as a fallback. */ private static int getPort(Service service, Annotation... qualifiers) { for (Annotation q : qualifiers) { if (q instanceof Port) { Port port = (Port) q; if (port.value() > 0) { return port.value(); } } } ServicePort servicePort = findQualifiedServicePort(service, qualifiers); if (servicePort != null) { return servicePort.getPort(); } return 0; }
/** * 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; }
/** * Find the the qualfied container port of the target service * Uses java annotations first or returns the container port. * * @param service * The target service. * @param qualifiers * The set of qualifiers. * * @return Returns the resolved containerPort of '0' as a fallback. */ private static int getContainerPort(Service service, Annotation... qualifiers) { for (Annotation q : qualifiers) { if (q instanceof Port) { Port port = (Port) q; if (port.value() > 0) { return port.value(); } } } ServicePort servicePort = findQualifiedServicePort(service, qualifiers); if (servicePort != null) { return servicePort.getTargetPort().getIntVal(); } return 0; }
/** * Find the the qualified container port of the target service * Uses java annotations first or returns the container port. * * @param service * The target service. * @param qualifiers * The set of qualifiers. * * @return Returns the resolved containerPort of '0' as a fallback. */ private static int getPort(Service service, Annotation... qualifiers) { for (Annotation q : qualifiers) { if (q instanceof Port) { Port port = (Port) q; if (port.value() > 0) { return port.value(); } } } ServicePort servicePort = findQualifiedServicePort(service, qualifiers); if (servicePort != null) { return servicePort.getPort(); } return 0; }
/** * 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; }
/** * Find the the qualfied container port of the target service * Uses java annotations first or returns the container port. * * @param service * The target service. * @param qualifiers * The set of qualifiers. * * @return Returns the resolved containerPort of '0' as a fallback. */ private static int getContainerPort(Service service, Annotation... qualifiers) { for (Annotation q : qualifiers) { if (q instanceof Port) { Port port = (Port) q; if (port.value() > 0) { return port.value(); } } } ServicePort servicePort = findQualifiedServicePort(service, qualifiers); if (servicePort != null) { return servicePort.getTargetPort().getIntVal(); } return 0; }
private synchronized void serviceStarted() throws Exception { containerIP = resource.getSpec().getClusterIP(); for (ServicePort servicePort : resource.getSpec().getPorts()) { final int port = servicePort.getPort(); final Integer nodePort = servicePort.getNodePort(); containerPorts.add(port); if (nodePort != null) { // overwrite whatever's there as the containerIP has just been set mappedPorts.put(port, new PortAddressImpl(containerIP, nodePort)); } } } }
sb.append(servicePort.getPort()).append(" ");
private int resolvePort(Service service) { final Pod pod = getRandomPod(client, service.getMetadata().getName(), namespace); final ServicePort servicePort = (service.getSpec() != null && service.getSpec().getPorts() != null) ? service.getSpec().getPorts().get(0) : null; final int containerPort = servicePort != null ? servicePort.getTargetPort().getIntVal() : 0; return portForward(pod.getMetadata().getName(), containerPort, namespace); }
public static Binding toBinding(Service pod) { Binding binding = null; if (pod.getStatus() != null && pod.getSpec().getClusterIP() != null) { // Running // pod binding = new Binding(pod.getSpec().getClusterIP()); } else { // Configured pod binding = new Binding(null); } for (ServicePort port : pod.getSpec().getPorts()) { // nodePort is service equivalent of pod's hostPort binding.addPortBinding(port.getPort(), port.getNodePort()); } return binding; }
sb.append(servicePort.getPort()).append(" ");
private int resolvePort(Service service) { final Pod pod = getRandomPod(client, service.getMetadata().getName(), namespace); final ServicePort servicePort = (service.getSpec() != null && service.getSpec().getPorts() != null) ? service.getSpec().getPorts().get(0) : null; final int containerPort = servicePort != null ? servicePort.getTargetPort().getIntVal() : 0; return portForward(pod.getMetadata().getName(), containerPort, namespace); }