Merge pull request #15798 from calavera/volume_driver_host_config
Move VolumeDriver to HostConfig to make containers portable. Upstream-commit: 9ca4aa479788867cd2dce161efa1e43ea5dfc14f Component: engine
This commit is contained in:
@@ -106,7 +106,7 @@ func (daemon *Daemon) Create(config *runconfig.Config, hostConfig *runconfig.Hos
|
||||
}
|
||||
defer container.Unmount()
|
||||
|
||||
if err := createContainerPlatformSpecificSettings(container, config, img); err != nil {
|
||||
if err := createContainerPlatformSpecificSettings(container, config, hostConfig, img); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
)
|
||||
|
||||
// createContainerPlatformSpecificSettings performs platform specific container create functionality
|
||||
func createContainerPlatformSpecificSettings(container *Container, config *runconfig.Config, img *image.Image) error {
|
||||
func createContainerPlatformSpecificSettings(container *Container, config *runconfig.Config, hostConfig *runconfig.HostConfig, img *image.Image) error {
|
||||
for spec := range config.Volumes {
|
||||
var (
|
||||
name, destination string
|
||||
@@ -44,7 +44,7 @@ func createContainerPlatformSpecificSettings(container *Container, config *runco
|
||||
return fmt.Errorf("cannot mount volume over existing file, file exists %s", path)
|
||||
}
|
||||
|
||||
volumeDriver := config.VolumeDriver
|
||||
volumeDriver := hostConfig.VolumeDriver
|
||||
if destination != "" && img != nil {
|
||||
if _, ok := img.ContainerConfig.Volumes[destination]; ok {
|
||||
// check for whether bind is not specified and then set to local
|
||||
|
||||
@@ -6,6 +6,6 @@ import (
|
||||
)
|
||||
|
||||
// createContainerPlatformSpecificSettings performs platform specific container create functionality
|
||||
func createContainerPlatformSpecificSettings(container *Container, config *runconfig.Config, img *image.Image) error {
|
||||
func createContainerPlatformSpecificSettings(container *Container, config *runconfig.Config, hostConfig *runconfig.HostConfig, img *image.Image) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -29,6 +29,30 @@ func (daemon *Daemon) ContainerInspect(name string) (*types.ContainerJSON, error
|
||||
return &types.ContainerJSON{base, mountPoints, container.Config}, nil
|
||||
}
|
||||
|
||||
// ContainerInspect120 serializes the master version of a container into a json type.
|
||||
func (daemon *Daemon) ContainerInspect120(name string) (*types.ContainerJSON120, error) {
|
||||
container, err := daemon.Get(name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
container.Lock()
|
||||
defer container.Unlock()
|
||||
|
||||
base, err := daemon.getInspectData(container)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
mountPoints := addMountPoints(container)
|
||||
config := &types.ContainerConfig120{
|
||||
container.Config,
|
||||
container.hostConfig.VolumeDriver,
|
||||
}
|
||||
|
||||
return &types.ContainerJSON120{base, mountPoints, config}, nil
|
||||
}
|
||||
|
||||
func (daemon *Daemon) getInspectData(container *Container) (*types.ContainerJSONBase, error) {
|
||||
// make a copy to play with
|
||||
hostConfig := *container.hostConfig
|
||||
|
||||
@@ -14,7 +14,7 @@ func setPlatformSpecificContainerFields(container *Container, contJSONBase *type
|
||||
return contJSONBase
|
||||
}
|
||||
|
||||
// ContainerInspectPre120 is for backwards compatibility with pre v1.20 clients.
|
||||
// ContainerInspectPre120 gets containers for pre 1.20 APIs.
|
||||
func (daemon *Daemon) ContainerInspectPre120(name string) (*types.ContainerJSONPre120, error) {
|
||||
container, err := daemon.Get(name)
|
||||
if err != nil {
|
||||
@@ -36,8 +36,9 @@ func (daemon *Daemon) ContainerInspectPre120(name string) (*types.ContainerJSONP
|
||||
volumesRW[m.Destination] = m.RW
|
||||
}
|
||||
|
||||
config := &types.ContainerConfig{
|
||||
config := &types.ContainerConfigPre120{
|
||||
container.Config,
|
||||
container.hostConfig.VolumeDriver,
|
||||
container.hostConfig.Memory,
|
||||
container.hostConfig.MemorySwap,
|
||||
container.hostConfig.CPUShares,
|
||||
|
||||
@@ -10,3 +10,8 @@ func setPlatformSpecificContainerFields(container *Container, contJSONBase *type
|
||||
func addMountPoints(container *Container) []types.MountPoint {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ContainerInspectPre120 get containers for pre 1.20 APIs.
|
||||
func (daemon *Daemon) ContainerInspectPre120(name string) (*types.ContainerJSON, error) {
|
||||
return daemon.ContainerInspect(name)
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ package daemon
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/runconfig"
|
||||
"github.com/docker/docker/volume"
|
||||
"github.com/docker/docker/volume/drivers"
|
||||
)
|
||||
@@ -56,8 +55,7 @@ func TestParseBindMount(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
conf := &runconfig.Config{VolumeDriver: c.driver}
|
||||
m, err := parseBindMount(c.bind, c.mountLabel, conf)
|
||||
m, err := parseBindMount(c.bind, c.mountLabel, c.driver)
|
||||
if c.fail {
|
||||
if err == nil {
|
||||
t.Fatalf("Expected error, was nil, for spec %s\n", c.bind)
|
||||
|
||||
@@ -59,7 +59,7 @@ func (container *Container) setupMounts() ([]execdriver.Mount, error) {
|
||||
}
|
||||
|
||||
// parseBindMount validates the configuration of mount information in runconfig is valid.
|
||||
func parseBindMount(spec string, mountLabel string, config *runconfig.Config) (*mountPoint, error) {
|
||||
func parseBindMount(spec, mountLabel, volumeDriver string) (*mountPoint, error) {
|
||||
bind := &mountPoint{
|
||||
RW: true,
|
||||
}
|
||||
@@ -92,7 +92,7 @@ func parseBindMount(spec string, mountLabel string, config *runconfig.Config) (*
|
||||
}
|
||||
|
||||
if len(source) == 0 {
|
||||
bind.Driver = config.VolumeDriver
|
||||
bind.Driver = volumeDriver
|
||||
if len(bind.Driver) == 0 {
|
||||
bind.Driver = volume.DefaultDriverName
|
||||
}
|
||||
@@ -330,7 +330,7 @@ func (daemon *Daemon) registerMountPoints(container *Container, hostConfig *runc
|
||||
// 3. Read bind mounts
|
||||
for _, b := range hostConfig.Binds {
|
||||
// #10618
|
||||
bind, err := parseBindMount(b, container.MountLabel, container.Config)
|
||||
bind, err := parseBindMount(b, container.MountLabel, hostConfig.VolumeDriver)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user