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)); } } }
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)); } } } }
return client.pods() .inNamespace(resource.getMetadata().getNamespace()) .withLabels(((Service) resource).getSpec().getSelector()) .list(); } else if (resource instanceof ReplicationController) {
String path = getPath(service, qualifiers); String ip = service.getSpec().getClusterIP(); int port = 0;
return client.pods() .inNamespace(resource.getMetadata().getNamespace()) .withLabels(((Service) resource).getSpec().getSelector()) .list(); } else if (resource instanceof ReplicationController) {
String path = getPath(service, qualifiers); String ip = service.getSpec().getClusterIP(); int port = 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; }
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; }
public <T extends HasMetadata> PodList podsOf(T resource) { if (resource instanceof Pod) { return new PodListBuilder().withItems((Pod) resource).build(); } else if (resource instanceof Endpoints) { return podsOf(client.services() .inNamespace(resource.getMetadata().getNamespace()) .withName(resource.getMetadata().getName()) .get()); } else if (resource instanceof Service) { return client.pods() .inNamespace(resource.getMetadata().getNamespace()) .withLabels(((Service) resource).getSpec().getSelector()) .list(); } else if (resource instanceof ReplicationController) { return client.pods() .inNamespace(resource.getMetadata().getNamespace()) .withLabels(((ReplicationController) resource).getSpec().getSelector()) .list(); } else if (resource instanceof ReplicaSet) { return findMatching((ReplicaSet) resource); } else if (resource instanceof Deployment) { return findMatching((Deployment) resource); } else if (resource instanceof DeploymentConfig) { return client.pods().inNamespace(resource.getMetadata().getName()).withLabel("deploymentconfig", resource.getMetadata().getName()).list(); } else { return new PodListBuilder().build(); } }
/** * 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; }
.append(" IP: [").append(service.getSpec().getClusterIP()).append("]") .append(" Ports: [ "); for (ServicePort servicePort : service.getSpec().getPorts()) { 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); }
.append(" IP: [").append(service.getSpec().getClusterIP()).append("]") .append(" Ports: [ "); for (ServicePort servicePort : service.getSpec().getPorts()) { 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); }