Search in sources :

Example 16 with PodList

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

the class ExampleTest method testNavigationListAssertions.

@Test
public void testNavigationListAssertions() throws Exception {
    final String id1 = "abc";
    final String id2 = "def";
    Map<String, String> labels1 = new HashMap<>();
    labels1.put("foo", "bar");
    Map<String, String> labels2 = new HashMap<>();
    labels2.put("whatnot", "cheese");
    final Pod pod1 = new Pod();
    pod1.setMetadata(new ObjectMeta());
    pod1.getMetadata().setName(id1);
    pod1.getMetadata().setLabels(labels1);
    final Pod pod2 = new Pod();
    pod2.setMetadata(new ObjectMeta());
    pod2.getMetadata().setName(id2);
    pod2.getMetadata().setLabels(labels2);
    final PodList emptyPodList = new PodList();
    final PodList podList = new PodList();
    podList.setItems(new ArrayList<Pod>(Arrays.asList(pod1, pod2)));
    assertThat(emptyPodList).describedAs("emptyPodList").items().isEmpty();
    assertThat(podList).describedAs("podListWith2Items").items().first().metadata().name().isEqualTo(id1);
    assertThat(podList).describedAs("podListWith2Items").items().last().metadata().name().isEqualTo(id2);
    assertAssertionError(new Block() {

        @Override
        public void invoke() throws Exception {
            assertThat(podList).describedAs("podListWith2Items").items().item(-1).isNotNull();
        }
    });
    assertAssertionError(new Block() {

        @Override
        public void invoke() throws Exception {
            assertThat(podList).describedAs("podListWith2Items").items().item(2).isNotNull();
        }
    });
    assertAssertionError(new Block() {

        @Override
        public void invoke() throws Exception {
            assertThat(podList).describedAs("podListWith2Items").items().first().metadata().name().isEqualTo("shouldNotMatch");
        }
    });
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) PodList(io.fabric8.kubernetes.api.model.PodList) Pod(io.fabric8.kubernetes.api.model.Pod) HashMap(java.util.HashMap) Block(io.fabric8.utils.Block) Test(org.junit.Test)

Example 17 with PodList

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

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 18 with PodList

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

the class Example method listPods.

protected static void listPods(KubernetesClient kube) {
    System.out.println("\n\nLooking up pods");
    System.out.println("=========================================================================");
    PodList pods = kube.pods().list();
    // System.out.println("Got pods: " + pods);
    List<Pod> items = pods.getItems();
    for (Pod item : items) {
        System.out.println("Pod " + KubernetesHelper.getName(item) + " with ip: " + item.getStatus().getPodIP() + " created: " + item.getMetadata().getCreationTimestamp());
        PodSpec spec = item.getSpec();
        if (spec != null) {
            List<Container> containers = spec.getContainers();
            if (containers != null) {
                for (Container container : containers) {
                    System.out.println("Container " + container.getImage() + " " + container.getCommand() + " ports: " + container.getPorts());
                }
            }
        }
        Map<String, ContainerStatus> currentContainers = KubernetesHelper.getCurrentContainers(item);
        System.out.println("Has " + currentContainers.size() + " container(s)");
        Set<Map.Entry<String, ContainerStatus>> entries = currentContainers.entrySet();
        for (Map.Entry<String, ContainerStatus> entry : entries) {
            String id = entry.getKey();
            ContainerStatus info = entry.getValue();
            System.out.println("Current container: " + id + " info: " + info);
        }
    }
    System.out.println();
}
Also used : PodList(io.fabric8.kubernetes.api.model.PodList) Pod(io.fabric8.kubernetes.api.model.Pod) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) Container(io.fabric8.kubernetes.api.model.Container) ContainerStatus(io.fabric8.kubernetes.api.model.ContainerStatus) Map(java.util.Map)

Example 19 with PodList

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

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 20 with PodList

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

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)

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