Skip to content

Commit 24cec9b

Browse files
committed
sandbox: Allows the sandbox to be deleted in NotReady state
The Pod Sandbox can enter in a NotReady state if the task associated with it no longer exists (it died, or it was killed). In this state, the Pod network namespace could still be open, which means we can't remove the sandbox, even if --force was used. Signed-off-by: Claudiu Belu <[email protected]>
1 parent 61a46e9 commit 24cec9b

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

pkg/cri/server/sandbox_remove.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
2727

2828
"github.com/containerd/containerd/pkg/cri/store"
29-
sandboxstore "github.com/containerd/containerd/pkg/cri/store/sandbox"
3029
)
3130

3231
// RemovePodSandbox removes the sandbox. If there are running containers in the
@@ -46,13 +45,12 @@ func (c *criService) RemovePodSandbox(ctx context.Context, r *runtime.RemovePodS
4645
// Use the full sandbox id.
4746
id := sandbox.ID
4847

49-
// If the sandbox is still running or in an unknown state, forcibly stop it.
50-
state := sandbox.Status.Get().State
51-
if state == sandboxstore.StateReady || state == sandboxstore.StateUnknown {
52-
logrus.Infof("Forcibly stopping sandbox %q", id)
53-
if err := c.stopPodSandbox(ctx, sandbox); err != nil {
54-
return nil, errors.Wrapf(err, "failed to forcibly stop sandbox %q", id)
55-
}
48+
// If the sandbox is still running, not ready, or in an unknown state, forcibly stop it.
49+
// Even if it's in a NotReady state, this will close its network namespace, if open.
50+
// This can happen if the task process associated with the Pod died or it was killed.
51+
logrus.Infof("Forcibly stopping sandbox %q", id)
52+
if err := c.stopPodSandbox(ctx, sandbox); err != nil {
53+
return nil, errors.Wrapf(err, "failed to forcibly stop sandbox %q", id)
5654
}
5755

5856
// Return error if sandbox network namespace is not closed yet.

0 commit comments

Comments
 (0)