Skip to content

Fix handling of non-existing repos during registry phase 2 migration

João Pereira requested to merge 356984-fix-timestamp into master

Context

Related to #356984 (closed).

This is a fix for a bug introduced in !83746 (merged). Please read that MR description for additional context. Back then we forgot to ensure that the migration_import_done_at attribute on the ContainerRepository object is set when the import is marked as done. This MR fixes that.

Note that all of this migration logic is gated behind a feature flag that is not enabled on gitlab.com.

What does this MR do and why?

Ensures that the migration_import_done_at attribute on the ContainerRepository object is always set when the migration_status transitions to import_done.

How to set up and validate locally

  1. Have a GDK ready with the registry enabled.

  2. Set up the feature flags:

    Feature.enable(:container_registry_migration_phase2_enabled)

We are ready to test things.

  1. Create a dummy image:

    repo = FactoryBot.create(:container_repository, project: Project.first)
  2. Getting a registry set up with all the parts for the migration is quite involved. Instead we're going to "stub" the registry response from the pre import call. Replace ContainerRepository#migration_pre_import with:

    def migration_pre_import
       :already_imported
    end
  3. Comment out the ContainerRepository#start_pre_import function (L262).

  4. Reload the console if necessary:

    reload!
  5. Start the pre-import:

    repo.start_pre_import
  6. Inspect the repo:

    [7] pry(main)> repo
    => #<ContainerRepository:0x00007f9d26b476a0
    id: 10,
    project_id: 88,
    name: "test_image_1",
    created_at: Thu, 31 Mar 2022 13:38:43.340949000 UTC +00:00,
    updated_at: Thu, 31 Mar 2022 13:38:47.594355000 UTC +00:00,
    status: nil,
    expiration_policy_started_at: nil,
    expiration_policy_cleanup_status: "cleanup_unscheduled",
    expiration_policy_completed_at: nil,
    migration_pre_import_started_at: Thu, 31 Mar 2022 13:38:47.583746000 UTC +00:00,
    migration_pre_import_done_at: nil,
    migration_import_started_at: nil,
    migration_import_done_at: Thu, 31 Mar 2022 13:38:47.591828000 UTC +00:00,
    migration_aborted_at: nil,
    migration_skipped_at: nil,
    migration_retries_count: 0,
    migration_skipped_reason: "native_import",
    migration_state: "import_done",
    migration_aborted_in_state: nil,
    migration_plan: nil>

Note that migration_import_done_at is set.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by David Fernandez

Merge request reports