mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-06 03:56:34 +00:00
Merge pull request #1012 from sameo/topic/sandbox-simplification
First createSandboxFromConfig simplification
This commit is contained in:
commit
87570b78eb
@ -105,21 +105,7 @@ func createSandboxFromConfig(ctx context.Context, sandboxConfig SandboxConfig, f
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// Once startVM is done, we want to guarantee
|
if err := s.getAndStoreGuestDetails(); err != nil {
|
||||||
// that the sandbox is manageable. For that we need
|
|
||||||
// to start the sandbox inside the VM.
|
|
||||||
if err = s.agent.startSandbox(s); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// rollback to stop sandbox in VM
|
|
||||||
defer func() {
|
|
||||||
if err != nil {
|
|
||||||
s.agent.stopSandbox(s)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
if err = s.getAndStoreGuestDetails(); err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -234,12 +220,8 @@ func StartSandbox(ctx context.Context, sandboxID string) (VCSandbox, error) {
|
|||||||
}
|
}
|
||||||
defer s.releaseStatelessSandbox()
|
defer s.releaseStatelessSandbox()
|
||||||
|
|
||||||
return startSandbox(s)
|
|
||||||
}
|
|
||||||
|
|
||||||
func startSandbox(s *Sandbox) (*Sandbox, error) {
|
|
||||||
// Start it
|
// Start it
|
||||||
err := s.Start()
|
err = s.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -285,6 +267,7 @@ func RunSandbox(ctx context.Context, sandboxConfig SandboxConfig, factory Factor
|
|||||||
span, ctx := trace(ctx, "RunSandbox")
|
span, ctx := trace(ctx, "RunSandbox")
|
||||||
defer span.Finish()
|
defer span.Finish()
|
||||||
|
|
||||||
|
// Create the sandbox
|
||||||
s, err := createSandboxFromConfig(ctx, sandboxConfig, factory)
|
s, err := createSandboxFromConfig(ctx, sandboxConfig, factory)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -297,7 +280,13 @@ func RunSandbox(ctx context.Context, sandboxConfig SandboxConfig, factory Factor
|
|||||||
}
|
}
|
||||||
defer unlockSandbox(lockFile)
|
defer unlockSandbox(lockFile)
|
||||||
|
|
||||||
return startSandbox(s)
|
// Start the sandbox
|
||||||
|
err = s.Start()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return s, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListSandbox is the virtcontainers sandbox listing entry point.
|
// ListSandbox is the virtcontainers sandbox listing entry point.
|
||||||
|
@ -1234,9 +1234,18 @@ func (s *Sandbox) startVM() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store the network
|
|
||||||
s.Logger().Info("VM started")
|
s.Logger().Info("VM started")
|
||||||
|
|
||||||
|
// Once the hypervisor is done starting the sandbox,
|
||||||
|
// we want to guarantee that it is manageable.
|
||||||
|
// For that we need to ask the agent to start the
|
||||||
|
// sandbox inside the VM.
|
||||||
|
if err := s.agent.startSandbox(s); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
s.Logger().Info("Agent started in the sandbox")
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1245,6 +1254,12 @@ func (s *Sandbox) stopVM() error {
|
|||||||
span, _ := s.trace("stopVM")
|
span, _ := s.trace("stopVM")
|
||||||
defer span.Finish()
|
defer span.Finish()
|
||||||
|
|
||||||
|
s.Logger().Info("Stopping sandbox in the VM")
|
||||||
|
if err := s.agent.stopSandbox(s); err != nil {
|
||||||
|
s.Logger().WithError(err).WithField("sandboxid", s.id).Warning("Agent did not stop sandbox")
|
||||||
|
}
|
||||||
|
|
||||||
|
s.Logger().Info("Stopping VM")
|
||||||
return s.hypervisor.stopSandbox()
|
return s.hypervisor.stopSandbox()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1579,12 +1594,7 @@ func (s *Sandbox) Stop() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := s.agent.stopSandbox(s); err != nil {
|
if err := s.stopVM(); err != nil {
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
s.Logger().Info("Stopping VM")
|
|
||||||
if err := s.hypervisor.stopSandbox(); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user