Make API volume-driver dependent on 'experimental'

Signed-off-by: Arnaud Porterie <arnaud.porterie@docker.com>
This commit is contained in:
Arnaud Porterie 2015-05-20 14:53:53 -07:00 коммит произвёл David Calavera
Родитель 4fc37a1ede
Коммит 2653c7c16c
11 изменённых файлов: 111 добавлений и 53 удалений

Просмотреть файл

@ -1039,7 +1039,7 @@ func (container *Container) networkMounts() []execdriver.Mount {
return mounts
}
func (container *Container) AddLocalMountPoint(name, destination string, rw bool) {
func (container *Container) addLocalMountPoint(name, destination string, rw bool) {
container.MountPoints[destination] = &mountPoint{
Name: name,
Driver: volume.DefaultDriverName,
@ -1048,7 +1048,7 @@ func (container *Container) AddLocalMountPoint(name, destination string, rw bool
}
}
func (container *Container) AddMountPointWithVolume(destination string, vol volume.Volume, rw bool) {
func (container *Container) addMountPointWithVolume(destination string, vol volume.Volume, rw bool) {
container.MountPoints[destination] = &mountPoint{
Name: vol.Name(),
Driver: vol.DriverName(),
@ -1058,11 +1058,11 @@ func (container *Container) AddMountPointWithVolume(destination string, vol volu
}
}
func (container *Container) IsDestinationMounted(destination string) bool {
func (container *Container) isDestinationMounted(destination string) bool {
return container.MountPoints[destination] != nil
}
func (container *Container) PrepareMountPoints() error {
func (container *Container) prepareMountPoints() error {
for _, config := range container.MountPoints {
if len(config.Driver) > 0 {
v, err := createVolume(config.Name, config.Driver)
@ -1075,7 +1075,7 @@ func (container *Container) PrepareMountPoints() error {
return nil
}
func (container *Container) RemoveMountPoints() error {
func (container *Container) removeMountPoints() error {
for _, m := range container.MountPoints {
if m.Volume != nil {
if err := removeVolume(m.Volume); err != nil {
@ -1086,7 +1086,7 @@ func (container *Container) RemoveMountPoints() error {
return nil
}
func (container *Container) ShouldRestart() bool {
func (container *Container) shouldRestart() bool {
return container.hostConfig.RestartPolicy.Name == "always" ||
(container.hostConfig.RestartPolicy.Name == "on-failure" && container.ExitCode != 0)
}

Просмотреть файл

@ -113,7 +113,7 @@ func (daemon *Daemon) Create(config *runconfig.Config, hostConfig *runconfig.Hos
}
// Skip volumes for which we already have something mounted on that
// destination because of a --volume-from.
if container.IsDestinationMounted(destination) {
if container.isDestinationMounted(destination) {
continue
}
path, err := container.GetResourcePath(destination)
@ -136,7 +136,7 @@ func (daemon *Daemon) Create(config *runconfig.Config, hostConfig *runconfig.Hos
}
copyExistingContents(rootfs, path)
container.AddMountPointWithVolume(destination, v, true)
container.addMountPointWithVolume(destination, v, true)
}
if err := container.ToDisk(); err != nil {
return nil, nil, err

Просмотреть файл

@ -216,7 +216,7 @@ func (daemon *Daemon) register(container *Container, updateSuffixarray bool) err
return err
}
if err := container.PrepareMountPoints(); err != nil {
if err := container.prepareMountPoints(); err != nil {
return err
}
@ -333,7 +333,7 @@ func (daemon *Daemon) restore() error {
// check the restart policy on the containers and restart any container with
// the restart policy of "always"
if daemon.config.AutoRestart && container.ShouldRestart() {
if daemon.config.AutoRestart && container.shouldRestart() {
logrus.Debugf("Starting container %s", container.ID)
if err := container.Start(); err != nil {

Просмотреть файл

@ -71,7 +71,7 @@ func (daemon *Daemon) ContainerRm(name string, config *ContainerRmConfig) error
}
container.LogEvent("destroy")
if config.RemoveVolume {
container.RemoveMountPoints()
container.removeMountPoints()
}
}
return nil
@ -154,5 +154,5 @@ func (daemon *Daemon) commonRm(container *Container, forceRemove bool) (err erro
}
func (daemon *Daemon) DeleteVolumes(c *Container) error {
return c.RemoveMountPoints()
return c.removeMountPoints()
}

Просмотреть файл

@ -12,7 +12,6 @@ import (
"github.com/docker/docker/pkg/chrootarchive"
"github.com/docker/docker/runconfig"
"github.com/docker/docker/volume"
volumedrivers "github.com/docker/docker/volume/drivers"
)
type mountPoint struct {
@ -246,7 +245,7 @@ func (daemon *Daemon) verifyOldVolumesInfo(container *Container) error {
if strings.HasPrefix(hostPath, vfsPath) {
id := filepath.Base(hostPath)
container.AddLocalMountPoint(id, destination, vols.VolumesRW[destination])
container.addLocalMountPoint(id, destination, vols.VolumesRW[destination])
}
}
@ -268,14 +267,3 @@ func removeVolume(v volume.Volume) error {
}
return vd.Remove(v)
}
func getVolumeDriver(name string) (volume.Driver, error) {
if name == "" {
name = volume.DefaultDriverName
}
vd := volumedrivers.Lookup(name)
if vd == nil {
return nil, fmt.Errorf("Volumes Driver %s isn't registered", name)
}
return vd, nil
}

Просмотреть файл

@ -0,0 +1,15 @@
// +build experimental
package daemon
import (
"github.com/docker/docker/volume"
"github.com/docker/docker/volume/drivers"
)
func getVolumeDriver(name string) (volume.Driver, error) {
if name == "" {
name = volume.DefaultDriverName
}
return volumedrivers.Lookup(name)
}

Просмотреть файл

@ -0,0 +1,32 @@
// +build experimental
package daemon
import (
"testing"
"github.com/docker/docker/volume"
"github.com/docker/docker/volume/drivers"
)
type fakeDriver struct{}
func (fakeDriver) Name() string { return "fake" }
func (fakeDriver) Create(name string) (volume.Volume, error) { return nil, nil }
func (fakeDriver) Remove(v volume.Volume) error { return nil }
func TestGetVolumeDriver(t *testing.T) {
_, err := getVolumeDriver("missing")
if err == nil {
t.Fatal("Expected error, was nil")
}
volumedrivers.Register(fakeDriver{}, "fake")
d, err := getVolumeDriver("fake")
if err != nil {
t.Fatal(err)
}
if d.Name() != "fake" {
t.Fatalf("Expected fake driver, got %s\n", d.Name())
}
}

12
daemon/volumes_stubs.go Normal file
Просмотреть файл

@ -0,0 +1,12 @@
// +build !experimental
package daemon
import (
"github.com/docker/docker/volume"
"github.com/docker/docker/volume/drivers"
)
func getVolumeDriver(_ string) (volume.Driver, error) {
return volumedrivers.Lookup(volume.DefaultDriverName)
}

Просмотреть файл

@ -0,0 +1,35 @@
// +build !experimental
package daemon
import (
"io/ioutil"
"os"
"testing"
"github.com/docker/docker/volume"
"github.com/docker/docker/volume/drivers"
"github.com/docker/docker/volume/local"
)
func TestGetVolumeDefaultDriver(t *testing.T) {
tmp, err := ioutil.TempDir("", "volume-test-")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tmp)
l, err := local.New(tmp)
if err != nil {
t.Fatal(err)
}
volumedrivers.Register(l, volume.DefaultDriverName)
d, err := getVolumeDriver("missing")
if err != nil {
t.Fatal(err)
}
if d.Name() != volume.DefaultDriverName {
t.Fatalf("Expected local driver, was %s\n", d.Name)
}
}

Просмотреть файл

@ -4,8 +4,6 @@ import (
"testing"
"github.com/docker/docker/runconfig"
"github.com/docker/docker/volume"
volumedrivers "github.com/docker/docker/volume/drivers"
)
func TestParseBindMount(t *testing.T) {
@ -95,25 +93,3 @@ func TestParseVolumeFrom(t *testing.T) {
}
}
}
type fakeDriver struct{}
func (fakeDriver) Name() string { return "fake" }
func (fakeDriver) Create(name string) (volume.Volume, error) { return nil, nil }
func (fakeDriver) Remove(v volume.Volume) error { return nil }
func TestGetVolumeDriver(t *testing.T) {
_, err := getVolumeDriver("missing")
if err == nil {
t.Fatal("Expected error, was nil")
}
volumedrivers.Register(fakeDriver{}, "fake")
d, err := getVolumeDriver("fake")
if err != nil {
t.Fatal(err)
}
if d.Name() != "fake" {
t.Fatalf("Expected fake driver, got %s\n", d.Name())
}
}

Просмотреть файл

@ -43,19 +43,19 @@ func Unregister(name string) bool {
return true
}
func Lookup(name string) volume.Driver {
func Lookup(name string) (volume.Driver, error) {
drivers.Lock()
defer drivers.Unlock()
ext, ok := drivers.extensions[name]
if ok {
return ext
return ext, nil
}
pl, err := plugins.Get(name, "VolumeDriver")
if err != nil {
logrus.Errorf("Error: %v", err)
return nil
return nil, err
}
d := NewVolumeDriver(name, pl.Client)
drivers.extensions[name] = d
return d
return d, nil
}