Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix gc dry run issue #19208

Merged
merged 1 commit into from Aug 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 17 additions & 8 deletions src/jobservice/job/impl/gc/garbage_collection.go
Expand Up @@ -541,22 +541,31 @@
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