Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retry import from the DockerHub on 401 #8574

Merged
merged 1 commit into from
Apr 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions pkg/dockerregistry/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ type v2repository struct {
name string
endpoint url.URL
token string
retries int
}

// v2tags describes the tags/list returned by the Docker V2 registry.
Expand Down Expand Up @@ -482,6 +483,13 @@ func (repo *v2repository) getTags(c *connection) (map[string]string, error) {
switch code := resp.StatusCode; {
case code == http.StatusUnauthorized:
if len(repo.token) != 0 {
// The DockerHub returns JWT tokens that take effect at "now" at second resolution, which means clients can
// be rejected when requests are made near the time boundary.
if repo.retries > 0 {
repo.retries--
time.Sleep(time.Second / 2)
return repo.getTags(c)
}
delete(c.cached, repo.name)
// docker will not return a NotFound on any repository URL - for backwards compatibilty, return NotFound on the
// repo
Expand All @@ -491,6 +499,7 @@ func (repo *v2repository) getTags(c *connection) (map[string]string, error) {
if err != nil {
return nil, fmt.Errorf("error getting image tags for %s: %v", repo.name, err)
}
repo.retries = 2
repo.token = token
return repo.getTags(c)

Expand Down Expand Up @@ -532,6 +541,13 @@ func (repo *v2repository) getTaggedImage(c *connection, tag, userTag string) (*I
switch code := resp.StatusCode; {
case code == http.StatusUnauthorized:
if len(repo.token) != 0 {
// The DockerHub returns JWT tokens that take effect at "now" at second resolution, which means clients can
// be rejected when requests are made near the time boundary.
if repo.retries > 0 {
repo.retries--
time.Sleep(time.Second / 2)
return repo.getTaggedImage(c, tag, userTag)
}
delete(c.cached, repo.name)
// docker will not return a NotFound on any repository URL - for backwards compatibilty, return NotFound on the
// repo
Expand All @@ -543,6 +559,7 @@ func (repo *v2repository) getTaggedImage(c *connection, tag, userTag string) (*I
if err != nil {
return nil, fmt.Errorf("error getting image for %s:%s: %v", repo.name, tag, err)
}
repo.retries = 2
repo.token = token
return repo.getTaggedImage(c, tag, userTag)
case code == http.StatusNotFound:
Expand Down
Loading