fix gc dry run issue (#19210)

In the dry run mode, the accessories should be considered when try to simulate delete the subject manifest.

Signed-off-by: wang yan <wangyan@vmware.com>
This commit is contained in:
Wang Yan 2023-08-18 13:27:50 +08:00 committed by GitHub
parent 62ed9fc947
commit 0507655fda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 8 deletions

View File

@ -541,7 +541,7 @@ func (gc *GarbageCollector) deletedArt(ctx job.Context) (map[string][]model.Arti
Keywords: map[string]interface{}{
"Tags": "nil",
},
}, nil)
}, &artifact.Option{WithAccessory: true})
if err != nil {
return artMap, err
}
@ -549,14 +549,23 @@ func (gc *GarbageCollector) deletedArt(ctx job.Context) (map[string][]model.Arti
for _, untagged := range untaggedArts {
// for dryRun, just simulate the artifact deletion, move the artifact to artifact trash
if gc.dryRun {
simulateDeletion := model.ArtifactTrash{
MediaType: untagged.MediaType,
ManifestMediaType: untagged.ManifestMediaType,
RepositoryName: untagged.RepositoryName,
Digest: untagged.Digest,
CreationTime: time.Now(),
var simulateDeletions []model.ArtifactTrash
err = gc.artCtl.Walk(ctx.SystemContext(), untagged, func(a *artifact.Artifact) error {
simulateDeletion := model.ArtifactTrash{
MediaType: a.MediaType,
ManifestMediaType: a.ManifestMediaType,
RepositoryName: a.RepositoryName,
Digest: a.Digest,
CreationTime: time.Now(),
}
simulateDeletions = append(simulateDeletions, simulateDeletion)
return nil
}, &artifact.Option{WithAccessory: true})
if err != nil {
gc.logger.Errorf("walk the artifact %s failed, error: %v", untagged.Digest, err)
continue
}
allTrashedArts = append(allTrashedArts, simulateDeletion)
allTrashedArts = append(allTrashedArts, simulateDeletions...)
} else {
if gc.shouldStop(ctx) {
return nil, errGcStop