diff --git a/cwm_worker_operator/deployments_manager.py b/cwm_worker_operator/deployments_manager.py index fc1d1eb..f58b3f9 100644 --- a/cwm_worker_operator/deployments_manager.py +++ b/cwm_worker_operator/deployments_manager.py @@ -262,8 +262,34 @@ def verify_worker_access(self, internal_hostname, log_kwargs, path='/minio/healt else: return True - def delete(self, namespace_name, deployment_type, **kwargs): - cwm_worker_deployment.deployment.delete(namespace_name, deployment_type, **kwargs) + def delete(self, namespace_name, deployment_type, delete_data=False, **kwargs): + if delete_data: + minio_admin = get_minio_admin() + failed = False + for cmd, args, kwargs in [ + ('user_remove', [namespace_name], {}), + ('policy_unset', [namespace_name], {'user': namespace_name}), + ('policy_remove', [namespace_name], {}), + ]: + try: + getattr(minio_admin, cmd)(*args, **kwargs) + except: + failed = True + if config.DEBUG and config.DEBUG_VERBOSITY >= 3: + traceback.print_exc() + minio = get_minio() + try: + if minio.bucket_exists(namespace_name): + for obj in minio.list_objects(namespace_name): + minio.remove_object(namespace_name, obj.object_name) + minio.remove_bucket(namespace_name) + except: + failed = True + if config.DEBUG and config.DEBUG_VERBOSITY >= 3: + traceback.print_exc() + if failed: + raise Exception("Failed to delete minio data") + # cwm_worker_deployment.deployment.delete(namespace_name, deployment_type, **kwargs) def iterate_all_releases(self): for username, user in json.loads(get_minio_admin().user_list()).items(): diff --git a/cwm_worker_operator/updater.py b/cwm_worker_operator/updater.py index af8adbd..44e3e99 100644 --- a/cwm_worker_operator/updater.py +++ b/cwm_worker_operator/updater.py @@ -59,7 +59,8 @@ def check_update_release(domains_config, updater_metrics, namespace_name, last_u else: hours_since_last_update = ((common.now() - last_updated).total_seconds() / 60 / 60) volume_config = domains_config.get_cwm_api_volume_config(worker_id=worker_id) - disable_force_delete = volume_config.disable_force_delete + # disable_force_delete = volume_config.disable_force_delete + disable_force_delete = True # the new minio tenant configuration doesn't need forced delete on a schedule disable_force_update = volume_config.disable_force_update is_deployed = status == "deployed" if not is_deployed: @@ -203,19 +204,19 @@ def run_single_iteration(domains_config, metrics, deployments_manager, cwm_api_m all_releases = {release["username"]: release for release in deployments_manager.iterate_all_releases()} for release in all_releases.values(): namespace_name = release["username"] - updated_instances.add(namespace_name) last_updated = common.strptime(release['user']['updatedAt'].split('.')[0], "%Y-%m-%dT%H:%M:%S") start_time = common.now() worker_id = common.get_worker_id_from_namespace_name(namespace_name) + updated_instances.add(worker_id) instance_update = instances_updates.get(worker_id) status = 'deployed' revision = 3 multiprocessor.process(domains_config, updater_metrics, namespace_name, last_updated, status, revision, worker_id, instance_update, start_time, cwm_api_manager) for namespace_name, operation in instances_updates.items(): - if operation == 'update' and namespace_name not in updated_instances: + worker_id = common.get_worker_id_from_namespace_name(namespace_name) + if operation == 'update' and worker_id not in updated_instances: start_time = common.now() - worker_id = common.get_worker_id_from_namespace_name(namespace_name) multiprocessor.process(domains_config, updater_metrics, namespace_name, None, None, None, worker_id, 'create', start_time, cwm_api_manager) multiprocessor.finalize()