Merge pull request #25721 from cpuguy83/revendor_engine-api

revendor engine-api
This commit is contained in:
Brian Goff
2016-08-16 17:18:43 -04:00
committed by GitHub
42 changed files with 241 additions and 182 deletions

View File

@@ -10,6 +10,7 @@ import (
"github.com/docker/docker/opts"
runconfigopts "github.com/docker/docker/runconfig/opts"
mounttypes "github.com/docker/engine-api/types/mount"
"github.com/docker/engine-api/types/swarm"
"github.com/docker/go-connections/nat"
units "github.com/docker/go-units"
@@ -130,7 +131,7 @@ func (i *Uint64Opt) Value() *uint64 {
// MountOpt is a Value type for parsing mounts
type MountOpt struct {
values []swarm.Mount
values []mounttypes.Mount
}
// Set a new mount value
@@ -141,23 +142,23 @@ func (m *MountOpt) Set(value string) error {
return err
}
mount := swarm.Mount{}
mount := mounttypes.Mount{}
volumeOptions := func() *swarm.VolumeOptions {
volumeOptions := func() *mounttypes.VolumeOptions {
if mount.VolumeOptions == nil {
mount.VolumeOptions = &swarm.VolumeOptions{
mount.VolumeOptions = &mounttypes.VolumeOptions{
Labels: make(map[string]string),
}
}
if mount.VolumeOptions.DriverConfig == nil {
mount.VolumeOptions.DriverConfig = &swarm.Driver{}
mount.VolumeOptions.DriverConfig = &mounttypes.Driver{}
}
return mount.VolumeOptions
}
bindOptions := func() *swarm.BindOptions {
bindOptions := func() *mounttypes.BindOptions {
if mount.BindOptions == nil {
mount.BindOptions = new(swarm.BindOptions)
mount.BindOptions = new(mounttypes.BindOptions)
}
return mount.BindOptions
}
@@ -171,7 +172,7 @@ func (m *MountOpt) Set(value string) error {
}
}
mount.Type = swarm.MountTypeVolume // default to volume mounts
mount.Type = mounttypes.TypeVolume // default to volume mounts
// Set writable as the default
for _, field := range fields {
parts := strings.SplitN(field, "=", 2)
@@ -195,7 +196,7 @@ func (m *MountOpt) Set(value string) error {
value := parts[1]
switch key {
case "type":
mount.Type = swarm.MountType(strings.ToLower(value))
mount.Type = mounttypes.Type(strings.ToLower(value))
case "source", "src":
mount.Source = value
case "target", "dst", "destination":
@@ -206,7 +207,7 @@ func (m *MountOpt) Set(value string) error {
return fmt.Errorf("invalid value for %s: %s", key, value)
}
case "bind-propagation":
bindOptions().Propagation = swarm.MountPropagation(strings.ToLower(value))
bindOptions().Propagation = mounttypes.Propagation(strings.ToLower(value))
case "volume-nocopy":
volumeOptions().NoCopy, err = strconv.ParseBool(value)
if err != nil {
@@ -238,11 +239,11 @@ func (m *MountOpt) Set(value string) error {
return fmt.Errorf("source is required when specifying volume-* options")
}
if mount.Type == swarm.MountTypeBind && mount.VolumeOptions != nil {
return fmt.Errorf("cannot mix 'volume-*' options with mount type '%s'", swarm.MountTypeBind)
if mount.Type == mounttypes.TypeBind && mount.VolumeOptions != nil {
return fmt.Errorf("cannot mix 'volume-*' options with mount type '%s'", mounttypes.TypeBind)
}
if mount.Type == swarm.MountTypeVolume && mount.BindOptions != nil {
return fmt.Errorf("cannot mix 'bind-*' options with mount type '%s'", swarm.MountTypeVolume)
if mount.Type == mounttypes.TypeVolume && mount.BindOptions != nil {
return fmt.Errorf("cannot mix 'bind-*' options with mount type '%s'", mounttypes.TypeVolume)
}
m.values = append(m.values, mount)
@@ -265,7 +266,7 @@ func (m *MountOpt) String() string {
}
// Value returns the mounts
func (m *MountOpt) Value() []swarm.Mount {
func (m *MountOpt) Value() []mounttypes.Mount {
return m.values
}

View File

@@ -5,7 +5,7 @@ import (
"time"
"github.com/docker/docker/pkg/testutil/assert"
"github.com/docker/engine-api/types/swarm"
mounttypes "github.com/docker/engine-api/types/mount"
)
func TestMemBytesString(t *testing.T) {
@@ -59,14 +59,14 @@ func TestUint64OptSetAndValue(t *testing.T) {
func TestMountOptString(t *testing.T) {
mount := MountOpt{
values: []swarm.Mount{
values: []mounttypes.Mount{
{
Type: swarm.MountTypeBind,
Type: mounttypes.TypeBind,
Source: "/home/path",
Target: "/target",
},
{
Type: swarm.MountTypeVolume,
Type: mounttypes.TypeVolume,
Source: "foo",
Target: "/target/foo",
},
@@ -90,8 +90,8 @@ func TestMountOptSetNoError(t *testing.T) {
mounts := mount.Value()
assert.Equal(t, len(mounts), 1)
assert.Equal(t, mounts[0], swarm.Mount{
Type: swarm.MountTypeBind,
assert.Equal(t, mounts[0], mounttypes.Mount{
Type: mounttypes.TypeBind,
Source: "/source",
Target: "/target",
})
@@ -103,7 +103,7 @@ func TestMountOptSetNoError(t *testing.T) {
func TestMountOptDefaultType(t *testing.T) {
var mount MountOpt
assert.NilError(t, mount.Set("target=/target,source=/foo"))
assert.Equal(t, mount.values[0].Type, swarm.MountTypeVolume)
assert.Equal(t, mount.values[0].Type, mounttypes.TypeVolume)
}
func TestMountOptSetErrorNoTarget(t *testing.T) {

View File

@@ -13,6 +13,7 @@ import (
"github.com/docker/docker/opts"
runconfigopts "github.com/docker/docker/runconfig/opts"
"github.com/docker/engine-api/types"
mounttypes "github.com/docker/engine-api/types/mount"
"github.com/docker/engine-api/types/swarm"
"github.com/docker/go-connections/nat"
shlex "github.com/flynn-archive/go-shlex"
@@ -353,14 +354,14 @@ func removeItems(
return newSeq
}
func updateMounts(flags *pflag.FlagSet, mounts *[]swarm.Mount) {
func updateMounts(flags *pflag.FlagSet, mounts *[]mounttypes.Mount) {
if flags.Changed(flagMountAdd) {
values := flags.Lookup(flagMountAdd).Value.(*MountOpt).Value()
*mounts = append(*mounts, values...)
}
toRemove := buildToRemoveSet(flags, flagMountRemove)
newMounts := []swarm.Mount{}
newMounts := []mounttypes.Mount{}
for _, mount := range *mounts {
if _, exists := toRemove[mount.Target]; !exists {
newMounts = append(newMounts, mount)

View File

@@ -5,6 +5,7 @@ import (
"testing"
"github.com/docker/docker/pkg/testutil/assert"
mounttypes "github.com/docker/engine-api/types/mount"
"github.com/docker/engine-api/types/swarm"
)
@@ -104,9 +105,9 @@ func TestUpdateMounts(t *testing.T) {
flags.Set("mount-add", "type=volume,target=/toadd")
flags.Set("mount-rm", "/toremove")
mounts := []swarm.Mount{
{Target: "/toremove", Type: swarm.MountTypeBind},
{Target: "/tokeep", Type: swarm.MountTypeBind},
mounts := []mounttypes.Mount{
{Target: "/toremove", Type: mounttypes.TypeBind},
{Target: "/tokeep", Type: mounttypes.TypeBind},
}
updateMounts(flags, &mounts)

View File

@@ -54,7 +54,7 @@ func runInspect(dockerCli *client.DockerCli, opts inspectOptions) error {
}
case "image":
getRefFunc = func(ref string) (interface{}, []byte, error) {
return client.ImageInspectWithRaw(ctx, ref, opts.size)
return client.ImageInspectWithRaw(ctx, ref)
}
case "task":
if opts.size {
@@ -81,7 +81,7 @@ func inspectAll(ctx context.Context, dockerCli *client.DockerCli, getSize bool)
return c, rawContainer, err
}
// Search for image with that id if a container doesn't exist.
i, rawImage, err := client.ImageInspectWithRaw(ctx, ref, getSize)
i, rawImage, err := client.ImageInspectWithRaw(ctx, ref)
if err == nil || !apiclient.IsErrNotFound(err) {
return i, rawImage, err
}

View File

@@ -30,7 +30,7 @@ func runRemove(dockerCli *client.DockerCli, volumes []string) error {
status := 0
for _, name := range volumes {
if err := client.VolumeRemove(ctx, name); err != nil {
if err := client.VolumeRemove(ctx, name, false); err != nil {
fmt.Fprintf(dockerCli.Err(), "%s\n", err)
status = 1
continue

View File

@@ -15,6 +15,7 @@ import (
"github.com/docker/engine-api/types/events"
"github.com/docker/engine-api/types/filters"
timetypes "github.com/docker/engine-api/types/time"
"github.com/docker/engine-api/types/versions"
"golang.org/x/net/context"
)
@@ -37,6 +38,14 @@ func (s *systemRouter) getInfo(ctx context.Context, w http.ResponseWriter, r *ht
info.Swarm = s.clusterProvider.Info()
}
if versions.LessThan("1.25", httputils.VersionFromContext(ctx)) {
// TODO: handle this conversion in engine-api
type oldInfo struct {
*types.Info
ExecutionDriver string
}
return httputils.WriteJSON(w, http.StatusOK, &oldInfo{Info: info, ExecutionDriver: "<not supported>"})
}
return httputils.WriteJSON(w, http.StatusOK, info)
}