mirror of
https://github.com/goharbor/harbor.git
synced 2025-01-26 17:41:25 +01:00
fix gc dry run issue (#19208)
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:
parent
c7e25295fe
commit
927e7f92a2
@ -541,7 +541,7 @@ func (gc *GarbageCollector) deletedArt(ctx job.Context) (map[string][]model.Arti
|
|||||||
Keywords: map[string]interface{}{
|
Keywords: map[string]interface{}{
|
||||||
"Tags": "nil",
|
"Tags": "nil",
|
||||||
},
|
},
|
||||||
}, nil)
|
}, &artifact.Option{WithAccessory: true})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return artMap, err
|
return artMap, err
|
||||||
}
|
}
|
||||||
@ -549,14 +549,23 @@ func (gc *GarbageCollector) deletedArt(ctx job.Context) (map[string][]model.Arti
|
|||||||
for _, untagged := range untaggedArts {
|
for _, untagged := range untaggedArts {
|
||||||
// for dryRun, just simulate the artifact deletion, move the artifact to artifact trash
|
// for dryRun, just simulate the artifact deletion, move the artifact to artifact trash
|
||||||
if gc.dryRun {
|
if gc.dryRun {
|
||||||
simulateDeletion := model.ArtifactTrash{
|
var simulateDeletions []model.ArtifactTrash
|
||||||
MediaType: untagged.MediaType,
|
err = gc.artCtl.Walk(ctx.SystemContext(), untagged, func(a *artifact.Artifact) error {
|
||||||
ManifestMediaType: untagged.ManifestMediaType,
|
simulateDeletion := model.ArtifactTrash{
|
||||||
RepositoryName: untagged.RepositoryName,
|
MediaType: a.MediaType,
|
||||||
Digest: untagged.Digest,
|
ManifestMediaType: a.ManifestMediaType,
|
||||||
CreationTime: time.Now(),
|
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 {
|
} else {
|
||||||
if gc.shouldStop(ctx) {
|
if gc.shouldStop(ctx) {
|
||||||
return nil, errGcStop
|
return nil, errGcStop
|
||||||
|
Loading…
Reference in New Issue
Block a user