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

Commit

Permalink
provision: add the rollback function for createsandbox failed
Browse files Browse the repository at this point in the history
Signed-off-by: fupan <[email protected]>
  • Loading branch information
lifupan committed Jul 11, 2018
1 parent 53bf002 commit 51ac7fe
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions daemon/pod/provision.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,22 @@ func CreateXPod(factory *PodFactory, spec *apitypes.UserPod) (*XPod, error) {
p.releaseNames(spec.Containers)
}
}()
err = p.createSandbox(spec) //TODO: add defer for rollback
if err != nil {
return nil, err
}

defer func() {
if err != nil && p.sandbox != nil {
status := p.sandbox.Status()
if status.State.State == vc.StateRunning {
vc.StopSandbox(p.sandbox.ID())
}
p.sandbox.Delete()
}
}()

err = p.createSandbox(spec)
if err != nil {
return nil, err
}

err = p.initResources(spec, true)
if err != nil {
return nil, err
Expand Down

0 comments on commit 51ac7fe

Please sign in to comment.