sandbox: Create and export Pause/ResumeContainer() to the API level

In order to support use cases such as containerd-shim-v2 where
we would have a long running process holding the sandbox pointer,
there would be no reason to call into the stateless functions
PauseContainer() and ResumeContainer(), which would recreate a
new sandbox pointer and the corresponding ones for containers.

Fixes #903

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf 2018-11-12 14:49:35 -08:00
parent b298ec4228
commit 57773816b3
4 changed files with 38 additions and 8 deletions

View File

@ -784,17 +784,11 @@ func togglePauseContainer(ctx context.Context, sandboxID, containerID string, pa
} }
defer s.releaseStatelessSandbox() defer s.releaseStatelessSandbox()
// Fetch the container.
c, err := s.findContainer(containerID)
if err != nil {
return err
}
if pause { if pause {
return c.pause() return s.PauseContainer(containerID)
} }
return c.resume() return s.ResumeContainer(containerID)
} }
// PauseContainer is the virtcontainers container pause entry point. // PauseContainer is the virtcontainers container pause entry point.

View File

@ -81,6 +81,8 @@ type VCSandbox interface {
KillContainer(containerID string, signal syscall.Signal, all bool) error KillContainer(containerID string, signal syscall.Signal, all bool) error
StatusContainer(containerID string) (ContainerStatus, error) StatusContainer(containerID string) (ContainerStatus, error)
StatsContainer(containerID string) (ContainerStats, error) StatsContainer(containerID string) (ContainerStats, error)
PauseContainer(containerID string) error
ResumeContainer(containerID string) error
EnterContainer(containerID string, cmd Cmd) (VCContainer, *Process, error) EnterContainer(containerID string, cmd Cmd) (VCContainer, *Process, error)
UpdateContainer(containerID string, resources specs.LinuxResources) error UpdateContainer(containerID string, resources specs.LinuxResources) error
ProcessListContainer(containerID string, options ProcessListOptions) (ProcessList, error) ProcessListContainer(containerID string, options ProcessListOptions) (ProcessList, error)

View File

@ -127,6 +127,16 @@ func (s *Sandbox) StatsContainer(contID string) (vc.ContainerStats, error) {
return vc.ContainerStats{}, nil return vc.ContainerStats{}, nil
} }
// PauseContainer implements the VCSandbox function of the same name.
func (s *Sandbox) PauseContainer(contID string) error {
return nil
}
// ResumeContainer implements the VCSandbox function of the same name.
func (s *Sandbox) ResumeContainer(contID string) error {
return nil
}
// Status implements the VCSandbox function of the same name. // Status implements the VCSandbox function of the same name.
func (s *Sandbox) Status() vc.SandboxStatus { func (s *Sandbox) Status() vc.SandboxStatus {
return vc.SandboxStatus{} return vc.SandboxStatus{}

View File

@ -1463,6 +1463,30 @@ func (s *Sandbox) StatsContainer(containerID string) (ContainerStats, error) {
return *stats, nil return *stats, nil
} }
// PauseContainer pauses a running container.
func (s *Sandbox) PauseContainer(containerID string) error {
// Fetch the container.
c, err := s.findContainer(containerID)
if err != nil {
return err
}
// Pause the container.
return c.pause()
}
// ResumeContainer resumes a paused container.
func (s *Sandbox) ResumeContainer(containerID string) error {
// Fetch the container.
c, err := s.findContainer(containerID)
if err != nil {
return err
}
// Resume the container.
return c.resume()
}
// createContainers registers all containers to the proxy, create the // createContainers registers all containers to the proxy, create the
// containers in the guest and starts one shim per container. // containers in the guest and starts one shim per container.
func (s *Sandbox) createContainers() error { func (s *Sandbox) createContainers() error {