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

Commit

Permalink
containerd-shim-kata-v2: use the sandbox api instead of VC api
Browse files Browse the repository at this point in the history
When creating a container, the sandbox struct has been created,
thus it's better to use sandbox's api to create container instead
of VC's api, which will reload the sandbox from the configure
files and recreate the sandbox structs in the memory.

Signed-off-by: fupan <[email protected]>
  • Loading branch information
lifupan committed Aug 10, 2018
1 parent bac0b90 commit 76ffe80
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions containerd-shim/kata/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ func create(s *service, containerID, bundlePath, netns string, detach bool,
s.sandbox = c.Sandbox()

case vc.PodContainer:
c, err = createContainer(ociSpec, containerID, bundlePath, disableOutput)
if s.sandbox == nil {
return nil, fmt.Errorf("BUG: Cannot start the container, since the sandbox hasn't been created")
}

c, err = createContainer(s.sandbox, ociSpec, containerID, bundlePath, disableOutput)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -233,7 +237,7 @@ func setEphemeralStorageType(ociSpec oci.CompatOCISpec) oci.CompatOCISpec {
return ociSpec
}

func createContainer(ociSpec oci.CompatOCISpec, containerID, bundlePath string,
func createContainer(sandbox vc.VCSandbox, ociSpec oci.CompatOCISpec, containerID, bundlePath string,
disableOutput bool) (vc.VCContainer, error) {

ociSpec = setEphemeralStorageType(ociSpec)
Expand All @@ -243,17 +247,12 @@ func createContainer(ociSpec oci.CompatOCISpec, containerID, bundlePath string,
return nil, err
}

sandboxID, err := ociSpec.SandboxID()
c, err := sandbox.CreateContainer(contConfig)
if err != nil {
return nil, err
}

_, c, err := vci.CreateContainer(sandboxID, contConfig)
if err != nil {
return nil, err
}

if err := addContainerIDMapping(containerID, sandboxID); err != nil {
if err := addContainerIDMapping(containerID, sandbox.ID()); err != nil {
return nil, err
}

Expand Down

0 comments on commit 76ffe80

Please sign in to comment.