def delete_routes(datapusher_name, deis_instance_id, root_domain, sub_domain): routers_manager.delete_routes(datapusher_name=datapusher_name, deis_instance_id=deis_instance_id, root_domain=root_domain, sub_domain=sub_domain) logs.exit_great_success()
def delete(self, force=False, wait_deleted=False): """ Can run delete multiple time until successful deletion of all components. Uses Kubernetes finalizers to ensure deletion is complete before applying the deletion. """ print(f'Deleting {self.kind} {self.id}') try: assert self.spec has_spec = True except Exception: has_spec = False # this updates deletion timestamp but doesn't delete the object until all finalizers are removed subprocess.call(f'kubectl -n ckan-cloud delete --wait=false {self.kind} {self.id}', shell=True) num_exceptions = 0 if has_spec: for delete_id, delete_code in { 'deployment': lambda: DeisCkanInstanceDeployment(self).delete(), 'envvars': lambda: DeisCkanInstanceEnvvars(self).delete(), 'registry': lambda: DeisCkanInstanceRegistry(self).delete(), 'solr': lambda: DeisCkanInstanceSolr(self).delete(), 'storage': lambda: DeisCkanInstanceStorage(self).delete(), 'namespace': lambda: DeisCkanInstanceNamespace(self).delete(), 'envvars-secret': lambda: kubectl.check_call(f'delete --ignore-not-found secret/{self.id}-envvars'), 'routes': lambda: routers_manager.delete_routes(deis_instance_id=self.id), 'uptime-monitoring': lambda: DeisCkanInstanceUptime(self).delete(self.id) }.items(): try: delete_code() except Exception as e: logs.critical(f'deletion failed for instance {self.id}, submodule: {delete_id}') num_exceptions += 1 else: try: routers_manager.delete_routes(deis_instance_id=self.id) except Exception as e: logs.critical(f'deletion failed for instance {self.id}, submodule: routes') num_exceptions += 1 num_exceptions += 1 if num_exceptions != 0 and not force: raise Exception('instance was not deleted, run with --force to force deletion with risk of remaining infra') else: print(f'Removing finalizers from {self.kind} {self.id}') try: subprocess.check_call( f'kubectl -n ckan-cloud patch {self.kind} {self.id} -p \'{{"metadata":{{"finalizers":[]}}}}\' --type=merge', shell=True ) except Exception: logs.critical(f'failed to remove finalizers: {self.id}') num_exceptions += 1 if not force: raise if wait_deleted and has_spec: logs.info('Waiting 30 seconds for instance to be deleted...') time.sleep(30)