Skip to content

Commit 02298e1

Browse files
ningmingxiaok8s-infra-cherrypick-robot
authored andcommitted
cri:fix containerd panic when can't find sandbox extension
Signed-off-by: ningmingxiao <ning.mingxiao@zte.com.cn>
1 parent a4771a8 commit 02298e1

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

internal/cri/server/restart.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package server
1818

1919
import (
2020
"context"
21+
"errors"
2122
"fmt"
2223
"os"
2324
"path/filepath"
@@ -106,6 +107,16 @@ func (c *criService) recover(ctx context.Context) error {
106107
metadata := sandboxstore.Metadata{}
107108
err := sbx.GetExtension(podsandbox.MetadataKey, &metadata)
108109
if err != nil {
110+
if errors.Is(err, errdefs.ErrNotFound) {
111+
log.G(ctx).WithError(err).Errorf("failed to get metadata for stored sandbox %q", sbx.ID)
112+
// Since commit https://github.com/containerd/containerd/pull/11612 has been merged metadata may not be nil.
113+
// Before 1162 we should delete leaked sandbox from sandbox store to make sure containerd can start successfully.
114+
err = c.client.SandboxStore().Delete(ctx, sbx.ID)
115+
if err != nil {
116+
log.G(ctx).WithError(err).Errorf("failed to delete sandbox %q, in response to failure to retrieve metadata for sandbox", sbx.ID)
117+
}
118+
continue
119+
}
109120
return fmt.Errorf("failed to get metadata for stored sandbox %q: %w", sbx.ID, err)
110121
}
111122

0 commit comments

Comments
 (0)