Skip to content

Commit

Permalink
Merge pull request #4959 from gyrter/update_selectel_implementation
Browse files Browse the repository at this point in the history
Update UX for selectel registry implementation
  • Loading branch information
distorhead committed Sep 27, 2022
2 parents 5de673d + 1aa250a commit 66349fc
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 23 deletions.
14 changes: 13 additions & 1 deletion pkg/docker_registry/selectel.go
Expand Up @@ -92,7 +92,11 @@ func (r *selectel) DeleteRepoImage(ctx context.Context, repoImage *image.Info) e
}

func (r *selectel) Tags(ctx context.Context, reference string, _ ...Option) ([]string, error) {
return r.tags(ctx, reference)
if r.hasExtraCredentials() {
return r.tags(ctx, reference)
}

return r.api.tags(ctx, reference)
}

func (r *selectel) deleteRepoImage(ctx context.Context, repoImage *image.Info) error {
Expand Down Expand Up @@ -231,3 +235,11 @@ func (r *selectel) parseReference(reference string) (string, string, string, err
repository := url.QueryEscape(strings.Join(repositoryParts[1:], "/"))
return parsedReference.RegistryStr(), repositoryParts[0], repository, nil
}

func (r *selectel) hasExtraCredentials() bool {
credentials := selectelCredentials(r.selectelCredentials)
if credentials.username != "" && credentials.password != "" && credentials.account != "" && (credentials.vpc != "" || credentials.vpcID != "") {
return true
}
return false
}
46 changes: 24 additions & 22 deletions pkg/docker_registry/selectel_api.go
Expand Up @@ -188,31 +188,33 @@ func (api *selectelApi) getTags(ctx context.Context, hostname, registryId, repos
}

func (api *selectelApi) doRequest(ctx context.Context, method, url string, body io.Reader, options doRequestOptions) (*http.Response, []byte, error) {
var seconds int
resp, respBody, err := doRequest(ctx, method, url, body, options)
if err != nil {
if resp != nil && resp.Header.Get("Retry-After") != "" {
secondsString := resp.Header.Get("Retry-After")
seconds, err := strconv.Atoi(secondsString)
if err == nil {
sleepSeconds := seconds + rand.Intn(15) + 5
workerId := ctx.Value(parallelConstant.CtxBackgroundTaskIDKey)
if workerId != nil {
logboek.Context(ctx).Warn().LogF(
"WARNING: Rate limit error occurred. Waiting for %d before retrying request... (worker %d).\nThe --parallel ($WERF_PARALLEL) and --parallel-tasks-limit ($WERF_PARALLEL_TASKS_LIMIT) options can be used to regulate parallel tasks.\n",
sleepSeconds,
workerId.(int),
)
logboek.Context(ctx).Warn().LogLn()
} else {
logboek.Context(ctx).Warn().LogF(
"WARNING: Rate limit error occurred. Waiting for %d before retrying request...\n",
sleepSeconds,
)
}

time.Sleep(time.Second * time.Duration(sleepSeconds))
return api.doRequest(ctx, method, url, body, options)
if resp != nil && resp.StatusCode == http.StatusTooManyRequests {
if resp.Header.Get("Retry-After") != "" {
secondsString := resp.Header.Get("Retry-After")
seconds, _ = strconv.Atoi(secondsString)
}

sleepSeconds := seconds + rand.Intn(15) + 5
workerId := ctx.Value(parallelConstant.CtxBackgroundTaskIDKey)
if workerId != nil {
logboek.Context(ctx).Warn().LogF(
"WARNING: Rate limit error occurred. Waiting for %d before retrying request... (worker %d).\nThe --parallel ($WERF_PARALLEL) and --parallel-tasks-limit ($WERF_PARALLEL_TASKS_LIMIT) options can be used to regulate parallel tasks.\n",
sleepSeconds,
workerId.(int),
)
logboek.Context(ctx).Warn().LogLn()
} else {
logboek.Context(ctx).Warn().LogF(
"WARNING: Rate limit error occurred. Waiting for %d before retrying request...\n",
sleepSeconds,
)
}

time.Sleep(time.Second * time.Duration(sleepSeconds))
return api.doRequest(ctx, method, url, body, options)
}

return resp, respBody, err
Expand Down

0 comments on commit 66349fc

Please sign in to comment.