sandbox: Create and export KillContainer() 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 function KillContainer(),
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:23:33 -08:00
parent 76537265cb
commit 3add296f78
4 changed files with 19 additions and 13 deletions

View File

@ -655,19 +655,7 @@ func KillContainer(ctx context.Context, sandboxID, containerID string, signal sy
} }
defer s.releaseStatelessSandbox() defer s.releaseStatelessSandbox()
// Fetch the container. return s.KillContainer(containerID, signal, all)
c, err := s.findContainer(containerID)
if err != nil {
return err
}
// Send a signal to the process.
err = c.kill(signal, all)
if err != nil {
return err
}
return nil
} }
// PauseSandbox is the virtcontainers pausing entry point which pauses an // PauseSandbox is the virtcontainers pausing entry point which pauses an

View File

@ -78,6 +78,7 @@ type VCSandbox interface {
DeleteContainer(contID string) (VCContainer, error) DeleteContainer(contID string) (VCContainer, error)
StartContainer(containerID string) (VCContainer, error) StartContainer(containerID string) (VCContainer, error)
StopContainer(containerID string) (VCContainer, error) StopContainer(containerID string) (VCContainer, 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)
EnterContainer(containerID string, cmd Cmd) (VCContainer, *Process, error) EnterContainer(containerID string, cmd Cmd) (VCContainer, *Process, error)

View File

@ -112,6 +112,11 @@ func (s *Sandbox) StopContainer(contID string) (vc.VCContainer, error) {
return &Container{}, nil return &Container{}, nil
} }
// KillContainer implements the VCSandbox function of the same name.
func (s *Sandbox) KillContainer(contID string, signal syscall.Signal, all bool) error {
return nil
}
// StatusContainer implements the VCSandbox function of the same name. // StatusContainer implements the VCSandbox function of the same name.
func (s *Sandbox) StatusContainer(contID string) (vc.ContainerStatus, error) { func (s *Sandbox) StatusContainer(contID string) (vc.ContainerStatus, error) {
return vc.ContainerStatus{}, nil return vc.ContainerStatus{}, nil

View File

@ -1336,6 +1336,18 @@ func (s *Sandbox) StopContainer(containerID string) (VCContainer, error) {
return c, nil return c, nil
} }
// KillContainer signals a container in the sandbox
func (s *Sandbox) KillContainer(containerID string, signal syscall.Signal, all bool) error {
// Fetch the container.
c, err := s.findContainer(containerID)
if err != nil {
return err
}
// Send a signal to the process.
return c.kill(signal, all)
}
// DeleteContainer deletes a container from the sandbox // DeleteContainer deletes a container from the sandbox
func (s *Sandbox) DeleteContainer(containerID string) (VCContainer, error) { func (s *Sandbox) DeleteContainer(containerID string) (VCContainer, error) {
if containerID == "" { if containerID == "" {