Search in sources :

Example 31 with PodList

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

the class PodPhaseWatcherTest method testPhaseWithError.

@Test
@Ignore("Reamer - ZEPPELIN-5403")
public void testPhaseWithError() throws InterruptedException {
    KubernetesClient client = server.getClient();
    // CREATE
    client.pods().inNamespace("ns1").create(new PodBuilder().withNewMetadata().withName("pod1").endMetadata().build());
    // READ
    PodList podList = client.pods().inNamespace("ns1").list();
    assertNotNull(podList);
    assertEquals(1, podList.getItems().size());
    // WATCH
    PodPhaseWatcher podWatcher = new PodPhaseWatcher(phase -> StringUtils.equalsAnyIgnoreCase(phase, "Succeeded", "Failed", "Running"));
    Watch watch = client.pods().inNamespace("ns1").withName("pod1").watch(podWatcher);
    // In the case of close, we do not block thread execution
    watch.close();
    assertTrue(podWatcher.getCountDownLatch().await(1, TimeUnit.SECONDS));
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) PodList(io.fabric8.kubernetes.api.model.PodList) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) Watch(io.fabric8.kubernetes.client.Watch) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 32 with PodList

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

the class PodSelectionAssert method getPods.

/**
 * Loads the current pods for this selection
 *
 * @return the current pods
 */
public List<Pod> getPods() {
    PodList list = getClient().pods().withLabels(getMatchLabels()).list();
    assertThat(list).describedAs(getDescription() + " pods").isNotNull();
    return list.getItems();
}
Also used : PodList(io.fabric8.kubernetes.api.model.PodList)

Example 33 with PodList

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

the class KubernetesHelperTest method testRemoveEmptyPods.

@Test
public void testRemoveEmptyPods() throws Exception {
    Pod pod1 = new Pod();
    pod1.setMetadata(new ObjectMeta());
    pod1.getMetadata().setName("test1");
    Pod pod2 = new Pod();
    pod2.setMetadata(new ObjectMeta());
    PodList podSchema = new PodList();
    podSchema.getItems().add(pod1);
    podSchema.getItems().add(pod2);
    KubernetesHelper.removeEmptyPods(podSchema);
    assertNotNull(podSchema);
    assertEquals(1, podSchema.getItems().size());
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) PodList(io.fabric8.kubernetes.api.model.PodList) Pod(io.fabric8.kubernetes.api.model.Pod) Test(org.junit.Test)

Example 34 with PodList

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

the class KubernetesAssert method getPods.

protected List<Pod> getPods(String namespace) {
    PodList podList = client.pods().inNamespace(namespace).list();
    assertThat(podList).isNotNull();
    List<Pod> pods = podList.getItems();
    podList(pods).isNotNull();
    return pods;
}
Also used : PodList(io.fabric8.kubernetes.api.model.PodList) Pod(io.fabric8.kubernetes.api.model.Pod)

Example 35 with PodList

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

the class Util method cleanupAllResources.

public static void cleanupAllResources(KubernetesClient client, Session session, List<Throwable> errors) throws MultiException {
    String sessionNamespace = session.getNamespace();
    session.getLogger().info("Removing all resources in namespace " + sessionNamespace);
    /**
     * Lets use a loop to ensure we really do delete all the matching resources
     */
    for (int i = 0; i < 10; i++) {
        OpenShiftClient openShiftClient = new Controller(client).getOpenShiftClientOrNull();
        if (openShiftClient != null) {
            try {
                openShiftClient.deploymentConfigs().inNamespace(sessionNamespace).delete();
            } catch (KubernetesClientException e) {
                errors.add(e);
            }
            try {
                openShiftClient.routes().inNamespace(sessionNamespace).delete();
            } catch (KubernetesClientException e) {
                errors.add(e);
            }
        }
        try {
            client.extensions().deployments().inNamespace(sessionNamespace).delete();
        } catch (KubernetesClientException e) {
            errors.add(e);
        }
        try {
            client.extensions().replicaSets().inNamespace(sessionNamespace).delete();
        } catch (KubernetesClientException e) {
            errors.add(e);
        }
        try {
            client.replicationControllers().inNamespace(sessionNamespace).delete();
        } catch (KubernetesClientException e) {
            errors.add(e);
        }
        try {
            client.pods().inNamespace(sessionNamespace).delete();
        } catch (KubernetesClientException e) {
            errors.add(e);
        }
        try {
            client.extensions().ingresses().inNamespace(sessionNamespace).delete();
        } catch (KubernetesClientException e) {
            errors.add(e);
        }
        try {
            client.services().inNamespace(sessionNamespace).delete();
        } catch (KubernetesClientException e) {
            errors.add(e);
        }
        try {
            client.securityContextConstraints().withName(sessionNamespace).delete();
        } catch (KubernetesClientException e) {
            errors.add(e);
        }
        // lets see if there are any matching podList left
        List<Pod> filteredPods = notNullList(client.pods().inNamespace(sessionNamespace).list().getItems());
        if (filteredPods.isEmpty()) {
            return;
        } else {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : Pod(io.fabric8.kubernetes.api.model.Pod) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) Controller(io.fabric8.kubernetes.api.Controller) 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