Skip to content

Commit

Permalink
fix gc dry run issue
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
wy65701436 authored and chlins committed Aug 18, 2023
1 parent c7e2529 commit 44291d5
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/jobservice/job/impl/gc/garbage_collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,22 +541,31 @@ 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
}
gc.logger.Info("start to delete untagged artifact (no actually deletion for dry-run mode)")
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

Check warning on line 566 in src/jobservice/job/impl/gc/garbage_collection.go

View check run for this annotation

Codecov / codecov/patch

src/jobservice/job/impl/gc/garbage_collection.go#L552-L566

Added lines #L552 - L566 were not covered by tests
}
allTrashedArts = append(allTrashedArts, simulateDeletion)
allTrashedArts = append(allTrashedArts, simulateDeletions...)

Check warning on line 568 in src/jobservice/job/impl/gc/garbage_collection.go

View check run for this annotation

Codecov / codecov/patch

src/jobservice/job/impl/gc/garbage_collection.go#L568

Added line #L568 was not covered by tests
} else {
if gc.shouldStop(ctx) {
return nil, errGcStop
Expand Down

0 comments on commit 44291d5

Please sign in to comment.