Skip to content

Commit

Permalink
remove dependency on github.com/fsouza/go-dockerclient from imageapi
Browse files Browse the repository at this point in the history
  • Loading branch information
deads2k committed Sep 20, 2017
1 parent ea400d2 commit 9911834
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 74 deletions.
1 change: 0 additions & 1 deletion hack/import-restrictions.json
Expand Up @@ -130,7 +130,6 @@
"vendor/k8s.io/kubernetes/pkg/api",
"vendor/k8s.io/kubernetes/pkg/api/v1",
"vendor/github.com/golang/glog",
"vendor/github.com/fsouza/go-dockerclient",
"vendor/github.com/docker/distribution/digest",
"vendor/github.com/blang/semver",
"github.com/openshift/origin/pkg/image/reference"
Expand Down
55 changes: 0 additions & 55 deletions pkg/image/apis/image/conversion.go

This file was deleted.

6 changes: 2 additions & 4 deletions pkg/image/apis/image/dockerpre012/conversion.go
@@ -1,8 +1,6 @@
package dockerpre012

import (
"github.com/fsouza/go-dockerclient"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/conversion"
"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -11,7 +9,7 @@ import (
)

// Convert docker client object to internal object, but only when this package is included
func Convert_dockerpre012_ImagePre_012_to_api_DockerImage(in *docker.ImagePre012, out *newer.DockerImage, s conversion.Scope) error {
func Convert_dockerpre012_ImagePre_012_to_api_DockerImage(in *ImagePre012, out *newer.DockerImage, s conversion.Scope) error {
if err := s.Convert(in.Config, &out.Config, conversion.AllowDifferentFieldTypeNames); err != nil {
return err
}
Expand All @@ -29,7 +27,7 @@ func Convert_dockerpre012_ImagePre_012_to_api_DockerImage(in *docker.ImagePre012
out.Size = in.Size
return nil
}
func Convert_api_DockerImage_to_dockerpre012_ImagePre_012(in *newer.DockerImage, out *docker.ImagePre012, s conversion.Scope) error {
func Convert_api_DockerImage_to_dockerpre012_ImagePre_012(in *newer.DockerImage, out *ImagePre012, s conversion.Scope) error {
if err := s.Convert(&in.Config, &out.Config, conversion.AllowDifferentFieldTypeNames); err != nil {
return err
}
Expand Down
79 changes: 79 additions & 0 deletions pkg/image/apis/image/dockerpre012/dockertypes.go
@@ -1,6 +1,8 @@
package dockerpre012

import (
"time"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -53,3 +55,80 @@ type DockerConfig struct {
// This field is not supported in pre012 and will always be empty.
Labels map[string]string `json:"Labels,omitempty"`
}

// ImagePre012 serves the same purpose as the Image type except that it is for
// earlier versions of the Docker API (pre-012 to be specific)
// Exists only for legacy conversion, copy of type from fsouza/go-dockerclient
type ImagePre012 struct {
ID string `json:"id"`
Parent string `json:"parent,omitempty"`
Comment string `json:"comment,omitempty"`
Created time.Time `json:"created"`
Container string `json:"container,omitempty"`
ContainerConfig Config `json:"container_config,omitempty"`
DockerVersion string `json:"docker_version,omitempty"`
Author string `json:"author,omitempty"`
Config *Config `json:"config,omitempty"`
Architecture string `json:"architecture,omitempty"`
Size int64 `json:"size,omitempty"`
}

// Config is the list of configuration options used when creating a container.
// Config does not contain the options that are specific to starting a container on a
// given host. Those are contained in HostConfig
// Exists only for legacy conversion, copy of type from fsouza/go-dockerclient
type Config struct {
Hostname string `json:"Hostname,omitempty" yaml:"Hostname,omitempty"`
Domainname string `json:"Domainname,omitempty" yaml:"Domainname,omitempty"`
User string `json:"User,omitempty" yaml:"User,omitempty"`
Memory int64 `json:"Memory,omitempty" yaml:"Memory,omitempty"`
MemorySwap int64 `json:"MemorySwap,omitempty" yaml:"MemorySwap,omitempty"`
MemoryReservation int64 `json:"MemoryReservation,omitempty" yaml:"MemoryReservation,omitempty"`
KernelMemory int64 `json:"KernelMemory,omitempty" yaml:"KernelMemory,omitempty"`
PidsLimit int64 `json:"PidsLimit,omitempty" yaml:"PidsLimit,omitempty"`
CPUShares int64 `json:"CpuShares,omitempty" yaml:"CpuShares,omitempty"`
CPUSet string `json:"Cpuset,omitempty" yaml:"Cpuset,omitempty"`
AttachStdin bool `json:"AttachStdin,omitempty" yaml:"AttachStdin,omitempty"`
AttachStdout bool `json:"AttachStdout,omitempty" yaml:"AttachStdout,omitempty"`
AttachStderr bool `json:"AttachStderr,omitempty" yaml:"AttachStderr,omitempty"`
PortSpecs []string `json:"PortSpecs,omitempty" yaml:"PortSpecs,omitempty"`
ExposedPorts map[Port]struct{} `json:"ExposedPorts,omitempty" yaml:"ExposedPorts,omitempty"`
StopSignal string `json:"StopSignal,omitempty" yaml:"StopSignal,omitempty"`
Tty bool `json:"Tty,omitempty" yaml:"Tty,omitempty"`
OpenStdin bool `json:"OpenStdin,omitempty" yaml:"OpenStdin,omitempty"`
StdinOnce bool `json:"StdinOnce,omitempty" yaml:"StdinOnce,omitempty"`
Env []string `json:"Env,omitempty" yaml:"Env,omitempty"`
Cmd []string `json:"Cmd" yaml:"Cmd"`
DNS []string `json:"Dns,omitempty" yaml:"Dns,omitempty"` // For Docker API v1.9 and below only
Image string `json:"Image,omitempty" yaml:"Image,omitempty"`
Volumes map[string]struct{} `json:"Volumes,omitempty" yaml:"Volumes,omitempty"`
VolumeDriver string `json:"VolumeDriver,omitempty" yaml:"VolumeDriver,omitempty"`
VolumesFrom string `json:"VolumesFrom,omitempty" yaml:"VolumesFrom,omitempty"`
WorkingDir string `json:"WorkingDir,omitempty" yaml:"WorkingDir,omitempty"`
MacAddress string `json:"MacAddress,omitempty" yaml:"MacAddress,omitempty"`
Entrypoint []string `json:"Entrypoint" yaml:"Entrypoint"`
NetworkDisabled bool `json:"NetworkDisabled,omitempty" yaml:"NetworkDisabled,omitempty"`
SecurityOpts []string `json:"SecurityOpts,omitempty" yaml:"SecurityOpts,omitempty"`
OnBuild []string `json:"OnBuild,omitempty" yaml:"OnBuild,omitempty"`
Mounts []Mount `json:"Mounts,omitempty" yaml:"Mounts,omitempty"`
Labels map[string]string `json:"Labels,omitempty" yaml:"Labels,omitempty"`
}

// Mount represents a mount point in the container.
//
// It has been added in the version 1.20 of the Docker API, available since
// Docker 1.8.
// Exists only for legacy conversion, copy of type from fsouza/go-dockerclient
type Mount struct {
Name string
Source string
Destination string
Driver string
Mode string
RW bool
}

// Port represents the port number and the protocol, in the form
// <number>/<protocol>. For example: 80/tcp.
// Exists only for legacy conversion, copy of type from fsouza/go-dockerclient
type Port string
2 changes: 1 addition & 1 deletion pkg/image/importer/client.go
Expand Up @@ -270,7 +270,7 @@ func schema0ToImage(dockerImage *dockerregistry.Image) (*imageapi.Image, error)

image := &imageapi.Image{
ObjectMeta: metav1.ObjectMeta{
Name: dockerImage.ID,
Name: dockerImage.Image.ID,
},
DockerImageMetadata: baseImage,
DockerImageMetadataVersion: "1.0",
Expand Down
60 changes: 56 additions & 4 deletions pkg/image/importer/dockerv1client/client.go
Expand Up @@ -13,19 +13,71 @@ import (
"strings"
"time"

"github.com/docker/distribution/manifest/schema1"
"github.com/docker/distribution/manifest/schema2"
"github.com/fsouza/go-dockerclient"
"github.com/golang/glog"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/conversion"
knet "k8s.io/apimachinery/pkg/util/net"
"k8s.io/client-go/transport"

"github.com/docker/distribution/manifest/schema1"
"github.com/docker/distribution/manifest/schema2"
kapi "k8s.io/kubernetes/pkg/api"

imageapi "github.com/openshift/origin/pkg/image/apis/image"
)

// this is the only entrypoint which deals in github.com/fsouza/go-dockerclient.Image and expects to use our conversion capability to coerce an external
// type into an api type. Localize the crazy here.
// TODO this scheme needs to be configurable or we're going to end up with weird problems.
func init() {
err := kapi.Scheme.AddConversionFuncs(
// Convert docker client object to internal object
func(in *docker.Image, out *imageapi.DockerImage, s conversion.Scope) error {
if err := s.Convert(&in.Config, &out.Config, conversion.AllowDifferentFieldTypeNames); err != nil {
return err
}
if err := s.Convert(&in.ContainerConfig, &out.ContainerConfig, conversion.AllowDifferentFieldTypeNames); err != nil {
return err
}
out.ID = in.ID
out.Parent = in.Parent
out.Comment = in.Comment
out.Created = metav1.NewTime(in.Created)
out.Container = in.Container
out.DockerVersion = in.DockerVersion
out.Author = in.Author
out.Architecture = in.Architecture
out.Size = in.Size
return nil
},
func(in *imageapi.DockerImage, out *docker.Image, s conversion.Scope) error {
if err := s.Convert(&in.Config, &out.Config, conversion.AllowDifferentFieldTypeNames); err != nil {
return err
}
if err := s.Convert(&in.ContainerConfig, &out.ContainerConfig, conversion.AllowDifferentFieldTypeNames); err != nil {
return err
}
out.ID = in.ID
out.Parent = in.Parent
out.Comment = in.Comment
out.Created = in.Created.Time
out.Container = in.Container
out.DockerVersion = in.DockerVersion
out.Author = in.Author
out.Architecture = in.Architecture
out.Size = in.Size
return nil
},
)
if err != nil {
// If one of the conversion functions is malformed, detect it immediately.
panic(err)
}
}

type Image struct {
docker.Image
Image docker.Image

// Does this registry support pull by ID
PullByID bool
Expand Down
2 changes: 1 addition & 1 deletion pkg/image/importer/dockerv1client/client_test.go
Expand Up @@ -303,7 +303,7 @@ func TestGetTagFallback(t *testing.T) {
t.Errorf("unexpected error getting tag: %v", err)
return
}
if img.ID != "image2" {
if img.Image.ID != "image2" {
t.Errorf("unexpected image for tag: %v", img)
}
// Case when tag is not found
Expand Down
16 changes: 8 additions & 8 deletions test/integration/dockerregistryclient_test.go
Expand Up @@ -128,7 +128,7 @@ func TestRegistryClientConnectPulpRegistry(t *testing.T) {
t.Skip("pulp is failing")
//t.Fatal(err)
}
if len(image.ID) == 0 {
if len(image.Image.ID) == 0 {
t.Fatalf("image had no ID: %#v", image)
}
}
Expand All @@ -148,7 +148,7 @@ func TestRegistryClientDockerHubV2(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if len(image.ID) == 0 {
if len(image.Image.ID) == 0 {
t.Fatalf("image had no ID: %#v", image)
}
}
Expand All @@ -169,7 +169,7 @@ func TestRegistryClientDockerHubV1(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if len(image.ID) == 0 {
if len(image.Image.ID) == 0 {
t.Fatalf("image had no ID: %#v", image)
}
}
Expand Down Expand Up @@ -207,27 +207,27 @@ func doTestRegistryClientImage(t *testing.T, registry, reponame, version string)
t.Fatal(err)
}

if image.Comment != "Imported from -" {
if image.Image.Comment != "Imported from -" {
t.Errorf("%s: unexpected image comment", version)
}

if image.Architecture != "amd64" {
if image.Image.Architecture != "amd64" {
t.Errorf("%s: unexpected image architecture", version)
}

if version == "v2" && !image.PullByID {
t.Errorf("%s: should be able to pull by ID %s", version, image.ID)
t.Errorf("%s: should be able to pull by ID %s", version, image.Image.ID)
}

var other *dockerregistry.Image
err = retryWhenUnreachable(t, func() error {
other, err = conn.ImageByID("openshift", reponame, image.ID)
other, err = conn.ImageByID("openshift", reponame, image.Image.ID)
return err
})
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(other.ContainerConfig.Entrypoint, image.ContainerConfig.Entrypoint) {
if !reflect.DeepEqual(other.Image.ContainerConfig.Entrypoint, image.Image.ContainerConfig.Entrypoint) {
t.Errorf("%s: unexpected image: %#v", version, other)
}
}
Expand Down

0 comments on commit 9911834

Please sign in to comment.