Search in sources :

Example 21 with PodList

use of io.fabric8.kubernetes.api.model.PodList in project fabric8 by jboss-fuse.

the class PodResourceProvider method lookup.

@Override
public Object lookup(ArquillianResource resource, Annotation... qualifiers) {
    KubernetesClient client = this.clientInstance.get();
    Session session = sessionInstance.get();
    String name = getPodName(qualifiers);
    if (name != null) {
        return client.pods().inNamespace(session.getNamespace()).withName(name).get();
    }
    // Gets the first pod found that matches the labels.
    Map<String, String> labels = getLabels(qualifiers);
    PodList list = client.pods().inNamespace(session.getNamespace()).withLabels(labels).list();
    List<Pod> pods = notNullList(list.getItems());
    if (!pods.isEmpty()) {
        return pods.get(0);
    }
    return null;
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) PodList(io.fabric8.kubernetes.api.model.PodList) Pod(io.fabric8.kubernetes.api.model.Pod) Session(io.fabric8.arquillian.kubernetes.Session)

Example 22 with PodList

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

the class OpenShiftConnector method getChePodByContainerId.

private Pod getChePodByContainerId(String containerId) throws IOException {
    PodList pods = openShiftClient.pods().inNamespace(this.openShiftCheProjectName).withLabel(CHE_CONTAINER_IDENTIFIER_LABEL_KEY, KubernetesStringUtils.getLabelFromContainerID(containerId)).list();
    List<Pod> items = pods.getItems();
    if (items.isEmpty()) {
        LOG.error("An OpenShift Pod with label {}={} could not be found", CHE_CONTAINER_IDENTIFIER_LABEL_KEY, containerId);
        throw new IOException("An OpenShift Pod with label " + CHE_CONTAINER_IDENTIFIER_LABEL_KEY + "=" + containerId + " could not be found");
    }
    if (items.size() > 1) {
        LOG.error("There are {} pod with label {}={} (just one was expeced)", items.size(), CHE_CONTAINER_IDENTIFIER_LABEL_KEY, containerId);
        throw new IOException("There are " + items.size() + " pod with label " + CHE_CONTAINER_IDENTIFIER_LABEL_KEY + "=" + containerId + " (just one was expeced)");
    }
    return items.get(0);
}
Also used : PodList(io.fabric8.kubernetes.api.model.PodList) Pod(io.fabric8.kubernetes.api.model.Pod) IOException(java.io.IOException)

Example 23 with PodList

use of io.fabric8.kubernetes.api.model.PodList 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)

Example 24 with PodList

use of io.fabric8.kubernetes.api.model.PodList in project camel by apache.

the class KubernetesPodsProducer method doList.

protected void doList(Exchange exchange, String operation) throws Exception {
    PodList podList = getEndpoint().getKubernetesClient().pods().list();
    MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
    exchange.getOut().setBody(podList.getItems());
}
Also used : PodList(io.fabric8.kubernetes.api.model.PodList)

Example 25 with PodList

use of io.fabric8.kubernetes.api.model.PodList in project fabric8-maven-plugin by fabric8io.

the class DebugMojo method waitForRunningPodWithEnvVar.

private String waitForRunningPodWithEnvVar(final KubernetesClient kubernetes, final String namespace, LabelSelector selector, final Map<String, String> envVars) throws MojoExecutionException {
    // wait for the newest pod to be ready with the given env var
    FilterWatchListDeletable<Pod, PodList, Boolean, Watch, Watcher<Pod>> pods = withSelector(kubernetes.pods().inNamespace(namespace), selector, log);
    log.info("Waiting for debug pod with selector " + selector + " and environment variables " + envVars);
    podWaitLog = createExternalProcessLogger("[[Y]][W][[Y]] ");
    PodList list = pods.list();
    if (list != null) {
        Pod latestPod = KubernetesResourceUtil.getNewestPod(list.getItems());
        if (latestPod != null && podHasEnvVars(latestPod, envVars)) {
            return getName(latestPod);
        }
    }
    podWatcher = pods.watch(new Watcher<Pod>() {

        @Override
        public void eventReceived(Watcher.Action action, Pod pod) {
            podWaitLog.info(getName(pod) + " status: " + getPodStatusDescription(pod) + getPodStatusMessagePostfix(action));
            if (isAddOrModified(action) && isPodRunning(pod) && isPodReady(pod) && podHasEnvVars(pod, envVars)) {
                foundPod = pod;
                terminateLatch.countDown();
            }
        }

        @Override
        public void onClose(KubernetesClientException e) {
        // ignore
        }
    });
    // now lets wait forever?
    while (terminateLatch.getCount() > 0) {
        try {
            terminateLatch.await();
        } catch (InterruptedException e) {
        // ignore
        }
        if (foundPod != null) {
            return getName(foundPod);
        }
    }
    throw new MojoExecutionException("Could not find a running pod with environment variables " + envVars);
}
Also used : PodList(io.fabric8.kubernetes.api.model.PodList) Pod(io.fabric8.kubernetes.api.model.Pod) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Watch(io.fabric8.kubernetes.client.Watch) Watcher(io.fabric8.kubernetes.client.Watcher) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Aggregations

PodList (io.fabric8.kubernetes.api.model.PodList)32 Pod (io.fabric8.kubernetes.api.model.Pod)30 Test (org.junit.Test)8 DoneablePod (io.fabric8.kubernetes.api.model.DoneablePod)7 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)7 Watch (io.fabric8.kubernetes.client.Watch)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 Watcher (io.fabric8.kubernetes.client.Watcher)5 ContainerStatus (io.fabric8.kubernetes.api.model.ContainerStatus)4 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)4 PodBuilder (io.fabric8.kubernetes.api.model.PodBuilder)4 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)4 Service (io.fabric8.kubernetes.api.model.Service)3 ServiceList (io.fabric8.kubernetes.api.model.ServiceList)3 PodResource (io.fabric8.kubernetes.client.dsl.PodResource)3 Session (io.fabric8.arquillian.kubernetes.Session)2 Controller (io.fabric8.kubernetes.api.Controller)2 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)2 ConfigMapList (io.fabric8.kubernetes.api.model.ConfigMapList)2