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

Commit

Permalink
sandbox: Create and export KillContainer() to the API level
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Sebastien Boeuf committed Nov 12, 2018
1 parent 7653726 commit 3add296
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
14 changes: 1 addition & 13 deletions virtcontainers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -655,19 +655,7 @@ func KillContainer(ctx context.Context, sandboxID, containerID string, signal sy
}
defer s.releaseStatelessSandbox()

// Fetch the container.
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
return s.KillContainer(containerID, signal, all)
}

// PauseSandbox is the virtcontainers pausing entry point which pauses an
Expand Down
1 change: 1 addition & 0 deletions virtcontainers/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ type VCSandbox interface {
DeleteContainer(contID string) (VCContainer, error)
StartContainer(containerID string) (VCContainer, error)
StopContainer(containerID string) (VCContainer, error)
KillContainer(containerID string, signal syscall.Signal, all bool) error
StatusContainer(containerID string) (ContainerStatus, error)
StatsContainer(containerID string) (ContainerStats, error)
EnterContainer(containerID string, cmd Cmd) (VCContainer, *Process, error)
Expand Down
5 changes: 5 additions & 0 deletions virtcontainers/pkg/vcmock/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ func (s *Sandbox) StopContainer(contID string) (vc.VCContainer, error) {
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.
func (s *Sandbox) StatusContainer(contID string) (vc.ContainerStatus, error) {
return vc.ContainerStatus{}, nil
Expand Down
12 changes: 12 additions & 0 deletions virtcontainers/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,18 @@ func (s *Sandbox) StopContainer(containerID string) (VCContainer, error) {
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
func (s *Sandbox) DeleteContainer(containerID string) (VCContainer, error) {
if containerID == "" {
Expand Down

0 comments on commit 3add296

Please sign in to comment.