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

Add a more detailed error message for potential auth fails in docker pull. #4285

Merged
merged 1 commit into from
Feb 13, 2015
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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