diff --git a/awx/main/tasks.py b/awx/main/tasks.py index 331a00bad9..ab8cd293d4 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -402,21 +402,18 @@ def purge_old_stdout_files(): def cleanup_execution_environment_images(): if settings.IS_K8S: return - images_in_use = [ee.image for ee in ExecutionEnvironment.objects.all()] - images_system = subprocess.run("podman images -a --format json".split(" "), capture_output=True) - if len(images_system.stdout) > 0: - images_system = json.loads(images_system.stdout) + process = subprocess.run('podman images --filter="dangling=true" --format json'.split(" "), capture_output=True) + if process.returncode != 0: + logger.debug("Cleanup execution environment images: could not get list of images") + return + if len(process.stdout) > 0: + images_system = json.loads(process.stdout) for e in images_system: - if 'Names' in e: - image_name = e['Names'][0] - else: - image_name = e["Id"] - image_size = e['Size'] / 1e6 - if image_name not in images_in_use: - logger.debug(f"Cleanup execution environment images: deleting {image_name}, {image_size:.0f} MB") - process = subprocess.run(['podman', 'rmi', image_name, '-f'], stdout=subprocess.DEVNULL) - if process.returncode != 0: - logger.debug(f"Unsuccessfully deleted image {image_name}") + image_name = e["Id"] + logger.debug(f"Cleanup execution environment images: deleting {image_name}") + process = subprocess.run(['podman', 'rmi', image_name, '-f'], stdout=subprocess.DEVNULL) + if process.returncode != 0: + logger.debug(f"Failed to delete image {image_name}") @task(queue=get_local_queuename) diff --git a/awx/settings/defaults.py b/awx/settings/defaults.py index e1b497f1b0..f750d336b1 100644 --- a/awx/settings/defaults.py +++ b/awx/settings/defaults.py @@ -439,7 +439,7 @@ CELERYBEAT_SCHEDULE = { 'task_manager': {'task': 'awx.main.scheduler.tasks.run_task_manager', 'schedule': timedelta(seconds=20), 'options': {'expires': 20}}, 'k8s_reaper': {'task': 'awx.main.tasks.awx_k8s_reaper', 'schedule': timedelta(seconds=60), 'options': {'expires': 50}}, 'send_subsystem_metrics': {'task': 'awx.main.analytics.analytics_tasks.send_subsystem_metrics', 'schedule': timedelta(seconds=20)}, - 'cleanup_images': {'task': 'awx.main.tasks.cleanup_execution_environment_images', 'schedule': timedelta(hours=8)}, + 'cleanup_images': {'task': 'awx.main.tasks.cleanup_execution_environment_images', 'schedule': timedelta(hours=3)}, # 'isolated_heartbeat': set up at the end of production.py and development.py }