Search in sources :

Example 6 with ServicePort

use of io.fabric8.kubernetes.api.model.ServicePort in project che by eclipse.

the class OpenShiftConnector method getCheServicePorts.

private Map<String, List<PortBinding>> getCheServicePorts(Service service) {
    Map<String, List<PortBinding>> networkSettingsPorts = new HashMap<>();
    List<ServicePort> servicePorts = service.getSpec().getPorts();
    LOG.info("Retrieving {} ports exposed by service {}", servicePorts.size(), service.getMetadata().getName());
    for (ServicePort servicePort : servicePorts) {
        String protocol = servicePort.getProtocol();
        String targetPort = String.valueOf(servicePort.getTargetPort().getIntVal());
        String nodePort = String.valueOf(servicePort.getNodePort());
        String portName = servicePort.getName();
        LOG.info("Port: {}{}{} ({})", targetPort, DOCKER_PROTOCOL_PORT_DELIMITER, protocol, portName);
        networkSettingsPorts.put(targetPort + DOCKER_PROTOCOL_PORT_DELIMITER + protocol.toLowerCase(), Collections.singletonList(new PortBinding().withHostIp(CHE_DEFAULT_EXTERNAL_ADDRESS).withHostPort(nodePort)));
    }
    return networkSettingsPorts;
}
Also used : ServicePort(io.fabric8.kubernetes.api.model.ServicePort) PortBinding(org.eclipse.che.plugin.docker.client.json.PortBinding) HashMap(java.util.HashMap) List(java.util.List) ServiceList(io.fabric8.kubernetes.api.model.ServiceList) ArrayList(java.util.ArrayList) PodList(io.fabric8.kubernetes.api.model.PodList)

Aggregations

ServicePort (io.fabric8.kubernetes.api.model.ServicePort)6 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 List (java.util.List)4 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)3 Service (io.fabric8.kubernetes.api.model.Service)3 Map (java.util.Map)3 ServiceSpec (io.fabric8.kubernetes.api.model.ServiceSpec)2 Exchange (org.apache.camel.Exchange)2 Processor (org.apache.camel.Processor)2 Test (org.junit.Test)2 PodList (io.fabric8.kubernetes.api.model.PodList)1 ServiceList (io.fabric8.kubernetes.api.model.ServiceList)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 ExposedPort (org.eclipse.che.plugin.docker.client.json.ExposedPort)1 PortBinding (org.eclipse.che.plugin.docker.client.json.PortBinding)1 KubernetesService (org.eclipse.che.plugin.openshift.client.kubernetes.KubernetesService)1 Assert.assertTrue (org.testng.Assert.assertTrue)1