From 112156321fceeb4a6c845970d971cec84a3f0794 Mon Sep 17 00:00:00 2001 From: Liang Zheng Date: Fri, 19 Apr 2024 12:03:24 +0800 Subject: [PATCH] fix: ignore error of manifest tag path not found in gc it is reasonable to ignore the error that the manifest tag path does not exist when querying all tags of the specified repository when executing gc. Signed-off-by: Liang Zheng --- registry/storage/garbagecollect.go | 3 ++- registry/storage/garbagecollect_test.go | 33 +++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/registry/storage/garbagecollect.go b/registry/storage/garbagecollect.go index 87046b76..23229e3d 100644 --- a/registry/storage/garbagecollect.go +++ b/registry/storage/garbagecollect.go @@ -73,7 +73,8 @@ func MarkAndSweep(ctx context.Context, storageDriver driver.StorageDriver, regis // which means that we need check (and delete) those references when deleting manifest allTags, err := repository.Tags(ctx).All(ctx) if err != nil { - if _, ok := err.(distribution.ErrManifestUnknownRevision); !ok { + if _, ok := err.(distribution.ErrRepositoryUnknown); ok { + emit("manifest tags path of repository %s does not exist", repoName) return nil } return fmt.Errorf("failed to retrieve tags %v", err) diff --git a/registry/storage/garbagecollect_test.go b/registry/storage/garbagecollect_test.go index eb133701..f9990c68 100644 --- a/registry/storage/garbagecollect_test.go +++ b/registry/storage/garbagecollect_test.go @@ -416,6 +416,39 @@ func TestDeleteManifestIndexIfTagNotFound(t *testing.T) { } } +func TestGCWithUnknownRepository(t *testing.T) { + ctx := dcontext.Background() + d := inmemory.New() + + registry := createRegistry(t, d) + repo := makeRepository(t, registry, "nonexistentrepo") + image := uploadRandomSchema2Image(t, repo) + + err := repo.Tags(ctx).Tag(ctx, "image", distribution.Descriptor{Digest: image.manifestDigest}) + if err != nil { + t.Fatalf("Failed to tag descriptor: %v", err) + } + + // Simulate a missing _manifests/tags directory + manifestTagsPath, err := pathFor(manifestTagsPathSpec{"nonexistentrepo"}) + if err != nil { + t.Fatal(err) + } + + err = d.Delete(ctx, manifestTagsPath) + if err != nil { + t.Fatal(err) + } + + err = MarkAndSweep(dcontext.Background(), d, registry, GCOpts{ + DryRun: false, + RemoveUntagged: true, + }) + if err != nil { + t.Fatalf("got error: %v, expected nil", err) + } +} + func TestGCWithMissingManifests(t *testing.T) { ctx := dcontext.Background() d := inmemory.New()