Merge pull request #8204 from dcantah/sandbox-create-cleanup

Sandbox: Delete shim+shutdown sandbox on create failure
This commit is contained in:
Fu Wei 2023-03-07 16:07:35 +08:00 committed by GitHub
commit b6c72a02ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -19,11 +19,13 @@ package sandbox
import ( import (
"context" "context"
"fmt" "fmt"
"time"
runtimeAPI "github.com/containerd/containerd/api/runtime/sandbox/v1" runtimeAPI "github.com/containerd/containerd/api/runtime/sandbox/v1"
"github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/events" "github.com/containerd/containerd/events"
"github.com/containerd/containerd/events/exchange" "github.com/containerd/containerd/events/exchange"
"github.com/containerd/containerd/log"
"github.com/containerd/containerd/platforms" "github.com/containerd/containerd/platforms"
"github.com/containerd/containerd/plugin" "github.com/containerd/containerd/plugin"
"github.com/containerd/containerd/runtime" "github.com/containerd/containerd/runtime"
@ -125,7 +127,22 @@ func (c *controllerLocal) Create(ctx context.Context, sandboxID string, opts ...
Rootfs: coptions.Rootfs, Rootfs: coptions.Rootfs,
Options: options, Options: options,
}); err != nil { }); err != nil {
// TODO: Delete sandbox shim here. // Let the shim exit, then we can clean up the bundle after.
if _, sErr := svc.ShutdownSandbox(ctx, &runtimeAPI.ShutdownSandboxRequest{
SandboxID: sandboxID,
}); sErr != nil {
log.G(ctx).WithError(sErr).WithField("sandboxID", sandboxID).
Error("failed to shutdown sandbox after failed create")
}
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
dErr := c.shims.Delete(ctx, sandboxID)
if dErr != nil {
log.G(ctx).WithError(dErr).WithField("sandboxID", sandboxID).
Error("failed to delete shim after failed sandbox create")
}
return fmt.Errorf("failed to create sandbox %s: %w", sandboxID, errdefs.FromGRPC(err)) return fmt.Errorf("failed to create sandbox %s: %w", sandboxID, errdefs.FromGRPC(err))
} }