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

Commit

Permalink
virtcontainers: add rollback to remove sandbox network
Browse files Browse the repository at this point in the history
If error occurs after sandbox network created successfully, we need to rollback
to remove the created sandbox network

Fixes: #297

Signed-off-by: flyflypeng <[email protected]>
Signed-off-by: Eric Ernst <[email protected]>
  • Loading branch information
flyflypeng authored and Eric Ernst committed Aug 23, 2018
1 parent 85b1627 commit 3bbcdbc
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions virtcontainers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,28 @@ func CreateSandbox(sandboxConfig SandboxConfig) (VCSandbox, error) {
}

func createSandboxFromConfig(sandboxConfig SandboxConfig) (*Sandbox, error) {
var err error

// Create the sandbox.
s, err := createSandbox(sandboxConfig)
if err != nil {
return nil, err
}

// Create the sandbox network
if err := s.createNetwork(); err != nil {
if err = s.createNetwork(); err != nil {
return nil, err
}

// network rollback
defer func() {
if err != nil && s.networkNS.NetNsCreated {
s.removeNetwork()
}
}()

// Start the VM
if err := s.startVM(); err != nil {
if err = s.startVM(); err != nil {
return nil, err
}

Expand All @@ -77,12 +86,12 @@ func createSandboxFromConfig(sandboxConfig SandboxConfig) (*Sandbox, error) {
}()

// Create Containers
if err := s.createContainers(); err != nil {
if err = s.createContainers(); err != nil {
return nil, err
}

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

Expand Down

0 comments on commit 3bbcdbc

Please sign in to comment.