cri:fix containerd panic when can't find sandbox extension

Signed-off-by: ningmingxiao <ning.mingxiao@zte.com.cn>
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
This commit is contained in:
ningmingxiao 2025-03-20 09:44:11 +08:00 committed by Brad Davidson
parent 1a43cb6a10
commit 2879c0790c
No known key found for this signature in database
GPG Key ID: FFB7A9376A9349B9

View File

@ -18,6 +18,7 @@ package server
import (
"context"
"errors"
"fmt"
"os"
"path/filepath"
@ -107,6 +108,14 @@ func (c *criService) recover(ctx context.Context) error {
metadata := sandboxstore.Metadata{}
err := sbx.GetExtension(podsandbox.MetadataKey, &metadata)
if err != nil {
if errors.Is(err, errdefs.ErrNotFound) {
err = c.client.SandboxStore().Delete(ctx, sbx.ID)
if err != nil {
return fmt.Errorf("failed to delete sandbox in response to missing metadata for sandbox %q: %w", sbx.ID, err)
}
// TODO: cleanup network namespace
continue
}
return fmt.Errorf("failed to get metadata for stored sandbox %q: %w", sbx.ID, err)
}