@@ -22,6 +22,7 @@ import (
22
22
"time"
23
23
24
24
sandboxstore "github.com/containerd/containerd/pkg/cri/store/sandbox"
25
+ "github.com/containerd/errdefs"
25
26
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
26
27
)
27
28
@@ -42,12 +43,32 @@ func (c *criService) PodSandboxStatus(ctx context.Context, r *runtime.PodSandbox
42
43
return nil , fmt .Errorf ("failed to get sandbox controller: %w" , err )
43
44
}
44
45
46
+ var (
47
+ createdAt time.Time
48
+ state string
49
+ info map [string ]string
50
+ )
45
51
cstatus , err := controller .Status (ctx , sandbox .ID , r .GetVerbose ())
46
52
if err != nil {
47
- return nil , fmt .Errorf ("failed to query controller status: %w" , err )
53
+ // If the shim died unexpectedly (segfault etc.) let's set the state as
54
+ // NOTREADY and not just error out to make k8s and clients like crictl
55
+ // happy. If we get back ErrNotFound from controller.Status above while
56
+ // we're using the shim-mode controller, this is a decent indicator it
57
+ // exited unexpectedly. We can use the fact that we successfully retrieved
58
+ // the sandbox object from the store above to tell that this is true, otherwise
59
+ // if we followed the normal k8s convention of StopPodSandbox -> RemovePodSandbox,
60
+ // we wouldn't have that object in the store anymore.
61
+ if ! errdefs .IsNotFound (err ) {
62
+ return nil , fmt .Errorf ("failed to query controller status: %w" , err )
63
+ }
64
+ state = runtime .PodSandboxState_SANDBOX_NOTREADY .String ()
65
+ } else {
66
+ state = cstatus .State
67
+ createdAt = cstatus .CreatedAt
68
+ info = cstatus .Info
48
69
}
49
70
50
- status := toCRISandboxStatus (sandbox .Metadata , cstatus . State , cstatus . CreatedAt , ip , additionalIPs )
71
+ status := toCRISandboxStatus (sandbox .Metadata , state , createdAt , ip , additionalIPs )
51
72
if status .GetCreatedAt () == 0 {
52
73
// CRI doesn't allow CreatedAt == 0.
53
74
sandboxInfo , err := c .client .SandboxStore ().Get (ctx , sandbox .ID )
@@ -59,7 +80,7 @@ func (c *criService) PodSandboxStatus(ctx context.Context, r *runtime.PodSandbox
59
80
60
81
return & runtime.PodSandboxStatusResponse {
61
82
Status : status ,
62
- Info : cstatus . Info ,
83
+ Info : info ,
63
84
}, nil
64
85
}
65
86
0 commit comments