Update errdefs to 0.3.0

Uses the new github.com/containerd/errdefs/pkg module which is intended
to hold less stable utility functions separately from the stable
github.com/containerd/errdefs error types.

Includes temporary update to hcsshim until a release is cut there

Signed-off-by: Derek McGowan <derek@mcg.dev>
This commit is contained in:
Derek McGowan
2024-10-18 15:57:27 -07:00
parent b291eb802b
commit 2f24aa00a5
61 changed files with 2054 additions and 529 deletions

View File

@@ -23,6 +23,7 @@ import (
"time"
"github.com/containerd/errdefs"
"github.com/containerd/errdefs/pkg/errgrpc"
"github.com/containerd/log"
"github.com/containerd/plugin"
"github.com/containerd/plugin/registry"
@@ -31,6 +32,7 @@ import (
runtimeAPI "github.com/containerd/containerd/api/runtime/sandbox/v1"
"github.com/containerd/containerd/api/types"
"github.com/containerd/containerd/v2/core/events"
"github.com/containerd/containerd/v2/core/events/exchange"
"github.com/containerd/containerd/v2/core/mount"
@@ -158,7 +160,7 @@ func (c *controllerLocal) Create(ctx context.Context, info sandbox.Sandbox, opts
NetnsPath: coptions.NetNSPath,
}); err != nil {
c.cleanupShim(ctx, sandboxID, svc)
return fmt.Errorf("failed to create sandbox %s: %w", sandboxID, errdefs.FromGRPC(err))
return fmt.Errorf("failed to create sandbox %s: %w", sandboxID, errgrpc.ToNative(err))
}
return nil
@@ -178,7 +180,7 @@ func (c *controllerLocal) Start(ctx context.Context, sandboxID string) (sandbox.
resp, err := svc.StartSandbox(ctx, &runtimeAPI.StartSandboxRequest{SandboxID: sandboxID})
if err != nil {
c.cleanupShim(ctx, sandboxID, svc)
return sandbox.ControllerInstance{}, fmt.Errorf("failed to start sandbox %s: %w", sandboxID, errdefs.FromGRPC(err))
return sandbox.ControllerInstance{}, fmt.Errorf("failed to start sandbox %s: %w", sandboxID, errgrpc.ToNative(err))
}
address, version := shim.Endpoint()
return sandbox.ControllerInstance{
@@ -198,7 +200,7 @@ func (c *controllerLocal) Platform(ctx context.Context, sandboxID string) (image
response, err := svc.Platform(ctx, &runtimeAPI.PlatformRequest{SandboxID: sandboxID})
if err != nil {
return imagespec.Platform{}, fmt.Errorf("failed to get sandbox platform: %w", errdefs.FromGRPC(err))
return imagespec.Platform{}, fmt.Errorf("failed to get sandbox platform: %w", errgrpc.ToNative(err))
}
var platform imagespec.Platform
@@ -229,7 +231,7 @@ func (c *controllerLocal) Stop(ctx context.Context, sandboxID string, opts ...sa
}
if _, err := svc.StopSandbox(ctx, req); err != nil {
err = errdefs.FromGRPC(err)
err = errgrpc.ToNative(err)
if !errdefs.IsNotFound(err) && !errdefs.IsUnavailable(err) {
return fmt.Errorf("failed to stop sandbox: %w", err)
}
@@ -246,7 +248,7 @@ func (c *controllerLocal) Shutdown(ctx context.Context, sandboxID string) error
_, err = svc.ShutdownSandbox(ctx, &runtimeAPI.ShutdownSandboxRequest{SandboxID: sandboxID})
if err != nil {
return fmt.Errorf("failed to shutdown sandbox: %w", errdefs.FromGRPC(err))
return fmt.Errorf("failed to shutdown sandbox: %w", errgrpc.ToNative(err))
}
if err := c.shims.Delete(ctx, sandboxID); err != nil {
@@ -267,7 +269,7 @@ func (c *controllerLocal) Wait(ctx context.Context, sandboxID string) (sandbox.E
})
if err != nil {
return sandbox.ExitStatus{}, fmt.Errorf("failed to wait sandbox %s: %w", sandboxID, errdefs.FromGRPC(err))
return sandbox.ExitStatus{}, fmt.Errorf("failed to wait sandbox %s: %w", sandboxID, errgrpc.ToNative(err))
}
return sandbox.ExitStatus{