Search in sources :

Example 1 with ContainerInNetwork

use of org.eclipse.che.plugin.docker.client.json.network.ContainerInNetwork in project che by eclipse.

the class OpenShiftConnector method inspectNetwork.

@Override
public Network inspectNetwork(InspectNetworkParams params) throws IOException {
    String netId = params.getNetworkId();
    ServiceList services = openShiftClient.services().inNamespace(this.openShiftCheProjectName).list();
    Map<String, ContainerInNetwork> containers = new HashMap<>();
    for (Service svc : services.getItems()) {
        String selector = svc.getSpec().getSelector().get(OPENSHIFT_DEPLOYMENT_LABEL);
        if (selector == null || !selector.startsWith(CHE_OPENSHIFT_RESOURCES_PREFIX)) {
            continue;
        }
        PodList pods = openShiftClient.pods().inNamespace(openShiftCheProjectName).withLabel(OPENSHIFT_DEPLOYMENT_LABEL, selector).list();
        for (Pod pod : pods.getItems()) {
            String podName = pod.getMetadata().getName();
            ContainerInNetwork container = new ContainerInNetwork().withName(podName).withIPv4Address(svc.getSpec().getClusterIP());
            String podId = KubernetesStringUtils.getLabelFromContainerID(pod.getMetadata().getLabels().get(CHE_CONTAINER_IDENTIFIER_LABEL_KEY));
            if (podId == null) {
                continue;
            }
            containers.put(podId, container);
        }
    }
    List<IpamConfig> ipamConfig = new ArrayList<>();
    Ipam ipam = new Ipam().withDriver("bridge").withOptions(Collections.emptyMap()).withConfig(ipamConfig);
    return new Network().withName("OpenShift").withId(netId).withContainers(containers).withLabels(Collections.emptyMap()).withOptions(Collections.emptyMap()).withDriver("default").withIPAM(ipam).withScope("local").withInternal(false).withEnableIPv6(false);
}
Also used : PodList(io.fabric8.kubernetes.api.model.PodList) Pod(io.fabric8.kubernetes.api.model.Pod) HashMap(java.util.HashMap) ServiceList(io.fabric8.kubernetes.api.model.ServiceList) ArrayList(java.util.ArrayList) KubernetesService(org.eclipse.che.plugin.openshift.client.kubernetes.KubernetesService) Service(io.fabric8.kubernetes.api.model.Service) IpamConfig(org.eclipse.che.plugin.docker.client.json.network.IpamConfig) ContainerInNetwork(org.eclipse.che.plugin.docker.client.json.network.ContainerInNetwork) Ipam(org.eclipse.che.plugin.docker.client.json.network.Ipam) Network(org.eclipse.che.plugin.docker.client.json.network.Network) ContainerInNetwork(org.eclipse.che.plugin.docker.client.json.network.ContainerInNetwork)

Aggregations

Pod (io.fabric8.kubernetes.api.model.Pod)1 PodList (io.fabric8.kubernetes.api.model.PodList)1 Service (io.fabric8.kubernetes.api.model.Service)1 ServiceList (io.fabric8.kubernetes.api.model.ServiceList)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ContainerInNetwork (org.eclipse.che.plugin.docker.client.json.network.ContainerInNetwork)1 Ipam (org.eclipse.che.plugin.docker.client.json.network.Ipam)1 IpamConfig (org.eclipse.che.plugin.docker.client.json.network.IpamConfig)1 Network (org.eclipse.che.plugin.docker.client.json.network.Network)1 KubernetesService (org.eclipse.che.plugin.openshift.client.kubernetes.KubernetesService)1