@Override public Boolean delete(List<T> items) { boolean deleted = true; if (items != null) { for (T item : items) { updateApiVersionResource(item); try { R op = createItemOperation(item); deleted &= op.delete(); } catch (KubernetesClientException e) { if (e.getCode() != 404) { throw e; } return false; } catch (NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) { throw KubernetesClientException.launderThrowable(forOperationType("delete"), e); } } } return deleted; }
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.templates().load(TemplateExample.class.getResourceAsStream("/test-template.yml")).get(); 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"); } } } }
public static void main(String[] args) { String master = "https://localhost:8443/"; if (args.length == 1) { master = args[0]; } Config config = new ConfigBuilder().withMasterUrl(master).build(); KubernetesClient client = new DefaultKubernetesClient(config); try { log("Create namespace:", client.namespaces().create(new NamespaceBuilder().withNewMetadata().withName("thisisatest").endMetadata().build())); log("Deleted namespace:", client.namespaces().withName("test").delete()); log("Deleted testPod:", client.pods().inNamespace("thisisatest").withName("testpod").delete()); log("Deleted pod by label:", client.pods().withLabel("this", "works").delete()); } catch (KubernetesClientException e) { logger.error(e.getMessage(), e); } finally { client.namespaces().withName("thisisatest").delete(); client.close(); } }
public static void main(String[] args) throws InterruptedException { String master = "https://localhost:8443/"; if (args.length == 1) { master = args[0]; } Config config = new ConfigBuilder().withMasterUrl(master).build(); try (OpenShiftClient client = new DefaultOpenShiftClient(config)) { ProjectRequest request = null; try { request = client.projectrequests().createNew().withNewMetadata().withName("thisisatest").endMetadata().withDescription("Jimmi").withDisplayName("Jimmi").done(); } finally { if (request != null) { client.projects().withName(request.getMetadata().getName()).delete(); } } } }
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(); } }
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();
private boolean removeImageStreams(String name) { LOGGER.debug("Remove ImageStream {}", name); return openShiftClient.imageStreams().withName(name).delete(); }
/** * Deletes the resource with the given namespace and name * and completes the given future accordingly */ protected Future<ReconcileResult<T>> internalDelete(String namespace, String name) { try { operation().inNamespace(namespace).withName(name).delete(); log.debug("{} {} in namespace {} has been deleted", resourceKind, name, namespace); return Future.succeededFuture(ReconcileResult.deleted()); } catch (Exception e) { log.error("Caught exception while deleting {} {} in namespace {}", resourceKind, name, namespace, e); return Future.failedFuture(e); } }
public String deleteServiceAccount(String name, String namespace) { log.info("Delete serviceaccount {} from namespace {}", name, namespace); client.serviceAccounts().inNamespace(namespace).withName(name).delete(); return "system:serviceaccount:" + namespace + ":" + name; }
public boolean deleteNamespace(String namespaceName) { if (!checkNamespace(namespaceName)) { return false; } OpenShiftClient openshiftClient = getOpenShiftClient(); if (openshiftClient != null) { return openshiftClient.projects().withName(namespaceName).delete(); } else { return kubernetesClient.namespaces().withName(namespaceName).delete(); } }
@Override public void deleteResource(ResourceName resourceName, Handler<AsyncResult<Void>> handler) { vertx.executeBlocking(future -> { try { // Delete the resource by the topic name, because neither ZK nor Kafka know the resource name operation().inNamespace(namespace).withName(resourceName.toString()).delete(); future.complete(); } catch (Exception e) { future.fail(e); } }, handler); }
logger.error(e.getMessage(), e); } finally { client.namespaces().withName("thisisatest").delete();
public void unsubscribe(String namespace, String name) { kubernetesClient.configMaps().inNamespace(namespace).withName(name).delete(); }
client.namespaces().withName("thisisatest").delete(); client.close();
@VisibleForTesting void doRemoveProject(String projectName) throws InfrastructureException { try { clientFactory.createOC(projectName).projects().withName(projectName).delete(); } catch (KubernetesClientException e) { if (!(e.getCode() == 403)) { throw new KubernetesInfrastructureException(e); } // project doesn't exist } } }
public void onRemoved(HasMetadata deployment) { String secretName = deployment.getMetadata().getAnnotations().get(TOPIC_SECRET_NAME); if (secretName == null) { secretName = deployment.getMetadata().getName() + "-kafka-credentials"; } log.info("Deleting secret {} for Deployment {}", secretName, deployment.getMetadata().getName()); kubeClient().secrets().withName(secretName).delete(); }
@Override public boolean deleteAddress(Address address) { Boolean deleted = client.configMaps().withName(getConfigMapName(address.getMetadata().getNamespace(), address.getMetadata().getName())).delete(); return deleted != null && deleted; }
@Override public boolean deleteAddressSpace(AddressSpace addressSpace) { String name = getConfigMapName(addressSpace.getMetadata().getNamespace(), addressSpace.getMetadata().getName()); Boolean deleted = client.configMaps().withName(name).delete(); return deleted != null && deleted; }
client.namespaces().withName("thisisatest").delete(); log("Deleted namespace");
client.namespaces().withName("thisisatest").delete(); client.close();