sandbox: fix recover status set issue

We can't set the status to Ready before task.Wait succeed.

Signed-off-by: Abel Feng <fshb1988@gmail.com>
This commit is contained in:
Abel Feng 2024-01-16 15:47:30 +08:00
parent 96bf529cbf
commit 3124964743

View File

@ -96,13 +96,17 @@ func (c *Controller) RecoverContainer(ctx context.Context, cntr containerd.Conta
status.State = sandboxstore.StateNotReady status.State = sandboxstore.StateNotReady
} else { } else {
if taskStatus.Status == containerd.Running { if taskStatus.Status == containerd.Running {
status.State = sandboxstore.StateReady
status.Pid = t.Pid()
exitCh, err := t.Wait(ctrdutil.NamespacedContext()) exitCh, err := t.Wait(ctrdutil.NamespacedContext())
if err != nil { if err != nil {
return status, channel, fmt.Errorf("failed to wait for sandbox container task: %w", err) if !errdefs.IsNotFound(err) {
return status, channel, fmt.Errorf("failed to wait for sandbox container task: %w", err)
}
status.State = sandboxstore.StateNotReady
} else {
status.State = sandboxstore.StateReady
status.Pid = t.Pid()
channel = exitCh
} }
channel = exitCh
} else { } else {
// Task is not running. Delete the task and set sandbox state as NOTREADY. // Task is not running. Delete the task and set sandbox state as NOTREADY.
if _, err := t.Delete(ctx, containerd.WithProcessKill); err != nil && !errdefs.IsNotFound(err) { if _, err := t.Delete(ctx, containerd.WithProcessKill); err != nil && !errdefs.IsNotFound(err) {