Skip to content

Add post deployment migration for cleanup policies

Context

In !61983 (merged), we created a background migration to disable all enabled cleanup policies for projects that don't have any container registry image.

This is done for ~performance reasons: we have a database index referencing all the enabled policies. Background jobs that process cleanup policies use that index extensively to locate and order the container registry image to cleanup. See #330315 (closed).

The background migration was properly executed except for 3 jobs which account for ~90 000 policies on gitlab.com.

I choose to not re-schedule the background migration but have a simpler post deployment migration for those left overs.

In the future, we will update an existing cron job to take care of those policies on a recurrent basis: !62461 (merged). documentation has been updated there.

🤔 What does this MR do?

  • Add a post deploy migration that will disable enabled policies linked to no container registry images.
  • Add the related specs.

📸 Screenshots (strongly suggested)

n / a

📏 Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

Does this MR contain changes to processing or storing of credentials or tokens, authorization and authentication methods or other items described in the security review guidelines? If not, then delete this Security section.

  • [-] Label as security and @ mention @gitlab-com/gl-security/appsec
  • [-] The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • [-] Security reports checked/validated by a reviewer from the AppSec team

💽 Database review

Up

$ rails db:migrate
== 20210610141711 DisableExpirationPoliciesLinkedToNoContainerImages: migrating 
-- execute("        WITH batched_relation AS MATERIALIZED (SELECT \"container_expiration_policies\".* FROM \"container_expiration_policies\" WHERE \"container_expiration_policies\".\"enabled\" = TRUE AND \"container_expiration_policies\".\"project_id\" >= 76 LIMIT 1000)\n        UPDATE container_expiration_policies\n        SET enabled = FALSE\n        FROM batched_relation\n        WHERE container_expiration_policies.project_id = batched_relation.project_id\n        AND NOT EXISTS (SELECT 1 FROM \"container_repositories\" WHERE container_repositories.project_id = container_expiration_policies.project_id)\n")
   -> 0.0072s
== 20210610141711 DisableExpirationPoliciesLinkedToNoContainerImages: migrated (0.0274s) 

Down

$ rails db:rollback
== 20210610141711 DisableExpirationPoliciesLinkedToNoContainerImages: reverting 
== 20210610141711 DisableExpirationPoliciesLinkedToNoContainerImages: reverted (0.0000s) 

Queries / Explain plans

Edited by David Fernandez

Merge request reports