Skip to content

Commit

Permalink
Add a more detailed error message for potential auth fails in docker …
Browse files Browse the repository at this point in the history
…pull.
  • Loading branch information
brendandburns committed Feb 13, 2015
1 parent e27d534 commit 0532c46
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
9 changes: 9 additions & 0 deletions pkg/credentialprovider/keyring.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,12 @@ func (dk *lazyDockerKeyring) Lookup(image string) (docker.AuthConfiguration, boo

return keyring.Lookup(image)
}

type FakeKeyring struct {
auth docker.AuthConfiguration
ok bool
}

func (f *FakeKeyring) Lookup(image string) (docker.AuthConfiguration, bool) {
return f.auth, f.ok
}
16 changes: 15 additions & 1 deletion pkg/kubelet/dockertools/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,21 @@ func (p dockerPuller) Pull(image string) error {
glog.V(1).Infof("Pulling image %s without credentials", image)
}

return p.client.PullImage(opts, creds)
err := p.client.PullImage(opts, creds)
// If there was no error, or we had credentials, just return the error.
if err == nil || ok {
return err
}
// Image spec: [<registry>/]<repository>/<image>[:<version] so we count '/'
explicitRegistry := (strings.Count(image, "/") == 2)
glog.Errorf("Foo: %s", explicitRegistry)
// Hack, look for a private registry, and decorate the error with the lack of
// credentials. This is heuristic, and really probably could be done better
// by talking to the registry API directly from the kubelet here.
if explicitRegistry {
return fmt.Errorf("image pull failed for %s, this may be because there are no credentials on this request. details: (%v)", image, err)
}
return err
}

func (p throttledDockerPuller) Pull(image string) error {
Expand Down
21 changes: 21 additions & 0 deletions pkg/kubelet/dockertools/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,27 @@ func TestParseImageName(t *testing.T) {
}
}

func TestDockerKeyringLookupFails(t *testing.T) {
fakeKeyring := &credentialprovider.FakeKeyring{}
fakeClient := &FakeDockerClient{
Err: fmt.Errorf("test error"),
}

dp := dockerPuller{
client: fakeClient,
keyring: fakeKeyring,
}

err := dp.Pull("host/repository/image:version")
if err == nil {
t.Errorf("unexpected non-error")
}
msg := "image pull failed for host/repository/image, this may be because there are no credentials on this request. details: (test error)"
if err.Error() != msg {
t.Errorf("expected: %s, saw: %s", msg, err.Error())
}
}

func TestDockerKeyringLookup(t *testing.T) {
empty := docker.AuthConfiguration{}

Expand Down

0 comments on commit 0532c46

Please sign in to comment.