fix gc log issue (#12943)

1, Do not log redis url, just log the user input from UI.
2, Format the artifact trash items.

Signed-off-by: wang yan <wangyan@vmware.com>
This commit is contained in:
Wang Yan 2020-09-02 17:11:05 +08:00 committed by GitHub
parent 05489fca1e
commit 262f22f5ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 10 deletions

View File

@ -112,7 +112,6 @@ func (gc *GarbageCollector) init(ctx job.Context, params job.Parameters) error {
// parseParams set the parameters according to the GC API call. // parseParams set the parameters according to the GC API call.
func (gc *GarbageCollector) parseParams(params job.Parameters) { func (gc *GarbageCollector) parseParams(params job.Parameters) {
// redis url // redis url
gc.logger.Info(params)
gc.redisURL = params["redis_url_reg"].(string) gc.redisURL = params["redis_url_reg"].(string)
// delete untagged: default is to delete the untagged artifact // delete untagged: default is to delete the untagged artifact
@ -141,6 +140,9 @@ func (gc *GarbageCollector) parseParams(params job.Parameters) {
gc.dryRun = dryRun gc.dryRun = dryRun
} }
} }
gc.logger.Infof("Garbage Collection parameters: [delete_untagged: %t, dry_run: %t, time_window: %d]",
gc.deleteUntagged, gc.dryRun, gc.timeWindowHours)
} }
// Run implements the interface in job/Interface // Run implements the interface in job/Interface
@ -395,18 +397,21 @@ func (gc *GarbageCollector) deletedArt(ctx job.Context) (map[string][]model.Arti
} }
// group the deleted artifact by digest. The repositories of blob is needed when to delete as a manifest. // group the deleted artifact by digest. The repositories of blob is needed when to delete as a manifest.
for _, art := range arts { if len(arts) > 0 {
_, exist := artMap[art.Digest] gc.logger.Info("artifact trash candidates.")
if !exist { for _, art := range arts {
artMap[art.Digest] = []model.ArtifactTrash{art} gc.logger.Info(art.String())
} else { _, exist := artMap[art.Digest]
repos := artMap[art.Digest] if !exist {
repos = append(repos, art) artMap[art.Digest] = []model.ArtifactTrash{art}
artMap[art.Digest] = repos } else {
repos := artMap[art.Digest]
repos = append(repos, art)
artMap[art.Digest] = repos
}
} }
} }
gc.logger.Info("required candidate: %+v", arts)
return artMap, nil return artMap, nil
} }

View File

@ -15,6 +15,7 @@
package model package model
import ( import (
"fmt"
"github.com/astaxie/beego/orm" "github.com/astaxie/beego/orm"
"time" "time"
) )
@ -37,3 +38,8 @@ type ArtifactTrash struct {
func (at *ArtifactTrash) TableName() string { func (at *ArtifactTrash) TableName() string {
return "artifact_trash" return "artifact_trash"
} }
func (at *ArtifactTrash) String() string {
return fmt.Sprintf("ID-%d MediaType-%s ManifestMediaType-%s RepositoryName-%s Digest-%s CreationTime-%s",
at.ID, at.MediaType, at.ManifestMediaType, at.RepositoryName, at.Digest, at.CreationTime.Format("2006-01-02 15:04:05"))
}