Improve ContainerExpirationPolicyWorker to only select policies linked to container repositories.
Summary
The ContainerExpirationPolicyWorker
is the worker in charge of executing cleanup policies.
This worker currently select all runnable policies and execute them.
The issue is that when a project is created, it gets a default cleanup policy. This default policy will get picked up by the worker although the project doesn't have any container repository.
Improvements
- In
ContainerExpirationPolicyWorker
, select policies that are:- runnable
- are linked to a project with container repositories
- Implement the above by introducing a scope (perhaps,
ContainerRepository.executable
) at the model level - By having a more precise selection of the policies, we don't spend worker computation time on policies that will result in a no op during their execution.
Risks
- The cleanup policies are going through a heavy change to implement limits. Do not implement this issue before this heavy change is merged.
Involved components
- https://gitlab.com/gitlab-org/gitlab/-/blob/master/app/workers/container_expiration_policy_worker.rb
Optional: Intended side effects
Optional: Missing test coverage
Edited by David Fernandez