sandbox: Export Start() 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 StartSandbox(),
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 13:32:55 -08:00
parent 4cddfc63d8
commit 6c3e266eb9
5 changed files with 16 additions and 10 deletions

View File

@ -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
}

View File

@ -66,6 +66,7 @@ type VCSandbox interface {
ID() string
SetAnnotations(annotations map[string]string) error
Start() error
Pause() error
Resume() error
Release() error

View File

@ -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

View File

@ -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
}

View File

@ -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)
@ -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)
@ -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()
@ -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)
@ -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)
@ -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)
@ -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)