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

Commit d3ca391

Browse files
committed
pod: rollback the opertions once starting sandbox failed
Signed-off-by: fupan <lifupan@gmail.com>
1 parent 54c75d8 commit d3ca391

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

daemon/pod/provision.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,28 +222,39 @@ func (p *XPod) ContainerStart(cid string) error {
222222

223223
// Start() means start a STOPPED pod.
224224
func (p *XPod) Start() error {
225+
var err error
226+
227+
defer func() {
228+
if err != nil && p.sandbox != nil {
229+
status := p.sandbox.Status()
230+
if status.State.State == vc.StateRunning {
231+
vc.StopSandbox(p.sandbox.ID())
232+
vc.DeleteSandbox(p.sandbox.ID())
233+
}
234+
}
235+
}()
225236

226237
if p.IsStopped() {
227-
if err := p.createSandbox(p.globalSpec); err != nil {
238+
if err = p.createSandbox(p.globalSpec); err != nil {
228239
p.Log(ERROR, "failed to create sandbox for the stopped pod: %v", err)
229240
return err
230241
}
231242

232-
if err := p.prepareResources(); err != nil {
243+
if err = p.prepareResources(); err != nil {
233244
return err
234245
}
235246

236-
if err := p.addResourcesToSandbox(); err != nil {
247+
if err = p.addResourcesToSandbox(); err != nil {
237248
return err
238249
}
239250
}
240251

241-
err := p.waitPodRun("start pod")
252+
err = p.waitPodRun("start pod")
242253
if err != nil {
243254
p.Log(ERROR, "wait running failed, cannot start pod")
244255
return err
245256
}
246-
if err := p.startAll(); err != nil {
257+
if err = p.startAll(); err != nil {
247258
return err
248259
}
249260

0 commit comments

Comments
 (0)