mirror of
https://github.com/ansible/awx.git
synced 2026-05-21 07:47:44 -02:30
Merge pull request #9907 from fosterseth/feat_a9212_image_cleanup
Add cleanup_images scheduled task SUMMARY #9212 Removes dangling podman images on the system [70e6cc8a] awx.main.tasks Cleanup execution environment images: deleting quay.io/fosterseth/awx-ee:v1, 643 MB ISSUE TYPE Feature Pull Request COMPONENT NAME API AWX VERSION awx: 19.0.0 Reviewed-by: Seth Foster <None> Reviewed-by: Ryan Petrello <ryan@ryanpetrello.com> Reviewed-by: Alan Rominger <arominge@redhat.com> Reviewed-by: Shane McDonald <me@shanemcd.com>
This commit is contained in:
@@ -27,6 +27,7 @@ import socket
|
|||||||
import threading
|
import threading
|
||||||
import concurrent.futures
|
import concurrent.futures
|
||||||
from base64 import b64encode
|
from base64 import b64encode
|
||||||
|
import subprocess
|
||||||
|
|
||||||
# Django
|
# Django
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
@@ -396,6 +397,24 @@ def purge_old_stdout_files():
|
|||||||
logger.debug("Removing {}".format(os.path.join(settings.JOBOUTPUT_ROOT, f)))
|
logger.debug("Removing {}".format(os.path.join(settings.JOBOUTPUT_ROOT, f)))
|
||||||
|
|
||||||
|
|
||||||
|
@task(queue=get_local_queuename)
|
||||||
|
def cleanup_execution_environment_images():
|
||||||
|
if settings.IS_K8S:
|
||||||
|
return
|
||||||
|
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:
|
||||||
|
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)
|
@task(queue=get_local_queuename)
|
||||||
def cluster_node_heartbeat():
|
def cluster_node_heartbeat():
|
||||||
logger.debug("Cluster node heartbeat task.")
|
logger.debug("Cluster node heartbeat task.")
|
||||||
|
|||||||
@@ -439,6 +439,7 @@ CELERYBEAT_SCHEDULE = {
|
|||||||
'task_manager': {'task': 'awx.main.scheduler.tasks.run_task_manager', 'schedule': timedelta(seconds=20), 'options': {'expires': 20}},
|
'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}},
|
'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)},
|
'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=3)},
|
||||||
# 'isolated_heartbeat': set up at the end of production.py and development.py
|
# 'isolated_heartbeat': set up at the end of production.py and development.py
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user