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");
}
});
}
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;
}
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();
}
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();
}
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());
}
Aggregations