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 StopContainer() 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 StopContainer(),
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 109e12a commit 7653726
Show file tree
Hide file tree
Showing 4 changed files with 23 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 @@ -502,19 +502,7 @@ func StopContainer(ctx context.Context, sandboxID, containerID string) (VCContai
}
defer s.releaseStatelessSandbox()

// Fetch the container.
c, err := s.findContainer(containerID)
if err != nil {
return nil, err
}

// Stop it.
err = c.stop()
if err != nil {
return nil, err
}

return c, nil
return s.StopContainer(containerID)
}

// EnterContainer is the virtcontainers container command execution entry point.
Expand Down
1 change: 1 addition & 0 deletions virtcontainers/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ type VCSandbox interface {
CreateContainer(contConfig ContainerConfig) (VCContainer, error)
DeleteContainer(contID string) (VCContainer, error)
StartContainer(containerID string) (VCContainer, error)
StopContainer(containerID string) (VCContainer, 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 @@ -107,6 +107,11 @@ func (s *Sandbox) StartContainer(contID string) (vc.VCContainer, error) {
return &Container{}, nil
}

// StopContainer implements the VCSandbox function of the same name.
func (s *Sandbox) StopContainer(contID string) (vc.VCContainer, error) {
return &Container{}, 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
16 changes: 16 additions & 0 deletions virtcontainers/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -1320,6 +1320,22 @@ func (s *Sandbox) StartContainer(containerID string) (VCContainer, error) {
return c, nil
}

// StopContainer stops a container in the sandbox
func (s *Sandbox) StopContainer(containerID string) (VCContainer, error) {
// Fetch the container.
c, err := s.findContainer(containerID)
if err != nil {
return nil, err
}

// Stop it.
if err := c.stop(); err != nil {
return nil, err
}

return c, nil
}

// DeleteContainer deletes a container from the sandbox
func (s *Sandbox) DeleteContainer(containerID string) (VCContainer, error) {
if containerID == "" {
Expand Down

0 comments on commit 7653726

Please sign in to comment.