mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Remove old/uneeded volume migration from vers 1.7
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
This commit is contained in:
parent
63826e291b
commit
0023abbad3
5 changed files with 0 additions and 259 deletions
|
@ -179,11 +179,6 @@ func (daemon *Daemon) restore() error {
|
||||||
delete(containers, id)
|
delete(containers, id)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// verify that all volumes valid and have been migrated from the pre-1.7 layout
|
|
||||||
if err := daemon.verifyVolumesInfo(c); err != nil {
|
|
||||||
// don't skip the container due to error
|
|
||||||
logrus.Errorf("Failed to verify volumes for container '%s': %v", c.ID, err)
|
|
||||||
}
|
|
||||||
if err := daemon.Register(c); err != nil {
|
if err := daemon.Register(c); err != nil {
|
||||||
logrus.Errorf("Failed to register container %s: %s", c.ID, err)
|
logrus.Errorf("Failed to register container %s: %s", c.ID, err)
|
||||||
delete(containers, id)
|
delete(containers, id)
|
||||||
|
|
|
@ -6,18 +6,11 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
containertypes "github.com/docker/docker/api/types/container"
|
containertypes "github.com/docker/docker/api/types/container"
|
||||||
"github.com/docker/docker/container"
|
"github.com/docker/docker/container"
|
||||||
"github.com/docker/docker/daemon/config"
|
"github.com/docker/docker/daemon/config"
|
||||||
"github.com/docker/docker/pkg/idtools"
|
|
||||||
"github.com/docker/docker/volume"
|
|
||||||
"github.com/docker/docker/volume/drivers"
|
|
||||||
"github.com/docker/docker/volume/local"
|
|
||||||
"github.com/docker/docker/volume/store"
|
|
||||||
"github.com/gotestyourself/gotestyourself/assert"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type fakeContainerGetter struct {
|
type fakeContainerGetter struct {
|
||||||
|
@ -273,85 +266,3 @@ func TestNetworkOptions(t *testing.T) {
|
||||||
t.Fatal("Expected networkOptions error, got nil")
|
t.Fatal("Expected networkOptions error, got nil")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMigratePre17Volumes(t *testing.T) {
|
|
||||||
rootDir, err := ioutil.TempDir("", "test-daemon-volumes")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(rootDir)
|
|
||||||
|
|
||||||
volumeRoot := filepath.Join(rootDir, "volumes")
|
|
||||||
err = os.MkdirAll(volumeRoot, 0755)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
containerRoot := filepath.Join(rootDir, "containers")
|
|
||||||
cid := "1234"
|
|
||||||
err = os.MkdirAll(filepath.Join(containerRoot, cid), 0755)
|
|
||||||
assert.NilError(t, err)
|
|
||||||
|
|
||||||
vid := "5678"
|
|
||||||
vfsPath := filepath.Join(rootDir, "vfs", "dir", vid)
|
|
||||||
err = os.MkdirAll(vfsPath, 0755)
|
|
||||||
assert.NilError(t, err)
|
|
||||||
|
|
||||||
config := []byte(`
|
|
||||||
{
|
|
||||||
"ID": "` + cid + `",
|
|
||||||
"Volumes": {
|
|
||||||
"/foo": "` + vfsPath + `",
|
|
||||||
"/bar": "/foo",
|
|
||||||
"/quux": "/quux"
|
|
||||||
},
|
|
||||||
"VolumesRW": {
|
|
||||||
"/foo": true,
|
|
||||||
"/bar": true,
|
|
||||||
"/quux": false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`)
|
|
||||||
|
|
||||||
volStore, err := store.New(volumeRoot)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
drv, err := local.New(volumeRoot, idtools.IDPair{UID: 0, GID: 0})
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
volumedrivers.Register(drv, volume.DefaultDriverName)
|
|
||||||
|
|
||||||
daemon := &Daemon{
|
|
||||||
root: rootDir,
|
|
||||||
repository: containerRoot,
|
|
||||||
volumes: volStore,
|
|
||||||
}
|
|
||||||
err = ioutil.WriteFile(filepath.Join(containerRoot, cid, "config.v2.json"), config, 600)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
c, err := daemon.load(cid)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
if err := daemon.verifyVolumesInfo(c); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
expected := map[string]volume.MountPoint{
|
|
||||||
"/foo": {Destination: "/foo", RW: true, Name: vid},
|
|
||||||
"/bar": {Source: "/foo", Destination: "/bar", RW: true},
|
|
||||||
"/quux": {Source: "/quux", Destination: "/quux", RW: false},
|
|
||||||
}
|
|
||||||
for id, mp := range c.MountPoints {
|
|
||||||
x, exists := expected[id]
|
|
||||||
if !exists {
|
|
||||||
t.Fatal("volume not migrated")
|
|
||||||
}
|
|
||||||
if mp.Source != x.Source || mp.Destination != x.Destination || mp.RW != x.RW || mp.Name != x.Name {
|
|
||||||
t.Fatalf("got unexpected mountpoint, expected: %+v, got: %+v", x, mp)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -632,13 +632,6 @@ func setupDaemonProcess(config *config.Config) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// verifyVolumesInfo is a no-op on windows.
|
|
||||||
// This is called during daemon initialization to migrate volumes from pre-1.7.
|
|
||||||
// volumes were not supported on windows pre-1.7
|
|
||||||
func (daemon *Daemon) verifyVolumesInfo(container *container.Container) error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (daemon *Daemon) setupSeccompProfile() error {
|
func (daemon *Daemon) setupSeccompProfile() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,10 +3,8 @@
|
||||||
package daemon // import "github.com/docker/docker/daemon"
|
package daemon // import "github.com/docker/docker/daemon"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -15,9 +13,6 @@ import (
|
||||||
"github.com/docker/docker/pkg/fileutils"
|
"github.com/docker/docker/pkg/fileutils"
|
||||||
"github.com/docker/docker/pkg/mount"
|
"github.com/docker/docker/pkg/mount"
|
||||||
"github.com/docker/docker/volume"
|
"github.com/docker/docker/volume"
|
||||||
"github.com/docker/docker/volume/drivers"
|
|
||||||
"github.com/docker/docker/volume/local"
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// setupMounts iterates through each of the mount points for a container and
|
// setupMounts iterates through each of the mount points for a container and
|
||||||
|
@ -113,80 +108,6 @@ func setBindModeIfNull(bind *volume.MountPoint) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// migrateVolume links the contents of a volume created pre Docker 1.7
|
|
||||||
// into the location expected by the local driver.
|
|
||||||
// It creates a symlink from DOCKER_ROOT/vfs/dir/VOLUME_ID to DOCKER_ROOT/volumes/VOLUME_ID/_container_data.
|
|
||||||
// It preserves the volume json configuration generated pre Docker 1.7 to be able to
|
|
||||||
// downgrade from Docker 1.7 to Docker 1.6 without losing volume compatibility.
|
|
||||||
func migrateVolume(id, vfs string) error {
|
|
||||||
l, err := volumedrivers.GetDriver(volume.DefaultDriverName)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
newDataPath := l.(*local.Root).DataPath(id)
|
|
||||||
fi, err := os.Stat(newDataPath)
|
|
||||||
if err != nil && !os.IsNotExist(err) {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if fi != nil && fi.IsDir() {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return os.Symlink(vfs, newDataPath)
|
|
||||||
}
|
|
||||||
|
|
||||||
// verifyVolumesInfo ports volumes configured for the containers pre docker 1.7.
|
|
||||||
// It reads the container configuration and creates valid mount points for the old volumes.
|
|
||||||
func (daemon *Daemon) verifyVolumesInfo(container *container.Container) error {
|
|
||||||
container.Lock()
|
|
||||||
defer container.Unlock()
|
|
||||||
|
|
||||||
// Inspect old structures only when we're upgrading from old versions
|
|
||||||
// to versions >= 1.7 and the MountPoints has not been populated with volumes data.
|
|
||||||
type volumes struct {
|
|
||||||
Volumes map[string]string
|
|
||||||
VolumesRW map[string]bool
|
|
||||||
}
|
|
||||||
cfgPath, err := container.ConfigPath()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
f, err := os.Open(cfgPath)
|
|
||||||
if err != nil {
|
|
||||||
return errors.Wrap(err, "could not open container config")
|
|
||||||
}
|
|
||||||
defer f.Close()
|
|
||||||
var cv volumes
|
|
||||||
if err := json.NewDecoder(f).Decode(&cv); err != nil {
|
|
||||||
return errors.Wrap(err, "could not decode container config")
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(container.MountPoints) == 0 && len(cv.Volumes) > 0 {
|
|
||||||
for destination, hostPath := range cv.Volumes {
|
|
||||||
vfsPath := filepath.Join(daemon.root, "vfs", "dir")
|
|
||||||
rw := cv.VolumesRW != nil && cv.VolumesRW[destination]
|
|
||||||
|
|
||||||
if strings.HasPrefix(hostPath, vfsPath) {
|
|
||||||
id := filepath.Base(hostPath)
|
|
||||||
v, err := daemon.volumes.CreateWithRef(id, volume.DefaultDriverName, container.ID, nil, nil)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := migrateVolume(id, hostPath); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
container.AddMountPointWithVolume(destination, v, true)
|
|
||||||
} else { // Bind mount
|
|
||||||
m := volume.MountPoint{Source: hostPath, Destination: destination, RW: rw}
|
|
||||||
container.MountPoints[destination] = &m
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (daemon *Daemon) mountVolumes(container *container.Container) error {
|
func (daemon *Daemon) mountVolumes(container *container.Container) error {
|
||||||
mounts, err := daemon.setupMounts(container)
|
mounts, err := daemon.setupMounts(container)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -35,7 +35,6 @@ import (
|
||||||
testdaemon "github.com/docker/docker/internal/test/daemon"
|
testdaemon "github.com/docker/docker/internal/test/daemon"
|
||||||
"github.com/docker/docker/opts"
|
"github.com/docker/docker/opts"
|
||||||
"github.com/docker/docker/pkg/mount"
|
"github.com/docker/docker/pkg/mount"
|
||||||
"github.com/docker/docker/pkg/stringid"
|
|
||||||
units "github.com/docker/go-units"
|
units "github.com/docker/go-units"
|
||||||
"github.com/docker/libnetwork/iptables"
|
"github.com/docker/libnetwork/iptables"
|
||||||
"github.com/docker/libtrust"
|
"github.com/docker/libtrust"
|
||||||
|
@ -2672,84 +2671,6 @@ func (s *DockerDaemonSuite) TestDaemonRestartSaveContainerExitCode(c *check.C) {
|
||||||
c.Assert(out, checker.Equals, errMsg1)
|
c.Assert(out, checker.Equals, errMsg1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerDaemonSuite) TestDaemonBackcompatPre17Volumes(c *check.C) {
|
|
||||||
testRequires(c, SameHostDaemon)
|
|
||||||
d := s.d
|
|
||||||
d.StartWithBusybox(c)
|
|
||||||
|
|
||||||
// hack to be able to side-load a container config
|
|
||||||
out, err := d.Cmd("create", "busybox:latest")
|
|
||||||
c.Assert(err, checker.IsNil, check.Commentf(out))
|
|
||||||
id := strings.TrimSpace(out)
|
|
||||||
|
|
||||||
out, err = d.Cmd("inspect", "--type=image", "--format={{.ID}}", "busybox:latest")
|
|
||||||
c.Assert(err, checker.IsNil, check.Commentf(out))
|
|
||||||
d.Stop(c)
|
|
||||||
<-d.Wait
|
|
||||||
|
|
||||||
imageID := strings.TrimSpace(out)
|
|
||||||
volumeID := stringid.GenerateNonCryptoID()
|
|
||||||
vfsPath := filepath.Join(d.Root, "vfs", "dir", volumeID)
|
|
||||||
c.Assert(os.MkdirAll(vfsPath, 0755), checker.IsNil)
|
|
||||||
|
|
||||||
config := []byte(`
|
|
||||||
{
|
|
||||||
"ID": "` + id + `",
|
|
||||||
"Name": "hello",
|
|
||||||
"Driver": "` + d.StorageDriver() + `",
|
|
||||||
"Image": "` + imageID + `",
|
|
||||||
"Config": {"Image": "busybox:latest"},
|
|
||||||
"NetworkSettings": {},
|
|
||||||
"Volumes": {
|
|
||||||
"/bar":"/foo",
|
|
||||||
"/foo": "` + vfsPath + `",
|
|
||||||
"/quux":"/quux"
|
|
||||||
},
|
|
||||||
"VolumesRW": {
|
|
||||||
"/bar": true,
|
|
||||||
"/foo": true,
|
|
||||||
"/quux": false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`)
|
|
||||||
|
|
||||||
configPath := filepath.Join(d.Root, "containers", id, "config.v2.json")
|
|
||||||
c.Assert(ioutil.WriteFile(configPath, config, 600), checker.IsNil)
|
|
||||||
d.Start(c)
|
|
||||||
|
|
||||||
out, err = d.Cmd("inspect", "--type=container", "--format={{ json .Mounts }}", id)
|
|
||||||
c.Assert(err, checker.IsNil, check.Commentf(out))
|
|
||||||
type mount struct {
|
|
||||||
Name string
|
|
||||||
Source string
|
|
||||||
Destination string
|
|
||||||
Driver string
|
|
||||||
RW bool
|
|
||||||
}
|
|
||||||
|
|
||||||
ls := []mount{}
|
|
||||||
err = json.NewDecoder(strings.NewReader(out)).Decode(&ls)
|
|
||||||
c.Assert(err, checker.IsNil)
|
|
||||||
|
|
||||||
expected := []mount{
|
|
||||||
{Source: "/foo", Destination: "/bar", RW: true},
|
|
||||||
{Name: volumeID, Destination: "/foo", RW: true},
|
|
||||||
{Source: "/quux", Destination: "/quux", RW: false},
|
|
||||||
}
|
|
||||||
c.Assert(ls, checker.HasLen, len(expected))
|
|
||||||
|
|
||||||
for _, m := range ls {
|
|
||||||
var matched bool
|
|
||||||
for _, x := range expected {
|
|
||||||
if m.Source == x.Source && m.Destination == x.Destination && m.RW == x.RW || m.Name != x.Name {
|
|
||||||
matched = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
c.Assert(matched, checker.True, check.Commentf("did find match for %+v", m))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *DockerDaemonSuite) TestDaemonWithUserlandProxyPath(c *check.C) {
|
func (s *DockerDaemonSuite) TestDaemonWithUserlandProxyPath(c *check.C) {
|
||||||
testRequires(c, SameHostDaemon, DaemonIsLinux)
|
testRequires(c, SameHostDaemon, DaemonIsLinux)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue