private void deleteSeleniumPods() { logger.info("About to clean up any left over docker-selenium pods created by Zalenium"); client.pods().withLabels(createdByZaleniumMap).delete(); }
private void reapMatchingReplicaSets(LabelSelector selector) { if (selector == null || (selector.getMatchLabels() == null && selector.getMatchExpressions() == null)) { return; } ReplicaSetOperationsImpl rsOper = new ReplicaSetOperationsImpl(oper.client, oper.getConfig(), oper.getNamespace()); rsOper.inNamespace(oper.getNamespace()).withLabelSelector(selector).delete(); } }
@Override public boolean reap() { DeploymentConfig deployment = operation.cascading(false).edit().editSpec().withReplicas(0).endSpec().done(); //TODO: These checks shouldn't be used as they are not realistic. We just use them to support mock/crud tests. Need to find a cleaner way to do so. if (deployment.getStatus() != null) { waitForObservedGeneration(deployment.getStatus().getObservedGeneration()); } //We are deleting the DC before reaping the replication controller, because the RC's won't go otherwise. Boolean reaped = operation.cascading(false).delete(); // Waiting for the DC to be completely deleted before removing the replication controller (error in Openshift 3.9) waitForDeletion(); Map<String, String> selector = new HashMap<>(); selector.put(DEPLOYMENT_CONFIG_REF, deployment.getMetadata().getName()); if (selector != null && !selector.isEmpty()) { Boolean deleted = new ReplicationControllerOperationsImpl(client, operation.getConfig(), operation.getNamespace()) .withLabels(selector) .delete(); } return reaped; }
@Override public void deleteAddresses(String namespace) { Map<String, String> labels = new LinkedHashMap<>(); labels.put(LabelKeys.TYPE, "address-config"); labels.put(LabelKeys.INFRA_UUID, infraUuid); labels.put(LabelKeys.NAMESPACE, namespace); client.configMaps().withLabels(labels).delete(); }
@Override public void deleteAddressSpaces(String namespace) { Map<String, String> labels = new LinkedHashMap<>(); labels.put(LabelKeys.TYPE, "address-space"); labels.put(LabelKeys.NAMESPACE, namespace); client.configMaps().withLabels(labels).delete(); }
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 void deletePod(String namespace, Map<String, String> labels) { log.info("Delete pods with labels: {}", labels.toString()); client.pods().inNamespace(namespace).withLabels(labels).delete(); }
private void deletePod(String id) { FilterWatchListDeletable<Pod, PodList, Boolean, Watch, Watcher<Pod>> podsToDelete = client.pods() .withLabel(SPRING_APP_KEY, id); if (podsToDelete != null && podsToDelete.list().getItems() != null) { logger.debug(String.format("Deleting Pod for task: %s", id)); boolean podsDeleted = podsToDelete.delete(); logger.debug(String.format("Pod deleted for: %s - %b", id, podsDeleted)); } }
private void deletePvc(Map<String, String> labels) { FilterWatchListDeletable<PersistentVolumeClaim, PersistentVolumeClaimList, Boolean, Watch, Watcher<PersistentVolumeClaim>> pvcsToDelete = client.persistentVolumeClaims() .withLabels(labels); if (pvcsToDelete != null && pvcsToDelete.list().getItems() != null) { boolean pvcsDeleted = pvcsToDelete.delete(); logger.debug(String.format("PVC deleted for: %s - %b", labels, pvcsDeleted)); } } }
private void deleteReplicationController(Map<String, String> labels) { FilterWatchListDeletable<ReplicationController, ReplicationControllerList, Boolean, Watch, Watcher<ReplicationController>> replicationControllersToDelete = client.replicationControllers() .withLabels(labels); if (replicationControllersToDelete != null && replicationControllersToDelete.list().getItems() != null) { boolean replicationControllersDeleted = replicationControllersToDelete.delete(); logger.debug(String.format("ReplicationController deleted for: %s - %b", labels, replicationControllersDeleted)); } }
private void deleteJob(String id) { FilterWatchListDeletable<Job, JobList, Boolean, Watch, Watcher<Job>> jobsToDelete = client.batch().jobs() .withLabel(SPRING_APP_KEY, id); if (jobsToDelete != null && jobsToDelete.list().getItems() != null) { logger.debug(String.format("Deleting Job for task: %s", id)); boolean jobDeleted = jobsToDelete.delete(); logger.debug(String.format("Job deleted for: %s - %b", id, jobDeleted)); } }
private void deleteService(Map<String, String> labels) { FilterWatchListDeletable<Service, ServiceList, Boolean, Watch, Watcher<Service>> servicesToDelete = client.services().withLabels(labels); if (servicesToDelete != null && servicesToDelete.list().getItems() != null) { boolean servicesDeleted = servicesToDelete.delete(); logger.debug(String.format("Service deleted for: %s - %b", labels, servicesDeleted)); } }
private void deletePod(Map<String, String> labels) { FilterWatchListDeletable<Pod, PodList, Boolean, Watch, Watcher<Pod>> podsToDelete = client.pods() .withLabels(labels); if (podsToDelete != null && podsToDelete.list().getItems() != null) { boolean podsDeleted = podsToDelete.delete(); logger.debug(String.format("Pod deleted for: %s - %b", labels, podsDeleted)); } }
private void deleteStatefulSet(Map<String, String> labels) { FilterWatchListDeletable<StatefulSet, StatefulSetList, Boolean, Watch, Watcher<StatefulSet>> ssToDelete = client.apps().statefulSets().withLabels(labels); if (ssToDelete != null && ssToDelete.list().getItems() != null) { boolean ssDeleted = ssToDelete.delete(); logger.debug(String.format("StatefulSet deleted for: %s - %b", labels, ssDeleted)); } }
private void deleteDeployment(Map<String, String> labels) { FilterWatchListDeletable<Deployment, DeploymentList, Boolean, Watch, Watcher<Deployment>> deploymentsToDelete = client.apps().deployments().withLabels(labels); if (deploymentsToDelete != null && deploymentsToDelete.list().getItems() != null) { boolean deploymentsDeleted = deploymentsToDelete.delete(); logger.debug(String.format("Deployment deleted for: %s - %b", labels, deploymentsDeleted)); } }
@Override public void deleteResourcesNotIn(String [] uuids) { client.apps().statefulSets().withLabel(LabelKeys.INFRA_TYPE).withLabelNotIn(LabelKeys.INFRA_UUID, uuids).delete(); client.secrets().withLabel(LabelKeys.INFRA_TYPE).withLabelNotIn(LabelKeys.INFRA_UUID, uuids).delete(); client.configMaps().withLabel(LabelKeys.INFRA_TYPE).withLabelNotIn(LabelKeys.INFRA_UUID, uuids).delete(); client.apps().deployments().withLabel(LabelKeys.INFRA_TYPE).withLabelNotIn(LabelKeys.INFRA_UUID, uuids).delete(); client.serviceAccounts().withLabel(LabelKeys.INFRA_TYPE).withLabelNotIn(LabelKeys.INFRA_UUID, uuids).delete(); client.services().withLabel(LabelKeys.INFRA_TYPE).withLabelNotIn(LabelKeys.INFRA_UUID, uuids).delete(); client.persistentVolumeClaims().withLabel(LabelKeys.INFRA_TYPE).withLabelNotIn(LabelKeys.INFRA_UUID, uuids).delete(); if (isOpenShift) { client.roleBindings().withLabel(LabelKeys.INFRA_TYPE).withLabelNotIn(LabelKeys.INFRA_UUID, uuids).delete(); client.deploymentConfigs().withLabel(LabelKeys.INFRA_TYPE).withLabelNotIn(LabelKeys.INFRA_UUID, uuids).delete(); client.routes().withLabel(LabelKeys.INFRA_TYPE).withLabelNotIn(LabelKeys.INFRA_UUID, uuids).delete(); } }
/** * @see ContainerBasedGatewayGenerator#removeContainerBasedGateway(String, API) (String) */ @Override public void removeContainerBasedGateway(String label, API api) throws ContainerBasedGatewayException { try { client.services().inNamespace(namespace).withLabel(ContainerBasedGatewayConstants.GATEWAY, label).delete(); client.extensions().deployments().inNamespace(namespace).withLabel(ContainerBasedGatewayConstants.GATEWAY, label).delete(); client.extensions().ingresses().inNamespace(namespace).withLabel(ContainerBasedGatewayConstants.GATEWAY, label).delete(); log.info(String.format("Completed deleting the container gateway related %s deployment, service and " + "ingress resources.", cmsType)); } catch (KubernetesClientException e) { throw new ContainerBasedGatewayException("Error while removing container based gateway", e, ExceptionCodes.CONTAINER_GATEWAY_REMOVAL_FAILED); } }
/** * @see ContainerBasedGatewayGenerator#removeContainerBasedGateway(String, API) (String) */ @Override public void removeContainerBasedGateway(String label, API api) throws ContainerBasedGatewayException { try { client.services().inNamespace(namespace).withLabel(ContainerBasedGatewayConstants.GATEWAY, label).delete(); client.extensions().deployments().inNamespace(namespace).withLabel(ContainerBasedGatewayConstants.GATEWAY, label).delete(); client.extensions().ingresses().inNamespace(namespace).withLabel(ContainerBasedGatewayConstants.GATEWAY, label).delete(); log.info(String.format("Completed deleting the container gateway related %s deployment, service and " + "ingress resources.", cmsType)); } catch (KubernetesClientException e) { throw new ContainerBasedGatewayException("Error while removing container based gateway", e, ExceptionCodes.CONTAINER_GATEWAY_REMOVAL_FAILED); } }
/** * Deletes all existing routes. * * @throws InfrastructureException when any exception occurs */ public void delete() throws InfrastructureException { try { clientFactory .createOC(workspaceId) .routes() .inNamespace(namespace) .withLabel(CHE_WORKSPACE_ID_LABEL, workspaceId) .delete(); } catch (KubernetesClientException e) { throw new KubernetesInfrastructureException(e); } } }
client.replicationControllers().inAnyNamespace().withLabel("server", "nginx").delete(); log("Deleted RC by label"); client.replicationControllers().inNamespace("thisisatest").withField("metadata.name", "nginx-controller").delete(); log("Deleted RC by field"); .done()); log("Updated service", client.services().inNamespace("thisisatest").withName("testservice").edit().editMetadata().addToLabels("test", "label").endMetadata().done()); client.replicationControllers().inNamespace("thisisatest").withField("metadata.name", "testservice").delete(); log("Deleted service by field");