public static void main(String[] args) throws IOException {
    try (OpenShiftClient client = new DefaultOpenShiftClient()) {
      try {
        client
            .namespaces()
            .createNew()
            .withNewMetadata()
            .withName("thisisatest")
            .endMetadata()
            .done();

        Template t =
            client.unmarshal(
                TemplateExample.class.getResourceAsStream("/test-template.yml"), Template.class);

        for (Parameter p : t.getParameters()) {
          System.out.println(p.getName());
        }

        t =
            client
                .templates()
                .load(TemplateExample.class.getResourceAsStream("/test-template.yml"))
                .get();
        t =
            client
                .templates()
                .inNamespace("thisisatest")
                .load(TemplateExample.class.getResourceAsStream("/test-template.yml"))
                .create();
        t = client.templates().inNamespace("thisisatest").withName("eap6-basic-sti").get();
        System.out.println(t.getMetadata().getName());

        KubernetesList l =
            client.templates().inNamespace("thisisatest").withName("eap6-basic-sti").process();
        System.out.println(l.getItems().size());

        l = client.lists().load(TemplateExample.class.getResourceAsStream("/test-list.yml")).get();
        System.out.println(l.getItems().size());

        l =
            client
                .lists()
                .inNamespace("thisisatest")
                .load(TemplateExample.class.getResourceAsStream("/test-list.yml"))
                .create();
      } finally {
        // And finally clean up the namespace
        client.namespaces().withName("thisisatest").delete();
        logger.info("Deleted namespace");
      }
    }
  }
Exemple #2
0
  @Test
  public void testParsePodList() throws Exception {
    KubernetesList podList = assertParseExampleFile("pod-list.json", KubernetesList.class);
    List<HasMetadata> items = podList.getItems();
    assertNotEmpty("items", items);

    Pod pod = (Pod) items.get(0);
    assertNotNull("pod1", pod);
    assertEquals("pod1.name", "my-pod-1", KubernetesHelper.getName(pod));
    PodSpec podSpec = pod.getSpec();
    assertNotNull("pod1.podSpec", podSpec);
    List<Container> containers = podSpec.getContainers();
    assertNotEmpty("pod1.podSpec.containers", containers);
    Container container = containers.get(0);
    assertNotNull("pod1.podSpec.container[0]", container);
    assertEquals("pod1.podSpec.container[0].name", "nginx", container.getName());
    assertEquals("pod1.podSpec.container[0].image", "dockerfile/nginx", container.getImage());

    LOG.info("pod1 container1 " + container);

    String json = KubernetesHelper.toJson(podList);
    LOG.info("Got JSON: " + json);
  }