[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:
Danny Kulchinsky 2023-06-12 04:33:20 -04:00 committed by GitHub
parent 0b55284ee3
commit f8282a56ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 16 deletions

View File

@ -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)

View File

@ -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