Skip to content

Commit

Permalink
feat(harbor): try to get the image again due to PROJECTPOLICYVIOLATIO…
Browse files Browse the repository at this point in the history
…N error

Signed-off-by: Aleksei Igrychev <aleksei.igrychev@palark.com>
  • Loading branch information
alexey-igrychev committed May 23, 2024
1 parent 6f72408 commit b7044c1
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion pkg/docker_registry/harbor.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,21 @@ import (
"errors"
"net/http"
"strings"
"time"

"github.com/cenkalti/backoff/v4"
"github.com/google/go-containerregistry/pkg/name"

"github.com/werf/logboek"
"github.com/werf/werf/v2/pkg/image"
)

const (
HarborImplementationName = "harbor"
harborRepositoryNotFoundErrPrefix = "harbor repository not found: "
)

var harborPatterns = []string{"^harbor\\..*"}
var harborPatterns = []string{"^harbor\\..*", "demo\\.goharbor\\.io"}

type HarborRepositoryNotFoundErr apiError

Expand Down Expand Up @@ -59,6 +64,38 @@ func newHarbor(options harborOptions) (*harbor, error) {
return harbor, nil
}

func (r *harbor) GetRepoImage(ctx context.Context, reference string) (*image.Info, error) {
var info *image.Info
operation := func() error {
var err error
info, err = r.api.GetRepoImage(ctx, reference)
if err != nil {
if strings.Contains(err.Error(), "PROJECTPOLICYVIOLATION") {
return err
}

// Do not retry on other errors.
return backoff.Permanent(err)
}
return nil
}

notify := func(err error, duration time.Duration) {
logboek.Context(ctx).Warn().LogF("WARNING: %s. Retrying in %v...\n", err.Error(), duration)
}

eb := backoff.NewExponentialBackOff()
eb.InitialInterval = 2 * time.Second
eb.MaxElapsedTime = 2 * time.Minute // Maximum time for all retries.

err := backoff.RetryNotify(operation, eb, notify)
if err != nil {
return nil, err
}

return info, nil
}

func (r *harbor) DeleteRepo(ctx context.Context, reference string) error {
return r.deleteRepo(ctx, reference)
}
Expand Down

0 comments on commit b7044c1

Please sign in to comment.