Example #1
0
  @Test
  public void testParsePodListEmptyResults() throws Exception {
    PodList podList = assertParseExampleFile("pod-list-empty-results.json", PodList.class);
    List<Pod> items = podList.getItems();
    assertNotEmpty("items", items);

    Pod pod = items.get(0);
    assertNotNull("pod1", pod);
    assertEquals("127.0.0.1", pod.getStatus().getHostIP());
  }
Example #2
0
  public static void cleanupAllMatching(
      KubernetesClient client, String key, Session session, List<Throwable> errors)
      throws MultiException {
    Map<String, String> labels = Collections.singletonMap(key, session.getId());
    Filter<Pod> podFilter = KubernetesHelper.createPodFilter(labels);
    Filter<Service> serviceFilter = KubernetesHelper.createServiceFilter(labels);
    Filter<ReplicationController> replicationControllerFilter =
        KubernetesHelper.createReplicationControllerFilter(labels);

    /** Lets use a loop to ensure we really do delete all the matching resources */
    for (int i = 0; i < 10; i++) {
      try {
        deleteReplicationControllers(client, session.getLogger(), replicationControllerFilter);
      } catch (MultiException e) {
        errors.addAll(Arrays.asList(e.getCauses()));
      }

      try {
        deletePods(client, session.getLogger(), podFilter);
      } catch (MultiException e) {
        errors.addAll(Arrays.asList(e.getCauses()));
      }

      try {
        deleteServices(client, session.getLogger(), serviceFilter);
      } catch (MultiException e) {
        errors.addAll(Arrays.asList(e.getCauses()));
      }

      // lets see if there are any matching podList left
      PodList podList = client.getPods();
      List<Pod> filteredPods = Filters.filter(notNullList(podList.getItems()), podFilter);
      if (filteredPods.isEmpty()) {
        return;
      } else {
        try {
          Thread.sleep(1000);
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
      }
    }
  }
Example #3
0
 protected static void listPods(Kubernetes kube) {
   System.out.println("Looking up pods");
   PodList pods = kube.getPods(Kubernetes.NAMESPACE_ALL);
   // System.out.println("Got pods: " + pods);
   List<Pod> items = pods.getItems();
   for (Pod item : items) {
     System.out.println("Pod " + getId(item) + " created: " + item.getCreationTimestamp());
     PodState desiredState = item.getDesiredState();
     if (desiredState != null) {
       ContainerManifest manifest = desiredState.getManifest();
       if (manifest != null) {
         List<Container> containers = manifest.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();
 }