Skip to content

Commit

Permalink
Merge pull request #729 from kayac/fix/retry-registry
Browse files Browse the repository at this point in the history
Fix/retry registry
  • Loading branch information
fujiwara authored Jul 27, 2024
2 parents 968760f + 348d4ee commit c9ee2f6
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions registry/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,26 @@ func (c *Repository) fetchManifests(ctx context.Context, method, tag string) (*h
}

func (c *Repository) getAvailability(ctx context.Context, tag string) (*http.Response, error) {
resp, err := c.fetchManifests(ctx, http.MethodHead, tag)
if err != nil {
return nil, err
retryer := retryPolicy.Start(ctx)
for retryer.Continue() {
resp, err := c.fetchManifests(ctx, http.MethodHead, tag)
if err != nil {
return nil, err
}
resp.Body.Close()
if resp.StatusCode == http.StatusTooManyRequests {
continue
} else {
return resp, nil
}
}
resp.Body.Close()
return resp, nil
return nil, fmt.Errorf("failed to fetch manifests: %w", ErrPullRateLimitExceeded)
}

func (c *Repository) getManifests(ctx context.Context, tag string) (mediaType string, _ io.ReadCloser, _ error) {
retrier := retryPolicy.Start(ctx)
retryer := retryPolicy.Start(ctx)
var lastErr error
for retrier.Continue() {
for retryer.Continue() {
resp, err := c.fetchManifests(ctx, http.MethodGet, tag)
if err == nil && resp.StatusCode == http.StatusOK {
mediaType = parseContentType(resp.Header.Get("Content-Type"))
Expand All @@ -139,14 +147,14 @@ func (c *Repository) getManifests(ctx context.Context, tag string) (mediaType st
switch resp.StatusCode {
case http.StatusNotFound, http.StatusUnauthorized:
// should not be retried
return "", nil, fmt.Errorf("faild to fetch manifests: %s", resp.Status)
return "", nil, fmt.Errorf("failed to fetch manifests: %s %d", resp.Status, resp.StatusCode)
case http.StatusTooManyRequests:
lastErr = ErrPullRateLimitExceeded
default:
lastErr = fmt.Errorf(resp.Status)
}
}
return "", nil, fmt.Errorf("faild to fetch manifests: %w", lastErr)
return "", nil, fmt.Errorf("failed to fetch manifests: %w", lastErr)
}

func (c *Repository) getImageConfig(ctx context.Context, digest string) (io.ReadCloser, error) {
Expand Down

0 comments on commit c9ee2f6

Please sign in to comment.