diff --git a/ironic/conductor/manager.py b/ironic/conductor/manager.py index 7fe4c59593..ed54aa67b1 100644 --- a/ironic/conductor/manager.py +++ b/ironic/conductor/manager.py @@ -72,6 +72,7 @@ from ironic.conductor import utils from ironic.conductor import verify from ironic.conf import CONF from ironic.drivers import base as drivers_base +from ironic.drivers.modules import image_cache from ironic import objects from ironic.objects import base as objects_base from ironic.objects import fields @@ -100,6 +101,12 @@ class ConductorManager(base_manager.BaseConductorManager): super(ConductorManager, self).__init__(host, topic) self.power_state_sync_count = collections.defaultdict(int) + @METRICS.timer('ConductorManager._clean_up_caches') + @periodics.periodic(spacing=CONF.conductor.cache_clean_up_interval, + enabled=CONF.conductor.cache_clean_up_interval > 0) + def _clean_up_caches(self, context): + image_cache.clean_up_all() + @METRICS.timer('ConductorManager.create_node') # No need to add these since they are subclasses of InvalidParameterValue: # InterfaceNotFoundInEntrypoint diff --git a/ironic/conf/conductor.py b/ironic/conf/conductor.py index 61d6b32478..f8eb0ff88d 100644 --- a/ironic/conf/conductor.py +++ b/ironic/conf/conductor.py @@ -59,6 +59,10 @@ opts = [ min=0, help=_('Interval between checks of orphaned allocations, ' 'in seconds. Set to 0 to disable checks.')), + cfg.IntOpt('cache_clean_up_interval', + default=3600, min=0, + help=_('Interval between cleaning up image caches, in seconds. ' + 'Set to 0 to disable periodic clean-up.')), cfg.IntOpt('deploy_callback_timeout', default=1800, min=0, diff --git a/ironic/drivers/modules/image_cache.py b/ironic/drivers/modules/image_cache.py index 41ab836fe5..8dde91260a 100644 --- a/ironic/drivers/modules/image_cache.py +++ b/ironic/drivers/modules/image_cache.py @@ -393,6 +393,13 @@ def clean_up_caches(ctx, directory, images_info): _clean_up_caches(directory, total_size) +def clean_up_all(): + """Clean up all entries from all caches.""" + caches_to_clean = [x[1]() for x in _cache_cleanup_list] + for cache in caches_to_clean: + cache.clean_up() + + def cleanup(priority): """Decorator method for adding cleanup priority to a class.""" def _add_property_to_class_func(cls): diff --git a/releasenotes/notes/periodic-clean-up-29c33d2516bf16ec.yaml b/releasenotes/notes/periodic-clean-up-29c33d2516bf16ec.yaml new file mode 100644 index 0000000000..4e84aeb01a --- /dev/null +++ b/releasenotes/notes/periodic-clean-up-29c33d2516bf16ec.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + All image caches are now cleaned up periodically, not only when used. + Set ``[conductor]cache_clean_up_interval`` to tune the interval or disable.