-
Notifications
You must be signed in to change notification settings - Fork 38.7k
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
Refactor image related functions to use docker engine-api #23800
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,6 @@ import ( | |
"github.com/docker/docker/pkg/jsonmessage" | ||
dockerapi "github.com/docker/engine-api/client" | ||
dockertypes "github.com/docker/engine-api/types" | ||
docker "github.com/fsouza/go-dockerclient" | ||
"github.com/golang/glog" | ||
"k8s.io/kubernetes/pkg/api" | ||
"k8s.io/kubernetes/pkg/credentialprovider" | ||
|
@@ -64,10 +63,10 @@ type DockerInterface interface { | |
StartContainer(id string) error | ||
StopContainer(id string, timeout int) error | ||
RemoveContainer(id string, opts dockertypes.ContainerRemoveOptions) error | ||
InspectImage(image string) (*docker.Image, error) | ||
ListImages(opts docker.ListImagesOptions) ([]docker.APIImages, error) | ||
PullImage(opts docker.PullImageOptions, auth docker.AuthConfiguration) error | ||
RemoveImage(image string) error | ||
InspectImage(image string) (*dockertypes.ImageInspect, error) | ||
ListImages(opts dockertypes.ImageListOptions) ([]dockertypes.Image, error) | ||
PullImage(image string, auth dockertypes.AuthConfig, opts dockertypes.ImagePullOptions) error | ||
RemoveImage(image string, opts dockertypes.ImageRemoveOptions) ([]dockertypes.ImageDelete, error) | ||
Logs(string, dockertypes.ContainerLogsOptions, StreamOptions) error | ||
Version() (*dockertypes.Version, error) | ||
Info() (*dockertypes.Info, error) | ||
|
@@ -146,23 +145,22 @@ func filterHTTPError(err error, image string) error { | |
|
||
func (p dockerPuller) Pull(image string, secrets []api.Secret) error { | ||
// If no tag was specified, use the default "latest". | ||
repoToPull, tag := parsers.ParseImageName(image) | ||
|
||
opts := docker.PullImageOptions{ | ||
Repository: repoToPull, | ||
Tag: tag, | ||
} | ||
imageID, tag := parsers.ParseImageName(image) | ||
|
||
keyring, err := credentialprovider.MakeDockerKeyring(secrets, p.keyring) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
creds, haveCredentials := keyring.Lookup(repoToPull) | ||
opts := dockertypes.ImagePullOptions{ | ||
Tag: tag, | ||
} | ||
|
||
creds, haveCredentials := keyring.Lookup(imageID) | ||
if !haveCredentials { | ||
glog.V(1).Infof("Pulling image %s without credentials", image) | ||
|
||
err := p.client.PullImage(opts, docker.AuthConfiguration{}) | ||
err := p.client.PullImage(imageID, dockertypes.AuthConfig{}, opts) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have to pass imageID both as an argument and as a filed in the options? The client should be able to write the imageID to the options. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So do we keep imageID here? Seems two opinions? |
||
if err == nil { | ||
// Sometimes PullImage failed with no error returned. | ||
exist, ierr := p.IsImagePresent(image) | ||
|
@@ -189,7 +187,7 @@ func (p dockerPuller) Pull(image string, secrets []api.Secret) error { | |
|
||
var pullErrs []error | ||
for _, currentCreds := range creds { | ||
err := p.client.PullImage(opts, credentialprovider.LazyProvide(currentCreds)) | ||
err = p.client.PullImage(imageID, credentialprovider.LazyProvide(currentCreds), opts) | ||
// If there was no error, return success | ||
if err == nil { | ||
return nil | ||
|
@@ -213,7 +211,7 @@ func (p dockerPuller) IsImagePresent(image string) (bool, error) { | |
if err == nil { | ||
return true, nil | ||
} | ||
if err == docker.ErrNoSuchImage { | ||
if _, ok := err.(imageNotFoundError); ok { | ||
return false, nil | ||
} | ||
return false, err | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,6 @@ import ( | |
|
||
dockertypes "github.com/docker/engine-api/types" | ||
dockercontainer "github.com/docker/engine-api/types/container" | ||
docker "github.com/fsouza/go-dockerclient" | ||
|
||
"k8s.io/kubernetes/pkg/api" | ||
"k8s.io/kubernetes/pkg/util/sets" | ||
|
@@ -40,11 +39,12 @@ type FakeDockerClient struct { | |
RunningContainerList []dockertypes.Container | ||
ExitedContainerList []dockertypes.Container | ||
ContainerMap map[string]*dockertypes.ContainerJSON | ||
Image *docker.Image | ||
Images []docker.APIImages | ||
Image *dockertypes.ImageInspect | ||
Images []dockertypes.Image | ||
Errors map[string]error | ||
called []string | ||
pulled []string | ||
|
||
// Created, Stopped and Removed all container docker ID | ||
Created []string | ||
Stopped []string | ||
|
@@ -281,7 +281,7 @@ func (f *FakeDockerClient) InspectContainer(id string) (*dockertypes.ContainerJS | |
|
||
// InspectImage is a test-spy implementation of DockerInterface.InspectImage. | ||
// It adds an entry "inspect" to the internal method call record. | ||
func (f *FakeDockerClient) InspectImage(name string) (*docker.Image, error) { | ||
func (f *FakeDockerClient) InspectImage(name string) (*dockertypes.ImageInspect, error) { | ||
f.Lock() | ||
defer f.Unlock() | ||
f.called = append(f.called, "inspect_image") | ||
|
@@ -421,18 +421,14 @@ func (f *FakeDockerClient) Logs(id string, opts dockertypes.ContainerLogsOptions | |
|
||
// PullImage is a test-spy implementation of DockerInterface.PullImage. | ||
// It adds an entry "pull" to the internal method call record. | ||
func (f *FakeDockerClient) PullImage(opts docker.PullImageOptions, auth docker.AuthConfiguration) error { | ||
func (f *FakeDockerClient) PullImage(imageID string, auth dockertypes.AuthConfig, opts dockertypes.ImagePullOptions) error { | ||
f.Lock() | ||
defer f.Unlock() | ||
f.called = append(f.called, "pull") | ||
err := f.popError("pull") | ||
if err == nil { | ||
registry := opts.Registry | ||
if len(registry) != 0 { | ||
registry = registry + "/" | ||
} | ||
authJson, _ := json.Marshal(auth) | ||
f.pulled = append(f.pulled, fmt.Sprintf("%s%s:%s using %s", registry, opts.Repository, opts.Tag, string(authJson))) | ||
f.pulled = append(f.pulled, fmt.Sprintf("%s:%s using %s", imageID, opts.Tag, string(authJson))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Get rid of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be better to just use the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes. Sorry. I had not read your explanation in the other comment yet. |
||
} | ||
return err | ||
} | ||
|
@@ -473,17 +469,17 @@ func (f *FakeDockerClient) InspectExec(id string) (*dockertypes.ContainerExecIns | |
return f.ExecInspect, f.popError("inspect_exec") | ||
} | ||
|
||
func (f *FakeDockerClient) ListImages(opts docker.ListImagesOptions) ([]docker.APIImages, error) { | ||
func (f *FakeDockerClient) ListImages(opts dockertypes.ImageListOptions) ([]dockertypes.Image, error) { | ||
err := f.popError("list_images") | ||
return f.Images, err | ||
} | ||
|
||
func (f *FakeDockerClient) RemoveImage(image string) error { | ||
func (f *FakeDockerClient) RemoveImage(image string, opts dockertypes.ImageRemoveOptions) ([]dockertypes.ImageDelete, error) { | ||
err := f.popError("remove_image") | ||
if err == nil { | ||
f.RemovedImages.Insert(image) | ||
} | ||
return err | ||
return []dockertypes.ImageDelete{{Deleted: image}}, err | ||
} | ||
|
||
func (f *FakeDockerClient) updateContainerStatus(id, status string) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same question as by others below.
Why are we adding an
image
argument when theopts
contain the image information.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MHBauer We do this, because:
ImagePullOptions
Make required arguments required. docker/engine-api#162, it will be easier to bump up the engine-api version later.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay.