mirror of
https://github.com/goharbor/harbor.git
synced 2024-10-31 23:59:32 +01:00
[cherry-pick][2.8] fix: add retry on the caller of v2DeleteManifest instead within v2DeleteManifest (#18803)
fix: add retry on the caller of v2DeleteManifest instead within v2DeleteManifest Signed-off-by: Danny Kulchinsky <dkulchinsky@fastly.com>
This commit is contained in:
parent
0b55284ee3
commit
f8282a56ea
@ -282,7 +282,18 @@ 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("[%d/%d] delete the manifest with registry v2 API: %s, %s, %s",
|
||||
idx, total, art.RepositoryName, blob.ContentType, blob.Digest)
|
||||
if err := v2DeleteManifest(gc.logger, art.RepositoryName, blob.Digest); err != nil {
|
||||
if err := retry.Retry(func() error {
|
||||
return ignoreNotFound(func() error {
|
||||
err := v2DeleteManifest(art.RepositoryName, blob.Digest)
|
||||
// if the system is in read-only mode, return an Abort error to skip retrying
|
||||
if err == readonly.Err {
|
||||
return retry.Abort(err)
|
||||
}
|
||||
return err
|
||||
})
|
||||
}, retry.Callback(func(err error, sleep time.Duration) {
|
||||
gc.logger.Infof("[%d/%d] failed to exec v2DeleteManifest, error: %v, will retry again after: %s", idx, total, err, sleep)
|
||||
})); err != nil {
|
||||
gc.logger.Errorf("[%d/%d] failed to delete manifest with v2 API, %s, %s, %v", idx, total, art.RepositoryName, blob.Digest, err)
|
||||
if err := ignoreNotFound(func() error {
|
||||
return gc.markDeleteFailed(ctx, blob)
|
||||
|
@ -2,15 +2,11 @@ package gc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/gomodule/redigo/redis"
|
||||
|
||||
"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"
|
||||
"github.com/goharbor/harbor/src/pkg/registry/interceptor/readonly"
|
||||
)
|
||||
|
||||
// delKeys ...
|
||||
@ -46,7 +42,7 @@ func delKeys(con redis.Conn, pattern string) error {
|
||||
}
|
||||
|
||||
// v2DeleteManifest calls the registry API to remove manifest
|
||||
func v2DeleteManifest(logger logger.Interface, repository, digest string) error {
|
||||
func v2DeleteManifest(repository, digest string) error {
|
||||
exist, _, err := registry.Cli.ManifestExist(repository, digest)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -56,16 +52,7 @@ func v2DeleteManifest(logger logger.Interface, repository, digest string) error
|
||||
if !exist {
|
||||
return nil
|
||||
}
|
||||
return retry.Retry(func() error {
|
||||
err := registry.Cli.DeleteManifest(repository, digest)
|
||||
// if the system is in read-only mode, return an Abort error to skip retrying
|
||||
if err == readonly.Err {
|
||||
return retry.Abort(err)
|
||||
}
|
||||
return err
|
||||
}, retry.Callback(func(err error, sleep time.Duration) {
|
||||
logger.Infof("failed to exec v2DeleteManifest, error: %v, will retry again after: %s", err, sleep)
|
||||
}))
|
||||
return registry.Cli.DeleteManifest(repository, digest)
|
||||
}
|
||||
|
||||
// ignoreNotFound ignores the NotFoundErr error
|
||||
|
Loading…
Reference in New Issue
Block a user