mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-04 02:56:18 +00:00
virtcontainers: add rollback to remove sandbox network
If error occurs after sandbox network created successfully, we need to rollback to remove the created sandbox network Fixes: #297 Signed-off-by: flyflypeng <jiangpengfei9@huawei.com>
This commit is contained in:
parent
b244410443
commit
daebbd1e93
@ -39,6 +39,8 @@ func CreateSandbox(sandboxConfig SandboxConfig, factory Factory) (VCSandbox, err
|
|||||||
}
|
}
|
||||||
|
|
||||||
func createSandboxFromConfig(sandboxConfig SandboxConfig, factory Factory) (*Sandbox, error) {
|
func createSandboxFromConfig(sandboxConfig SandboxConfig, factory Factory) (*Sandbox, error) {
|
||||||
|
var err error
|
||||||
|
|
||||||
// Create the sandbox.
|
// Create the sandbox.
|
||||||
s, err := createSandbox(sandboxConfig, factory)
|
s, err := createSandbox(sandboxConfig, factory)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -46,22 +48,29 @@ func createSandboxFromConfig(sandboxConfig SandboxConfig, factory Factory) (*San
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create the sandbox network
|
// Create the sandbox network
|
||||||
if err := s.createNetwork(); err != nil {
|
if err = s.createNetwork(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// network rollback
|
||||||
|
defer func() {
|
||||||
|
if err != nil && s.networkNS.NetNsCreated {
|
||||||
|
s.removeNetwork()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
// Start the VM
|
// Start the VM
|
||||||
if err := s.startVM(); err != nil {
|
if err = s.startVM(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create Containers
|
// Create Containers
|
||||||
if err := s.createContainers(); err != nil {
|
if err = s.createContainers(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// The sandbox is completely created now, we can store it.
|
// The sandbox is completely created now, we can store it.
|
||||||
if err := s.storeSandbox(); err != nil {
|
if err = s.storeSandbox(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user