Clean up caches periodically

Currently they're only cleaned up on demand, which can lead to
unnecessary disk usage on deployments that are not actively used.

Story: #2008909
Task: #42500
Change-Id: Id5b58d1d1b2bbd2988db7a08d4ccfe2166033147
This commit is contained in:
Dmitry Tantsur 2021-09-22 15:17:35 +02:00
parent fe9514f775
commit db4b4c08d9
4 changed files with 23 additions and 0 deletions

View File

@ -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

View File

@ -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,

View File

@ -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):

View File

@ -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.