Skip to content

Commit 351a512

Browse files
committed
fix container can't be started when task status is created
Signed-off-by: ningmingxiao <ning.mingxiao@zte.com.cn>
1 parent 89ecd85 commit 351a512

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

pkg/containerutil/containerutil.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,25 @@ func Start(ctx context.Context, container containerd.Container, isAttach bool, i
258258
}
259259

260260
if oldTask, err := container.Task(ctx, nil); err == nil {
261+
if status, err := oldTask.Status(ctx); err == nil {
262+
if status.Status == containerd.Created {
263+
sig, err := signal.ParseSignal("SIGKILL")
264+
if err != nil {
265+
return err
266+
}
267+
err = oldTask.Kill(ctx, sig)
268+
if err != nil {
269+
return err
270+
}
271+
statusC, err := oldTask.Wait(ctx)
272+
if err != nil {
273+
return err
274+
}
275+
<-statusC
276+
}
277+
}
261278
if _, err := oldTask.Delete(ctx); err != nil {
262-
log.G(ctx).WithError(err).Debug("failed to delete old task")
279+
log.G(ctx).WithError(err).Error("failed to delete old task")
263280
}
264281
}
265282
detachC := make(chan struct{})

0 commit comments

Comments
 (0)