Skip to content
This repository has been archived by the owner on Feb 8, 2021. It is now read-only.

Commit

Permalink
sandbox: add the volume support for sandbox
Browse files Browse the repository at this point in the history
Signed-off-by: fupan <[email protected]>
  • Loading branch information
lifupan committed Jul 17, 2018
1 parent 9d2bee1 commit 10c4087
Showing 1 changed file with 49 additions and 21 deletions.
70 changes: 49 additions & 21 deletions daemon/pod/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,18 +424,6 @@ func (c *Container) init(allowCreate bool) error {

c.status.CreatedAt, _ = time.Parse(time.RFC3339Nano, cjson.Created)

contConfig, err := c.containerConfig(cjson)
if err != nil {
c.Log(ERROR, err)
return err
}
c.contConfig = contConfig

if err != nil {
c.Log(ERROR, err)
return err
}

c.mergeVolumes(cjson)

if !loaded {
Expand All @@ -451,6 +439,13 @@ func (c *Container) init(allowCreate bool) error {
c.injectFiles(c.mountId)
}

contConfig, err := c.containerConfig(cjson)
if err != nil {
c.Log(ERROR, err)
return err
}
c.contConfig = contConfig

return nil
}

Expand Down Expand Up @@ -559,26 +554,54 @@ func (c *Container) cmdEnvs(envs []vc.EnvVar) []vc.EnvVar {
return envs
}

func newMount(m dockertypes.MountPoint) vc.Mount {
func newcMount(m dockertypes.MountPoint) vc.Mount {
return vc.Mount{
Source: m.Source,
Destination: m.Destination,
}
}

func containerMounts(cjson *dockertypes.ContainerJSON) []vc.Mount {
func newOciMount(m dockertypes.MountPoint) specs.Mount {
return specs.Mount{
Source: m.Source,
Destination: m.Destination,
}
}

func (c *Container) containerOciMounts(cjson *dockertypes.ContainerJSON) ([]vc.Mount, []specs.Mount) {
cMounts := cjson.Mounts

if cMounts == nil {
return []vc.Mount{}
}
var cmnts []vc.Mount
var ocimnts []specs.Mount

var mnts []vc.Mount
for _, m := range cMounts {
mnts = append(mnts, newMount(m))
cmnts = append(cmnts, newcMount(m))
ocimnts = append(ocimnts, newOciMount(m))
}

for _, vol := range c.spec.Volumes {
if vol.Detail.Format == "vfs" {
cmnt := vc.Mount{
Source: vol.Detail.Source,
Destination: vol.Path,
Type: "bind",
ReadOnly: vol.ReadOnly,
}

cmnts = append(cmnts, cmnt)

ocimnt := specs.Mount{
Source: vol.Detail.Source,
Destination: vol.Path,
Type: "bind",
Options: []string{"rbind", "rprivate"},
}

ocimnts = append(ocimnts, ocimnt)
}
}

return mnts
return cmnts, ocimnts
}

func (c *Container) ociEnv() []string {
Expand Down Expand Up @@ -660,6 +683,11 @@ func (c *Container) containerConfig(cjson *dockertypes.ContainerJSON) (*vc.Conta
oci.RemoveNamespace(ociSpec, ns)
}

cmnts, ocimnts := c.containerOciMounts(cjson)
for _, mnt := range ocimnts {
ociSpec.Mounts = append(ociSpec.Mounts, mnt)
}

ociSpecJson, err := json.Marshal(ociSpec)
if err != nil {
return &vc.ContainerConfig{}, nil
Expand Down Expand Up @@ -704,7 +732,7 @@ func (c *Container) containerConfig(cjson *dockertypes.ContainerJSON) (*vc.Conta
vcAnnotations.ConfigJSONKey: string(ociSpecJson),
vcAnnotations.BundlePathKey: path.Join(c.p.sandboxShareDir(), mountId),
},
Mounts: containerMounts(cjson),
Mounts: cmnts,
}

c.Log(TRACE, "Container Info is \n%#v", containerConfig)
Expand Down

0 comments on commit 10c4087

Please sign in to comment.