Merge pull request #19273 from calavera/volume-lazy-init
[Carry 18549] Lazy initialize Volume on container Mount object. Upstream-commit: 184040bdd55c3930123ad4984dd976181b26cae8 Component: engine
This commit is contained in:
@ -10,13 +10,8 @@ import (
|
||||
|
||||
func (daemon *Daemon) prepareMountPoints(container *container.Container) error {
|
||||
for _, config := range container.MountPoints {
|
||||
if len(config.Driver) > 0 {
|
||||
v, err := daemon.volumes.GetWithRef(config.Name, config.Driver, container.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
config.Volume = v
|
||||
if err := daemon.lazyInitializeVolume(container.ID, config); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
@ -153,3 +153,17 @@ func (daemon *Daemon) registerMountPoints(container *container.Container, hostCo
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// lazyInitializeVolume initializes a mountpoint's volume if needed.
|
||||
// This happens after a daemon restart.
|
||||
func (daemon *Daemon) lazyInitializeVolume(containerID string, m *volume.MountPoint) error {
|
||||
if len(m.Driver) > 0 && m.Volume == nil {
|
||||
v, err := daemon.volumes.GetWithRef(m.Name, m.Driver, containerID)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
m.Volume = v
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -20,6 +20,9 @@ import (
|
||||
func (daemon *Daemon) setupMounts(container *container.Container) ([]execdriver.Mount, error) {
|
||||
var mounts []execdriver.Mount
|
||||
for _, m := range container.MountPoints {
|
||||
if err := daemon.lazyInitializeVolume(container.ID, m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
path, err := m.Setup()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@ -18,6 +18,9 @@ import (
|
||||
func (daemon *Daemon) setupMounts(container *container.Container) ([]execdriver.Mount, error) {
|
||||
var mnts []execdriver.Mount
|
||||
for _, mount := range container.MountPoints { // type is volume.MountPoint
|
||||
if err := daemon.lazyInitializeVolume(container.ID, mount); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// If there is no source, take it from the volume path
|
||||
s := mount.Source
|
||||
if s == "" && mount.Volume != nil {
|
||||
|
||||
Reference in New Issue
Block a user