Java Code Examples for io.fabric8.openshift.client.OpenShiftClient#close()

The following examples show how to use io.fabric8.openshift.client.OpenShiftClient#close() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImageStreamTagExample.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws InterruptedException {

    String namespace = "myproject";
    String master = "CLUSTER_URL";
    Config config = new ConfigBuilder().withMasterUrl(master).build();
    OpenShiftClient client = new DefaultOpenShiftClient(config);

    try {

      ImageStreamTag istag = new ImageStreamTagBuilder().withNewMetadata().withName("bar1:1.0.12").endMetadata()
        .withNewTag().withNewFrom().withKind("DockerImage").withName("openshift/wildfly-81-centos7:latest").endFrom().endTag()
        .build();

      log("Created istag", client.imageStreamTags().inNamespace(namespace).create(istag));
      
      Thread.sleep(30000);

    }finally {

      log("ImageStreamTags are :");
      log(client.imageStreamTags().inNamespace(namespace).withName("bar1:1.0.12").get().toString());

      log("ImageStreamTags using list are :");
      log(client.imageStreamTags().list().getItems().get(0).toString());
      log("Deleted istag",client.imageStreamTags().withName("bar1:1.0.12").delete());
      client.close();
    }
  }
 
Example 2
Source File: ImageStreamExample.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws InterruptedException {

    String namespace = "myproject";
    String master = "CLUSTER_URL";
    Config config = new ConfigBuilder().withMasterUrl(master).build();
    OpenShiftClient client = new DefaultOpenShiftClient(config);

    HashMap annotations = new HashMap();
    annotations.put("role", "jenkins-slave");
    annotations.put("slave-label", "jenkins-slave");

    try {

      ImageStream imageStream = new ImageStreamBuilder()
        .withNewMetadata()
          .withName("slave-jenkins")
        .endMetadata()
        .withNewSpec()
          .addToTags(0, new TagReferenceBuilder()
            .withName("base")
            .withFrom(new ObjectReferenceBuilder()
              .withKind("DockerImage")
              .withName("docker.io/openshift/jenkins-slave-maven-centos7:latest")
              .build()
            )
            .build()
          )
          .addToTags(1, new TagReferenceBuilder()
            .withAnnotations(annotations)
            .withName("latest")
            .withFrom(new ObjectReferenceBuilder()
              .withKind("ImageStreamTag")
              .withName("base")
              .build()
            )
            .build()
          )
        .endSpec()
        .build();

      log("Created ImageStream", client.imageStreams().inNamespace(namespace).create(imageStream));

    }finally {

      log("Tags in ImageStream are");
      log("First Tag is " + client.imageStreams().inNamespace(namespace).withName("slave-jenkins").get().getSpec().getTags().get(0).getName());
      log("Second Tag is " + client.imageStreams().inNamespace(namespace).withName("slave-jenkins").get().getSpec().getTags().get(1).getName());

      client.imageStreams().inNamespace(namespace).withName("slave-jenkins").delete();
      client.close();
    }
  }
 
Example 3
Source File: DeploymentConfigExamples.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws InterruptedException {
  Config config = new ConfigBuilder().build();
  KubernetesClient kubernetesClient = new DefaultKubernetesClient(config);
  OpenShiftClient client = kubernetesClient.adapt(OpenShiftClient.class);

  try {
    ProjectRequest  projectRequest = new ProjectRequestBuilder()
        .withNewMetadata()
          .withName("thisisatest")
          .addToLabels("project", "thisisatest")
        .endMetadata()
        .build();


    log("Created project", client.projectrequests().create(projectRequest));

    ServiceAccount fabric8 = new ServiceAccountBuilder().withNewMetadata().withName("fabric8").endMetadata().build();

    client.serviceAccounts().inNamespace("thisisatest").createOrReplace(fabric8);

    log("Created deployment", client.deploymentConfigs().inNamespace("thisisatest").createOrReplaceWithNew()
      .withNewMetadata()
        .withName("nginx")
      .endMetadata()
      .withNewSpec()
        .withReplicas(1)
        .addNewTrigger()
          .withType("ConfigChange")
        .endTrigger()
        .addToSelector("app", "nginx")
        .withNewTemplate()
          .withNewMetadata()
            .addToLabels("app", "nginx")
          .endMetadata()
          .withNewSpec()
            .addNewContainer()
              .withName("nginx")
              .withImage("nginx")
              .addNewPort()
                .withContainerPort(80)
              .endPort()
            .endContainer()
          .endSpec()
        .endTemplate()
      .endSpec()
      .done());


    client.deploymentConfigs().inNamespace("thisisatest").withName("nginx").scale(2, true);
    log("Created pods:", client.pods().inNamespace("thisisatest").list().getItems());
    client.deploymentConfigs().inNamespace("thisisatest").withName("nginx").delete();
    log("Pods:", client.pods().inNamespace("thisisatest").list().getItems());
    log("Replication Controllers:", client.replicationControllers().inNamespace("thisisatest").list().getItems());

    log("Done.");
  }finally {
   // client.projects().withName("thisisatest").delete();
    client.close();
  }
}