fix gc delete manifest log issue (#15495)

It needs to use the logger to print error log when timeout, otherwise, it will be dropped.

Signed-off-by: Wang Yan <wangyan@vmware.com>
This commit is contained in:
Wang Yan 2021-08-30 13:40:33 +08:00 committed by GitHub
parent d482a0c323
commit e0c4ebd84d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 8 deletions

View File

@ -260,7 +260,7 @@ func (gc *GarbageCollector) sweep(ctx job.Context) error {
// Harbor cannot know the existing tags in the backend from its database, so let the v2 DELETE manifest to remove all of them.
gc.logger.Infof("delete the manifest with registry v2 API: %s, %s, %s",
art.RepositoryName, blob.ContentType, blob.Digest)
if err := v2DeleteManifest(art.RepositoryName, blob.Digest); err != nil {
if err := v2DeleteManifest(gc.logger, art.RepositoryName, blob.Digest); err != nil {
gc.logger.Errorf("failed to delete manifest with v2 API, %s, %s, %v", art.RepositoryName, blob.Digest, err)
if err := ignoreNotFound(func() error {
return gc.markDeleteFailed(ctx, blob)
@ -276,7 +276,7 @@ func (gc *GarbageCollector) sweep(ctx job.Context) error {
return gc.registryCtlClient.DeleteManifest(art.RepositoryName, blob.Digest)
})
}, retry.Callback(func(err error, sleep time.Duration) {
gc.logger.Infof("failed to exec DeleteManifest retry after %s : %v", sleep, err)
gc.logger.Infof("failed to exec DeleteManifest, error: %v, will retry again after: %s", err, sleep)
})); err != nil {
if err := ignoreNotFound(func() error {
return gc.markDeleteFailed(ctx, blob)
@ -304,7 +304,7 @@ func (gc *GarbageCollector) sweep(ctx job.Context) error {
return gc.registryCtlClient.DeleteBlob(blob.Digest)
})
}, retry.Callback(func(err error, sleep time.Duration) {
gc.logger.Infof("failed to exec DeleteBlob retry after %s : %v", sleep, err)
gc.logger.Infof("failed to exec DeleteBlob, error: %v, will retry again after: %s", err, sleep)
})); err != nil {
if err := ignoreNotFound(func() error {
return gc.markDeleteFailed(ctx, blob)
@ -461,19 +461,19 @@ func (gc *GarbageCollector) markOrSweepUntaggedBlobs(ctx job.Context) []*blob_mo
}
blobs, err := gc.blobMgr.List(ctx.SystemContext(), q)
if err != nil {
gc.logger.Errorf("failed to get blobs of project, %v", err)
gc.logger.Errorf("failed to get blobs of project: %d, %v", p.ProjectID, err)
break
}
if gc.dryRun {
unassociated, err := gc.blobMgr.FindBlobsShouldUnassociatedWithProject(ctx.SystemContext(), p.ProjectID, blobs)
if err != nil {
gc.logger.Errorf("failed to find untagged blobs of project, %v", err)
gc.logger.Errorf("failed to find untagged blobs of project: %d, %v", p.ProjectID, err)
break
}
untaggedBlobs = append(untaggedBlobs, unassociated...)
} else {
if err := gc.blobMgr.CleanupAssociationsForProject(ctx.SystemContext(), p.ProjectID, blobs); err != nil {
gc.logger.Errorf("failed to clean untagged blobs of project, %v", err)
gc.logger.Errorf("failed to clean untagged blobs of project: %d, %v", p.ProjectID, err)
break
}
}

View File

@ -4,6 +4,7 @@ import (
"fmt"
"time"
"github.com/goharbor/harbor/src/jobservice/logger"
"github.com/goharbor/harbor/src/lib/errors"
"github.com/goharbor/harbor/src/lib/retry"
"github.com/goharbor/harbor/src/pkg/registry"
@ -43,7 +44,7 @@ func delKeys(con redis.Conn, pattern string) error {
}
// v2DeleteManifest calls the registry API to remove manifest
func v2DeleteManifest(repository, digest string) error {
func v2DeleteManifest(logger logger.Interface, repository, digest string) error {
exist, _, err := registry.Cli.ManifestExist(repository, digest)
if err != nil {
return err
@ -56,7 +57,7 @@ func v2DeleteManifest(repository, digest string) error {
return retry.Retry(func() error {
return registry.Cli.DeleteManifest(repository, digest)
}, retry.Callback(func(err error, sleep time.Duration) {
fmt.Printf("failed to exec DeleteManifest retry after %s : %v\n", sleep, err)
logger.Infof("failed to exec v2DeleteManifest, error: %v, will retry again after: %s", err, sleep)
}))
}