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

Commit 51ac7fe

Browse files
committed
provision: add the rollback function for createsandbox failed
Signed-off-by: fupan <[email protected]>
1 parent 53bf002 commit 51ac7fe

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

daemon/pod/provision.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,22 @@ func CreateXPod(factory *PodFactory, spec *apitypes.UserPod) (*XPod, error) {
3434
p.releaseNames(spec.Containers)
3535
}
3636
}()
37-
err = p.createSandbox(spec) //TODO: add defer for rollback
38-
if err != nil {
39-
return nil, err
40-
}
4137

4238
defer func() {
4339
if err != nil && p.sandbox != nil {
40+
status := p.sandbox.Status()
41+
if status.State.State == vc.StateRunning {
42+
vc.StopSandbox(p.sandbox.ID())
43+
}
4444
p.sandbox.Delete()
4545
}
4646
}()
4747

48+
err = p.createSandbox(spec)
49+
if err != nil {
50+
return nil, err
51+
}
52+
4853
err = p.initResources(spec, true)
4954
if err != nil {
5055
return nil, err

0 commit comments

Comments
 (0)