mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 22:17:14 +00:00
Merge pull request #23800 from resouer/image-refactor
Automatic merge from submit-queue Refactor image related functions to use docker engine-api ref #23563 Hopes can do some help, cc @Random-Liu If it's ok, will add more work here.
This commit is contained in:
commit
4f9e8729bf
@ -24,9 +24,9 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
docker "github.com/fsouza/go-dockerclient"
|
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
|
|
||||||
|
dockertypes "github.com/docker/engine-api/types"
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
"k8s.io/kubernetes/pkg/util/sets"
|
"k8s.io/kubernetes/pkg/util/sets"
|
||||||
)
|
)
|
||||||
@ -54,17 +54,17 @@ type lazyDockerKeyring struct {
|
|||||||
Providers []DockerConfigProvider
|
Providers []DockerConfigProvider
|
||||||
}
|
}
|
||||||
|
|
||||||
// LazyAuthConfiguration wraps AuthConfiguration, potentially deferring its
|
// LazyAuthConfiguration wraps dockertypes.AuthConfig, potentially deferring its
|
||||||
// binding. If Provider is non-nil, it will be used to obtain new credentials
|
// binding. If Provider is non-nil, it will be used to obtain new credentials
|
||||||
// by calling LazyProvide() on it.
|
// by calling LazyProvide() on it.
|
||||||
type LazyAuthConfiguration struct {
|
type LazyAuthConfiguration struct {
|
||||||
docker.AuthConfiguration
|
dockertypes.AuthConfig
|
||||||
Provider DockerConfigProvider
|
Provider DockerConfigProvider
|
||||||
}
|
}
|
||||||
|
|
||||||
func DockerConfigEntryToLazyAuthConfiguration(ident DockerConfigEntry) LazyAuthConfiguration {
|
func DockerConfigEntryToLazyAuthConfiguration(ident DockerConfigEntry) LazyAuthConfiguration {
|
||||||
return LazyAuthConfiguration{
|
return LazyAuthConfiguration{
|
||||||
AuthConfiguration: docker.AuthConfiguration{
|
AuthConfig: dockertypes.AuthConfig{
|
||||||
Username: ident.Username,
|
Username: ident.Username,
|
||||||
Password: ident.Password,
|
Password: ident.Password,
|
||||||
Email: ident.Email,
|
Email: ident.Email,
|
||||||
@ -291,7 +291,6 @@ type unionDockerKeyring struct {
|
|||||||
|
|
||||||
func (k *unionDockerKeyring) Lookup(image string) ([]LazyAuthConfiguration, bool) {
|
func (k *unionDockerKeyring) Lookup(image string) ([]LazyAuthConfiguration, bool) {
|
||||||
authConfigs := []LazyAuthConfiguration{}
|
authConfigs := []LazyAuthConfiguration{}
|
||||||
|
|
||||||
for _, subKeyring := range k.keyrings {
|
for _, subKeyring := range k.keyrings {
|
||||||
if subKeyring == nil {
|
if subKeyring == nil {
|
||||||
continue
|
continue
|
||||||
|
@ -22,7 +22,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
docker "github.com/fsouza/go-dockerclient"
|
dockertypes "github.com/docker/engine-api/types"
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -36,12 +36,12 @@ type DockerConfigProvider interface {
|
|||||||
LazyProvide() *DockerConfigEntry
|
LazyProvide() *DockerConfigEntry
|
||||||
}
|
}
|
||||||
|
|
||||||
func LazyProvide(creds LazyAuthConfiguration) docker.AuthConfiguration {
|
func LazyProvide(creds LazyAuthConfiguration) dockertypes.AuthConfig {
|
||||||
if creds.Provider != nil {
|
if creds.Provider != nil {
|
||||||
entry := *creds.Provider.LazyProvide()
|
entry := *creds.Provider.LazyProvide()
|
||||||
return DockerConfigEntryToLazyAuthConfiguration(entry).AuthConfiguration
|
return DockerConfigEntryToLazyAuthConfiguration(entry).AuthConfig
|
||||||
} else {
|
} else {
|
||||||
return creds.AuthConfiguration
|
return creds.AuthConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
dockertypes "github.com/docker/engine-api/types"
|
dockertypes "github.com/docker/engine-api/types"
|
||||||
docker "github.com/fsouza/go-dockerclient"
|
|
||||||
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -70,8 +69,8 @@ func toRuntimeContainer(c *dockertypes.Container) (*kubecontainer.Container, err
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Converts docker.APIImages to kubecontainer.Image.
|
// Converts dockertypes.Image to kubecontainer.Image.
|
||||||
func toRuntimeImage(image *docker.APIImages) (*kubecontainer.Image, error) {
|
func toRuntimeImage(image *dockertypes.Image) (*kubecontainer.Image, error) {
|
||||||
if image == nil {
|
if image == nil {
|
||||||
return nil, fmt.Errorf("unable to convert a nil pointer to a runtime image")
|
return nil, fmt.Errorf("unable to convert a nil pointer to a runtime image")
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
dockertypes "github.com/docker/engine-api/types"
|
dockertypes "github.com/docker/engine-api/types"
|
||||||
docker "github.com/fsouza/go-dockerclient"
|
|
||||||
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -70,7 +69,7 @@ func TestToRuntimeContainer(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestToRuntimeImage(t *testing.T) {
|
func TestToRuntimeImage(t *testing.T) {
|
||||||
original := &docker.APIImages{
|
original := &dockertypes.Image{
|
||||||
ID: "aeeea",
|
ID: "aeeea",
|
||||||
RepoTags: []string{"abc", "def"},
|
RepoTags: []string{"abc", "def"},
|
||||||
VirtualSize: 1234,
|
VirtualSize: 1234,
|
||||||
|
@ -27,7 +27,6 @@ import (
|
|||||||
"github.com/docker/docker/pkg/jsonmessage"
|
"github.com/docker/docker/pkg/jsonmessage"
|
||||||
dockerapi "github.com/docker/engine-api/client"
|
dockerapi "github.com/docker/engine-api/client"
|
||||||
dockertypes "github.com/docker/engine-api/types"
|
dockertypes "github.com/docker/engine-api/types"
|
||||||
docker "github.com/fsouza/go-dockerclient"
|
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
"k8s.io/kubernetes/pkg/credentialprovider"
|
"k8s.io/kubernetes/pkg/credentialprovider"
|
||||||
@ -64,10 +63,10 @@ type DockerInterface interface {
|
|||||||
StartContainer(id string) error
|
StartContainer(id string) error
|
||||||
StopContainer(id string, timeout int) error
|
StopContainer(id string, timeout int) error
|
||||||
RemoveContainer(id string, opts dockertypes.ContainerRemoveOptions) error
|
RemoveContainer(id string, opts dockertypes.ContainerRemoveOptions) error
|
||||||
InspectImage(image string) (*docker.Image, error)
|
InspectImage(image string) (*dockertypes.ImageInspect, error)
|
||||||
ListImages(opts docker.ListImagesOptions) ([]docker.APIImages, error)
|
ListImages(opts dockertypes.ImageListOptions) ([]dockertypes.Image, error)
|
||||||
PullImage(opts docker.PullImageOptions, auth docker.AuthConfiguration) error
|
PullImage(image string, auth dockertypes.AuthConfig, opts dockertypes.ImagePullOptions) error
|
||||||
RemoveImage(image string) error
|
RemoveImage(image string, opts dockertypes.ImageRemoveOptions) ([]dockertypes.ImageDelete, error)
|
||||||
Logs(string, dockertypes.ContainerLogsOptions, StreamOptions) error
|
Logs(string, dockertypes.ContainerLogsOptions, StreamOptions) error
|
||||||
Version() (*dockertypes.Version, error)
|
Version() (*dockertypes.Version, error)
|
||||||
Info() (*dockertypes.Info, 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 {
|
func (p dockerPuller) Pull(image string, secrets []api.Secret) error {
|
||||||
// If no tag was specified, use the default "latest".
|
// If no tag was specified, use the default "latest".
|
||||||
repoToPull, tag := parsers.ParseImageName(image)
|
imageID, tag := parsers.ParseImageName(image)
|
||||||
|
|
||||||
opts := docker.PullImageOptions{
|
|
||||||
Repository: repoToPull,
|
|
||||||
Tag: tag,
|
|
||||||
}
|
|
||||||
|
|
||||||
keyring, err := credentialprovider.MakeDockerKeyring(secrets, p.keyring)
|
keyring, err := credentialprovider.MakeDockerKeyring(secrets, p.keyring)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
creds, haveCredentials := keyring.Lookup(repoToPull)
|
opts := dockertypes.ImagePullOptions{
|
||||||
|
Tag: tag,
|
||||||
|
}
|
||||||
|
|
||||||
|
creds, haveCredentials := keyring.Lookup(imageID)
|
||||||
if !haveCredentials {
|
if !haveCredentials {
|
||||||
glog.V(1).Infof("Pulling image %s without credentials", image)
|
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)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
// Sometimes PullImage failed with no error returned.
|
// Sometimes PullImage failed with no error returned.
|
||||||
exist, ierr := p.IsImagePresent(image)
|
exist, ierr := p.IsImagePresent(image)
|
||||||
@ -189,7 +187,7 @@ func (p dockerPuller) Pull(image string, secrets []api.Secret) error {
|
|||||||
|
|
||||||
var pullErrs []error
|
var pullErrs []error
|
||||||
for _, currentCreds := range creds {
|
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 there was no error, return success
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return nil
|
return nil
|
||||||
@ -213,7 +211,7 @@ func (p dockerPuller) IsImagePresent(image string) (bool, error) {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
if err == docker.ErrNoSuchImage {
|
if _, ok := err.(imageNotFoundError); ok {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
return false, err
|
return false, err
|
||||||
|
@ -29,7 +29,6 @@ import (
|
|||||||
"github.com/docker/docker/pkg/jsonmessage"
|
"github.com/docker/docker/pkg/jsonmessage"
|
||||||
dockertypes "github.com/docker/engine-api/types"
|
dockertypes "github.com/docker/engine-api/types"
|
||||||
dockernat "github.com/docker/go-connections/nat"
|
dockernat "github.com/docker/go-connections/nat"
|
||||||
docker "github.com/fsouza/go-dockerclient"
|
|
||||||
cadvisorapi "github.com/google/cadvisor/info/v1"
|
cadvisorapi "github.com/google/cadvisor/info/v1"
|
||||||
"k8s.io/kubernetes/cmd/kubelet/app/options"
|
"k8s.io/kubernetes/cmd/kubelet/app/options"
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
@ -352,9 +351,8 @@ func TestDockerKeyringLookupFails(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDockerKeyringLookup(t *testing.T) {
|
func TestDockerKeyringLookup(t *testing.T) {
|
||||||
|
|
||||||
ada := credentialprovider.LazyAuthConfiguration{
|
ada := credentialprovider.LazyAuthConfiguration{
|
||||||
AuthConfiguration: docker.AuthConfiguration{
|
AuthConfig: dockertypes.AuthConfig{
|
||||||
Username: "ada",
|
Username: "ada",
|
||||||
Password: "smash",
|
Password: "smash",
|
||||||
Email: "ada@example.com",
|
Email: "ada@example.com",
|
||||||
@ -362,7 +360,7 @@ func TestDockerKeyringLookup(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
grace := credentialprovider.LazyAuthConfiguration{
|
grace := credentialprovider.LazyAuthConfiguration{
|
||||||
AuthConfiguration: docker.AuthConfiguration{
|
AuthConfig: dockertypes.AuthConfig{
|
||||||
Username: "grace",
|
Username: "grace",
|
||||||
Password: "squash",
|
Password: "squash",
|
||||||
Email: "grace@example.com",
|
Email: "grace@example.com",
|
||||||
@ -425,7 +423,7 @@ func TestDockerKeyringLookup(t *testing.T) {
|
|||||||
// NOTE: the above covers the case of a more specific match trumping just hostname.
|
// NOTE: the above covers the case of a more specific match trumping just hostname.
|
||||||
func TestIssue3797(t *testing.T) {
|
func TestIssue3797(t *testing.T) {
|
||||||
rex := credentialprovider.LazyAuthConfiguration{
|
rex := credentialprovider.LazyAuthConfiguration{
|
||||||
AuthConfiguration: docker.AuthConfiguration{
|
AuthConfig: dockertypes.AuthConfig{
|
||||||
Username: "rex",
|
Username: "rex",
|
||||||
Password: "tiny arms",
|
Password: "tiny arms",
|
||||||
Email: "rex@example.com",
|
Email: "rex@example.com",
|
||||||
@ -471,7 +469,7 @@ type imageTrackingDockerClient struct {
|
|||||||
imageName string
|
imageName string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *imageTrackingDockerClient) InspectImage(name string) (image *docker.Image, err error) {
|
func (f *imageTrackingDockerClient) InspectImage(name string) (image *dockertypes.ImageInspect, err error) {
|
||||||
image, err = f.FakeDockerClient.InspectImage(name)
|
image, err = f.FakeDockerClient.InspectImage(name)
|
||||||
f.imageName = name
|
f.imageName = name
|
||||||
return
|
return
|
||||||
|
@ -28,7 +28,6 @@ import (
|
|||||||
|
|
||||||
dockertypes "github.com/docker/engine-api/types"
|
dockertypes "github.com/docker/engine-api/types"
|
||||||
dockercontainer "github.com/docker/engine-api/types/container"
|
dockercontainer "github.com/docker/engine-api/types/container"
|
||||||
docker "github.com/fsouza/go-dockerclient"
|
|
||||||
|
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
"k8s.io/kubernetes/pkg/util/sets"
|
"k8s.io/kubernetes/pkg/util/sets"
|
||||||
@ -40,11 +39,12 @@ type FakeDockerClient struct {
|
|||||||
RunningContainerList []dockertypes.Container
|
RunningContainerList []dockertypes.Container
|
||||||
ExitedContainerList []dockertypes.Container
|
ExitedContainerList []dockertypes.Container
|
||||||
ContainerMap map[string]*dockertypes.ContainerJSON
|
ContainerMap map[string]*dockertypes.ContainerJSON
|
||||||
Image *docker.Image
|
Image *dockertypes.ImageInspect
|
||||||
Images []docker.APIImages
|
Images []dockertypes.Image
|
||||||
Errors map[string]error
|
Errors map[string]error
|
||||||
called []string
|
called []string
|
||||||
pulled []string
|
pulled []string
|
||||||
|
|
||||||
// Created, Stopped and Removed all container docker ID
|
// Created, Stopped and Removed all container docker ID
|
||||||
Created []string
|
Created []string
|
||||||
Stopped []string
|
Stopped []string
|
||||||
@ -281,7 +281,7 @@ func (f *FakeDockerClient) InspectContainer(id string) (*dockertypes.ContainerJS
|
|||||||
|
|
||||||
// InspectImage is a test-spy implementation of DockerInterface.InspectImage.
|
// InspectImage is a test-spy implementation of DockerInterface.InspectImage.
|
||||||
// It adds an entry "inspect" to the internal method call record.
|
// 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()
|
f.Lock()
|
||||||
defer f.Unlock()
|
defer f.Unlock()
|
||||||
f.called = append(f.called, "inspect_image")
|
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.
|
// PullImage is a test-spy implementation of DockerInterface.PullImage.
|
||||||
// It adds an entry "pull" to the internal method call record.
|
// 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()
|
f.Lock()
|
||||||
defer f.Unlock()
|
defer f.Unlock()
|
||||||
f.called = append(f.called, "pull")
|
f.called = append(f.called, "pull")
|
||||||
err := f.popError("pull")
|
err := f.popError("pull")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
registry := opts.Registry
|
|
||||||
if len(registry) != 0 {
|
|
||||||
registry = registry + "/"
|
|
||||||
}
|
|
||||||
authJson, _ := json.Marshal(auth)
|
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)))
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -473,17 +469,17 @@ func (f *FakeDockerClient) InspectExec(id string) (*dockertypes.ContainerExecIns
|
|||||||
return f.ExecInspect, f.popError("inspect_exec")
|
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")
|
err := f.popError("list_images")
|
||||||
return f.Images, err
|
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")
|
err := f.popError("remove_image")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
f.RemovedImages.Insert(image)
|
f.RemovedImages.Insert(image)
|
||||||
}
|
}
|
||||||
return err
|
return []dockertypes.ImageDelete{{Deleted: image}}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FakeDockerClient) updateContainerStatus(id, status string) {
|
func (f *FakeDockerClient) updateContainerStatus(id, status string) {
|
||||||
|
@ -20,7 +20,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
dockertypes "github.com/docker/engine-api/types"
|
dockertypes "github.com/docker/engine-api/types"
|
||||||
docker "github.com/fsouza/go-dockerclient"
|
|
||||||
"k8s.io/kubernetes/pkg/kubelet/metrics"
|
"k8s.io/kubernetes/pkg/kubelet/metrics"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -103,7 +102,7 @@ func (in instrumentedDockerInterface) RemoveContainer(id string, opts dockertype
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (in instrumentedDockerInterface) InspectImage(image string) (*docker.Image, error) {
|
func (in instrumentedDockerInterface) InspectImage(image string) (*dockertypes.ImageInspect, error) {
|
||||||
const operation = "inspect_image"
|
const operation = "inspect_image"
|
||||||
defer recordOperation(operation, time.Now())
|
defer recordOperation(operation, time.Now())
|
||||||
|
|
||||||
@ -112,7 +111,7 @@ func (in instrumentedDockerInterface) InspectImage(image string) (*docker.Image,
|
|||||||
return out, err
|
return out, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (in instrumentedDockerInterface) ListImages(opts docker.ListImagesOptions) ([]docker.APIImages, error) {
|
func (in instrumentedDockerInterface) ListImages(opts dockertypes.ImageListOptions) ([]dockertypes.Image, error) {
|
||||||
const operation = "list_images"
|
const operation = "list_images"
|
||||||
defer recordOperation(operation, time.Now())
|
defer recordOperation(operation, time.Now())
|
||||||
|
|
||||||
@ -121,22 +120,21 @@ func (in instrumentedDockerInterface) ListImages(opts docker.ListImagesOptions)
|
|||||||
return out, err
|
return out, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (in instrumentedDockerInterface) PullImage(opts docker.PullImageOptions, auth docker.AuthConfiguration) error {
|
func (in instrumentedDockerInterface) PullImage(imageID string, auth dockertypes.AuthConfig, opts dockertypes.ImagePullOptions) error {
|
||||||
const operation = "pull_image"
|
const operation = "pull_image"
|
||||||
defer recordOperation(operation, time.Now())
|
defer recordOperation(operation, time.Now())
|
||||||
|
err := in.client.PullImage(imageID, auth, opts)
|
||||||
err := in.client.PullImage(opts, auth)
|
|
||||||
recordError(operation, err)
|
recordError(operation, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (in instrumentedDockerInterface) RemoveImage(image string) error {
|
func (in instrumentedDockerInterface) RemoveImage(image string, opts dockertypes.ImageRemoveOptions) ([]dockertypes.ImageDelete, error) {
|
||||||
const operation = "remove_image"
|
const operation = "remove_image"
|
||||||
defer recordOperation(operation, time.Now())
|
defer recordOperation(operation, time.Now())
|
||||||
|
|
||||||
err := in.client.RemoveImage(image)
|
imageDelete, err := in.client.RemoveImage(image, opts)
|
||||||
recordError(operation, err)
|
recordError(operation, err)
|
||||||
return err
|
return imageDelete, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (in instrumentedDockerInterface) Logs(id string, opts dockertypes.ContainerLogsOptions, sopts StreamOptions) error {
|
func (in instrumentedDockerInterface) Logs(id string, opts dockertypes.ContainerLogsOptions, sopts StreamOptions) error {
|
||||||
|
@ -30,7 +30,6 @@ import (
|
|||||||
dockerapi "github.com/docker/engine-api/client"
|
dockerapi "github.com/docker/engine-api/client"
|
||||||
dockertypes "github.com/docker/engine-api/types"
|
dockertypes "github.com/docker/engine-api/types"
|
||||||
dockerfilters "github.com/docker/engine-api/types/filters"
|
dockerfilters "github.com/docker/engine-api/types/filters"
|
||||||
docker "github.com/fsouza/go-dockerclient"
|
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -141,39 +140,26 @@ func (d *kubeDockerClient) RemoveContainer(id string, opts dockertypes.Container
|
|||||||
return d.client.ContainerRemove(getDefaultContext(), opts)
|
return d.client.ContainerRemove(getDefaultContext(), opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *kubeDockerClient) InspectImage(image string) (*docker.Image, error) {
|
func (d *kubeDockerClient) InspectImage(image string) (*dockertypes.ImageInspect, error) {
|
||||||
resp, _, err := d.client.ImageInspectWithRaw(getDefaultContext(), image, true)
|
resp, _, err := d.client.ImageInspectWithRaw(getDefaultContext(), image, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// TODO(random-liu): Use IsErrImageNotFound instead of ErrNoSuchImage
|
|
||||||
if dockerapi.IsErrImageNotFound(err) {
|
if dockerapi.IsErrImageNotFound(err) {
|
||||||
err = docker.ErrNoSuchImage
|
err = imageNotFoundError{ID: image}
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
imageInfo := &docker.Image{}
|
return &resp, nil
|
||||||
if err := convertType(&resp, imageInfo); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return imageInfo, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *kubeDockerClient) ListImages(opts docker.ListImagesOptions) ([]docker.APIImages, error) {
|
func (d *kubeDockerClient) ListImages(opts dockertypes.ImageListOptions) ([]dockertypes.Image, error) {
|
||||||
resp, err := d.client.ImageList(getDefaultContext(), dockertypes.ImageListOptions{
|
images, err := d.client.ImageList(getDefaultContext(), opts)
|
||||||
MatchName: opts.Filter,
|
|
||||||
All: opts.All,
|
|
||||||
Filters: convertFilters(opts.Filters),
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
images := []docker.APIImages{}
|
|
||||||
if err = convertType(&resp, &images); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return images, nil
|
return images, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func base64EncodeAuth(auth docker.AuthConfiguration) (string, error) {
|
func base64EncodeAuth(auth dockertypes.AuthConfig) (string, error) {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
if err := json.NewEncoder(&buf).Encode(auth); err != nil {
|
if err := json.NewEncoder(&buf).Encode(auth); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@ -181,16 +167,15 @@ func base64EncodeAuth(auth docker.AuthConfiguration) (string, error) {
|
|||||||
return base64.URLEncoding.EncodeToString(buf.Bytes()), nil
|
return base64.URLEncoding.EncodeToString(buf.Bytes()), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *kubeDockerClient) PullImage(opts docker.PullImageOptions, auth docker.AuthConfiguration) error {
|
func (d *kubeDockerClient) PullImage(image string, auth dockertypes.AuthConfig, opts dockertypes.ImagePullOptions) error {
|
||||||
|
// RegistryAuth is the base64 encoded credentials for the registry
|
||||||
base64Auth, err := base64EncodeAuth(auth)
|
base64Auth, err := base64EncodeAuth(auth)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
resp, err := d.client.ImagePull(getDefaultContext(), dockertypes.ImagePullOptions{
|
opts.ImageID = image
|
||||||
ImageID: opts.Repository,
|
opts.RegistryAuth = base64Auth
|
||||||
Tag: opts.Tag,
|
resp, err := d.client.ImagePull(getDefaultContext(), opts, nil)
|
||||||
RegistryAuth: base64Auth,
|
|
||||||
}, nil)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -213,9 +198,8 @@ func (d *kubeDockerClient) PullImage(opts docker.PullImageOptions, auth docker.A
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *kubeDockerClient) RemoveImage(image string) error {
|
func (d *kubeDockerClient) RemoveImage(image string, opts dockertypes.ImageRemoveOptions) ([]dockertypes.ImageDelete, error) {
|
||||||
_, err := d.client.ImageRemove(getDefaultContext(), dockertypes.ImageRemoveOptions{ImageID: image})
|
return d.client.ImageRemove(getDefaultContext(), dockertypes.ImageRemoveOptions{ImageID: image})
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *kubeDockerClient) Logs(id string, opts dockertypes.ContainerLogsOptions, sopts StreamOptions) error {
|
func (d *kubeDockerClient) Logs(id string, opts dockertypes.ContainerLogsOptions, sopts StreamOptions) error {
|
||||||
@ -359,3 +343,12 @@ type containerNotFoundError struct {
|
|||||||
func (e containerNotFoundError) Error() string {
|
func (e containerNotFoundError) Error() string {
|
||||||
return fmt.Sprintf("Error: No such container: %s", e.ID)
|
return fmt.Sprintf("Error: No such container: %s", e.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// imageNotFoundError is the error returned by InspectImage when image not found.
|
||||||
|
type imageNotFoundError struct {
|
||||||
|
ID string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e imageNotFoundError) Error() string {
|
||||||
|
return fmt.Sprintf("Error: No such image: %s", e.ID)
|
||||||
|
}
|
||||||
|
@ -34,7 +34,6 @@ import (
|
|||||||
dockercontainer "github.com/docker/engine-api/types/container"
|
dockercontainer "github.com/docker/engine-api/types/container"
|
||||||
dockerstrslice "github.com/docker/engine-api/types/strslice"
|
dockerstrslice "github.com/docker/engine-api/types/strslice"
|
||||||
dockernat "github.com/docker/go-connections/nat"
|
dockernat "github.com/docker/go-connections/nat"
|
||||||
docker "github.com/fsouza/go-dockerclient"
|
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
cadvisorapi "github.com/google/cadvisor/info/v1"
|
cadvisorapi "github.com/google/cadvisor/info/v1"
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
@ -793,7 +792,7 @@ func (dm *DockerManager) GetPods(all bool) ([]*kubecontainer.Pod, error) {
|
|||||||
func (dm *DockerManager) ListImages() ([]kubecontainer.Image, error) {
|
func (dm *DockerManager) ListImages() ([]kubecontainer.Image, error) {
|
||||||
var images []kubecontainer.Image
|
var images []kubecontainer.Image
|
||||||
|
|
||||||
dockerImages, err := dm.client.ListImages(docker.ListImagesOptions{})
|
dockerImages, err := dm.client.ListImages(dockertypes.ImageListOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return images, err
|
return images, err
|
||||||
}
|
}
|
||||||
@ -821,7 +820,9 @@ func (dm *DockerManager) IsImagePresent(image kubecontainer.ImageSpec) (bool, er
|
|||||||
|
|
||||||
// Removes the specified image.
|
// Removes the specified image.
|
||||||
func (dm *DockerManager) RemoveImage(image kubecontainer.ImageSpec) error {
|
func (dm *DockerManager) RemoveImage(image kubecontainer.ImageSpec) error {
|
||||||
return dm.client.RemoveImage(image.Image)
|
// TODO(harryz) currently Runtime interface does not provide other remove options.
|
||||||
|
_, err := dm.client.RemoveImage(image.Image, dockertypes.ImageRemoveOptions{})
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// podInfraContainerChanged returns true if the pod infra container has changed.
|
// podInfraContainerChanged returns true if the pod infra container has changed.
|
||||||
|
@ -32,7 +32,6 @@ import (
|
|||||||
dockertypes "github.com/docker/engine-api/types"
|
dockertypes "github.com/docker/engine-api/types"
|
||||||
dockercontainer "github.com/docker/engine-api/types/container"
|
dockercontainer "github.com/docker/engine-api/types/container"
|
||||||
dockerstrslice "github.com/docker/engine-api/types/strslice"
|
dockerstrslice "github.com/docker/engine-api/types/strslice"
|
||||||
docker "github.com/fsouza/go-dockerclient"
|
|
||||||
cadvisorapi "github.com/google/cadvisor/info/v1"
|
cadvisorapi "github.com/google/cadvisor/info/v1"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"k8s.io/kubernetes/cmd/kubelet/app/options"
|
"k8s.io/kubernetes/cmd/kubelet/app/options"
|
||||||
@ -363,7 +362,7 @@ func TestGetPods(t *testing.T) {
|
|||||||
|
|
||||||
func TestListImages(t *testing.T) {
|
func TestListImages(t *testing.T) {
|
||||||
manager, fakeDocker := newTestDockerManager()
|
manager, fakeDocker := newTestDockerManager()
|
||||||
dockerImages := []docker.APIImages{{ID: "1111"}, {ID: "2222"}, {ID: "3333"}}
|
dockerImages := []dockertypes.Image{{ID: "1111"}, {ID: "2222"}, {ID: "3333"}}
|
||||||
expected := sets.NewString([]string{"1111", "2222", "3333"}...)
|
expected := sets.NewString([]string{"1111", "2222", "3333"}...)
|
||||||
|
|
||||||
fakeDocker.Images = dockerImages
|
fakeDocker.Images = dockerImages
|
||||||
@ -1419,7 +1418,7 @@ func TestVerifyNonRoot(t *testing.T) {
|
|||||||
|
|
||||||
tests := map[string]struct {
|
tests := map[string]struct {
|
||||||
container *api.Container
|
container *api.Container
|
||||||
inspectImage *docker.Image
|
inspectImage *dockertypes.ImageInspect
|
||||||
expectedError string
|
expectedError string
|
||||||
}{
|
}{
|
||||||
// success cases
|
// success cases
|
||||||
@ -1432,16 +1431,16 @@ func TestVerifyNonRoot(t *testing.T) {
|
|||||||
},
|
},
|
||||||
"numeric non-root image user": {
|
"numeric non-root image user": {
|
||||||
container: &api.Container{},
|
container: &api.Container{},
|
||||||
inspectImage: &docker.Image{
|
inspectImage: &dockertypes.ImageInspect{
|
||||||
Config: &docker.Config{
|
Config: &dockercontainer.Config{
|
||||||
User: "1",
|
User: "1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"numeric non-root image user with gid": {
|
"numeric non-root image user with gid": {
|
||||||
container: &api.Container{},
|
container: &api.Container{},
|
||||||
inspectImage: &docker.Image{
|
inspectImage: &dockertypes.ImageInspect{
|
||||||
Config: &docker.Config{
|
Config: &dockercontainer.Config{
|
||||||
User: "1:2",
|
User: "1:2",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -1458,8 +1457,8 @@ func TestVerifyNonRoot(t *testing.T) {
|
|||||||
},
|
},
|
||||||
"non-numeric image user": {
|
"non-numeric image user": {
|
||||||
container: &api.Container{},
|
container: &api.Container{},
|
||||||
inspectImage: &docker.Image{
|
inspectImage: &dockertypes.ImageInspect{
|
||||||
Config: &docker.Config{
|
Config: &dockercontainer.Config{
|
||||||
User: "foo",
|
User: "foo",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -1467,8 +1466,8 @@ func TestVerifyNonRoot(t *testing.T) {
|
|||||||
},
|
},
|
||||||
"numeric root image user": {
|
"numeric root image user": {
|
||||||
container: &api.Container{},
|
container: &api.Container{},
|
||||||
inspectImage: &docker.Image{
|
inspectImage: &dockertypes.ImageInspect{
|
||||||
Config: &docker.Config{
|
Config: &dockercontainer.Config{
|
||||||
User: "0",
|
User: "0",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -1476,8 +1475,8 @@ func TestVerifyNonRoot(t *testing.T) {
|
|||||||
},
|
},
|
||||||
"numeric root image user with gid": {
|
"numeric root image user with gid": {
|
||||||
container: &api.Container{},
|
container: &api.Container{},
|
||||||
inspectImage: &docker.Image{
|
inspectImage: &dockertypes.ImageInspect{
|
||||||
Config: &docker.Config{
|
Config: &dockercontainer.Config{
|
||||||
User: "0:1",
|
User: "0:1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -1489,7 +1488,7 @@ func TestVerifyNonRoot(t *testing.T) {
|
|||||||
},
|
},
|
||||||
"nil config in image inspect": {
|
"nil config in image inspect": {
|
||||||
container: &api.Container{},
|
container: &api.Container{},
|
||||||
inspectImage: &docker.Image{},
|
inspectImage: &dockertypes.ImageInspect{},
|
||||||
expectedError: "unable to inspect image",
|
expectedError: "unable to inspect image",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ import (
|
|||||||
|
|
||||||
appcschema "github.com/appc/spec/schema"
|
appcschema "github.com/appc/spec/schema"
|
||||||
rktapi "github.com/coreos/rkt/api/v1alpha"
|
rktapi "github.com/coreos/rkt/api/v1alpha"
|
||||||
"github.com/fsouza/go-dockerclient"
|
dockertypes "github.com/docker/engine-api/types"
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
@ -183,7 +183,7 @@ func (r *Runtime) writeDockerAuthConfig(image string, credsSlice []credentialpro
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
creds := docker.AuthConfiguration{}
|
creds := dockertypes.AuthConfig{}
|
||||||
// TODO handle multiple creds
|
// TODO handle multiple creds
|
||||||
if len(credsSlice) >= 1 {
|
if len(credsSlice) >= 1 {
|
||||||
creds = credentialprovider.LazyProvide(credsSlice[0])
|
creds = credentialprovider.LazyProvide(credsSlice[0])
|
||||||
|
Loading…
Reference in New Issue
Block a user