Extract helper method for volume linking.
Makes this more readable.
This commit is contained in:
parent
7428e6a5f0
commit
84f78d9cad
76
container.go
76
container.go
|
@ -583,42 +583,7 @@ func (container *Container) Start() (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply volumes from another container if requested
|
// Apply volumes from another container if requested
|
||||||
if container.Config.VolumesFrom != "" {
|
container.joinVolumes()
|
||||||
containerSpecs := strings.Split(container.Config.VolumesFrom, ",")
|
|
||||||
for _, containerSpec := range containerSpecs {
|
|
||||||
mountRW := true
|
|
||||||
specParts := strings.SplitN(containerSpec, ":", 2)
|
|
||||||
switch len(specParts) {
|
|
||||||
case 0:
|
|
||||||
return fmt.Errorf("Malformed volumes-from specification: %s", container.Config.VolumesFrom)
|
|
||||||
case 2:
|
|
||||||
switch specParts[1] {
|
|
||||||
case "ro":
|
|
||||||
mountRW = false
|
|
||||||
case "rw": // mountRW is already true
|
|
||||||
default:
|
|
||||||
return fmt.Errorf("Malformed volumes-from speficication: %s", containerSpec)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
c := container.runtime.Get(specParts[0])
|
|
||||||
if c == nil {
|
|
||||||
return fmt.Errorf("Container %s not found. Impossible to mount its volumes", container.ID)
|
|
||||||
}
|
|
||||||
for volPath, id := range c.Volumes {
|
|
||||||
if _, exists := container.Volumes[volPath]; exists {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if err := os.MkdirAll(path.Join(container.RootfsPath(), volPath), 0755); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
container.Volumes[volPath] = id
|
|
||||||
if isRW, exists := c.VolumesRW[volPath]; exists {
|
|
||||||
container.VolumesRW[volPath] = isRW && mountRW
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
volumesDriver := container.runtime.volumes.driver
|
volumesDriver := container.runtime.volumes.driver
|
||||||
// Create the requested volumes if they don't exist
|
// Create the requested volumes if they don't exist
|
||||||
|
@ -915,6 +880,45 @@ func (container *Container) Start() (err error) {
|
||||||
return ErrContainerStart
|
return ErrContainerStart
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (container *Container) joinVolumes() error {
|
||||||
|
if container.Config.VolumesFrom != "" {
|
||||||
|
containerSpecs := strings.Split(container.Config.VolumesFrom, ",")
|
||||||
|
for _, containerSpec := range containerSpecs {
|
||||||
|
mountRW := true
|
||||||
|
specParts := strings.SplitN(containerSpec, ":", 2)
|
||||||
|
switch len(specParts) {
|
||||||
|
case 0:
|
||||||
|
return fmt.Errorf("Malformed volumes-from specification: %s", container.Config.VolumesFrom)
|
||||||
|
case 2:
|
||||||
|
switch specParts[1] {
|
||||||
|
case "ro":
|
||||||
|
mountRW = false
|
||||||
|
case "rw": // mountRW is already true
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("Malformed volumes-from speficication: %s", containerSpec)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c := container.runtime.Get(specParts[0])
|
||||||
|
if c == nil {
|
||||||
|
return fmt.Errorf("Container %s not found. Impossible to mount its volumes", container.ID)
|
||||||
|
}
|
||||||
|
for volPath, id := range c.Volumes {
|
||||||
|
if _, exists := container.Volumes[volPath]; exists {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if err := os.MkdirAll(path.Join(container.RootfsPath(), volPath), 0755); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
container.Volumes[volPath] = id
|
||||||
|
if isRW, exists := c.VolumesRW[volPath]; exists {
|
||||||
|
container.VolumesRW[volPath] = isRW && mountRW
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (container *Container) Run() error {
|
func (container *Container) Run() error {
|
||||||
if err := container.Start(); err != nil {
|
if err := container.Start(); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in New Issue