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

Commit

Permalink
sandbox: Export Start() 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 StartSandbox(),
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 4cddfc6 commit 6c3e266
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion virtcontainers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func StartSandbox(ctx context.Context, sandboxID string) (VCSandbox, error) {

func startSandbox(s *Sandbox) (*Sandbox, error) {
// Start it
err := s.start()
err := s.Start()
if err != nil {
return nil, err
}
Expand Down
1 change: 1 addition & 0 deletions virtcontainers/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ type VCSandbox interface {
ID() string
SetAnnotations(annotations map[string]string) error

Start() error
Pause() error
Resume() error
Release() 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 @@ -67,6 +67,11 @@ func (s *Sandbox) Release() error {
return nil
}

// Start implements the VCSandbox function of the same name.
func (s *Sandbox) Start() error {
return nil
}

// Pause implements the VCSandbox function of the same name.
func (s *Sandbox) Pause() error {
return nil
Expand Down
4 changes: 2 additions & 2 deletions virtcontainers/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -1442,9 +1442,9 @@ func (s *Sandbox) createContainers() error {
return nil
}

// start starts a sandbox. The containers that are making the sandbox
// Start starts a sandbox. The containers that are making the sandbox
// will be started.
func (s *Sandbox) start() error {
func (s *Sandbox) Start() error {
if err := s.state.validTransition(s.state.State, StateRunning); err != nil {
return err
}
Expand Down
14 changes: 7 additions & 7 deletions virtcontainers/sandbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1345,7 +1345,7 @@ func TestStartContainer(t *testing.T) {
_, err = s.StartContainer(contID)
assert.NotNil(t, err, "Starting non-existing container should fail")

err = s.start()
err = s.Start()
assert.Nil(t, err, "Failed to start sandbox: %v", err)

contConfig := newTestContainerConfigNoop(contID)
Expand Down Expand Up @@ -1401,7 +1401,7 @@ func TestEnterContainer(t *testing.T) {
_, _, err = s.EnterContainer(contID, cmd)
assert.NotNil(t, err, "Entering non-running container should fail")

err = s.start()
err = s.Start()
assert.Nil(t, err, "Failed to start sandbox: %v", err)

_, _, err = s.EnterContainer(contID, cmd)
Expand All @@ -1416,7 +1416,7 @@ func TestMonitor(t *testing.T) {
_, err = s.Monitor()
assert.NotNil(t, err, "Monitoring non-running container should fail")

err = s.start()
err = s.Start()
assert.Nil(t, err, "Failed to start sandbox: %v", err)

_, err = s.Monitor()
Expand All @@ -1438,7 +1438,7 @@ func TestWaitProcess(t *testing.T) {
_, err = s.WaitProcess(contID, execID)
assert.NotNil(t, err, "Wait process in stopped sandbox should fail")

err = s.start()
err = s.Start()
assert.Nil(t, err, "Failed to start sandbox: %v", err)

_, err = s.WaitProcess(contID, execID)
Expand Down Expand Up @@ -1468,7 +1468,7 @@ func TestSignalProcess(t *testing.T) {
err = s.SignalProcess(contID, execID, syscall.SIGKILL, true)
assert.NotNil(t, err, "Wait process in stopped sandbox should fail")

err = s.start()
err = s.Start()
assert.Nil(t, err, "Failed to start sandbox: %v", err)

err = s.SignalProcess(contID, execID, syscall.SIGKILL, false)
Expand Down Expand Up @@ -1498,7 +1498,7 @@ func TestWinsizeProcess(t *testing.T) {
err = s.WinsizeProcess(contID, execID, 100, 200)
assert.NotNil(t, err, "Winsize process in stopped sandbox should fail")

err = s.start()
err = s.Start()
assert.Nil(t, err, "Failed to start sandbox: %v", err)

err = s.WinsizeProcess(contID, execID, 100, 200)
Expand Down Expand Up @@ -1528,7 +1528,7 @@ func TestContainerProcessIOStream(t *testing.T) {
_, _, _, err = s.IOStream(contID, execID)
assert.NotNil(t, err, "Winsize process in stopped sandbox should fail")

err = s.start()
err = s.Start()
assert.Nil(t, err, "Failed to start sandbox: %v", err)

_, _, _, err = s.IOStream(contID, execID)
Expand Down

0 comments on commit 6c3e266

Please sign in to comment.