Add a new control message for destroying sandbox in multi-container mode.

- Adds SandboxShutdown() control message to destroy sandbox manually.
- Adds a new gVisor API for destroying the sandbox in multi container mode.
- Test to verify the API and the control message works correctly.

PiperOrigin-RevId: 459290099
This commit is contained in:
Nayana Bidari
2022-07-06 10:48:29 -07:00
committed by gVisor bot
parent 84e56e8b50
commit 5b70da9525
+10 -15
View File
@@ -35,16 +35,13 @@ type Lifecycle struct {
// Kernel is the kernel where the tasks belong to.
Kernel *kernel.Kernel
// StartedCh is the channel used to send a message to the sentry that
// all the containers in the sandbox have been started.
StartedCh chan struct{}
// ShutdownCh is the channel used to signal the sentry to shutdown
// the sentry/sandbox.
ShutdownCh chan struct{}
// mu protects the fields below.
mu sync.RWMutex
// containersStarted is the number of containers started in the sandbox.
containersStarted int32
// MountNamespacesMap is a map of container id/names and the mount
// namespaces.
MountNamespacesMap map[string]*vfs.MountNamespace
@@ -171,17 +168,9 @@ func (l *Lifecycle) StartContainer(args *StartContainerArgs, _ *uint32) error {
return err
}
l.mu.Lock()
numContainers := int32(len(l.MountNamespacesMap))
// Start the newly created process.
l.Kernel.StartProcess(tg)
log.Infof("Started the new container %v ", l.containersStarted)
l.containersStarted++
if numContainers == l.containersStarted {
l.StartedCh <- struct{}{}
}
l.mu.Unlock()
log.Infof("Started the new container %v ", initArgs.ContainerID)
return nil
}
@@ -196,3 +185,9 @@ func (l *Lifecycle) Resume(_, _ *struct{}) error {
l.Kernel.Unpause()
return nil
}
// Shutdown sends signal to destroy the sentry/sandbox.
func (l *Lifecycle) Shutdown(_, _ *struct{}) error {
close(l.ShutdownCh)
return nil
}