feat: replace github.com/pkg/errors to errors
Signed-off-by: haoyun <yun.hao@daocloud.io> Co-authored-by: zounengren <zouyee1989@gmail.com>
This commit is contained in:
@@ -21,6 +21,7 @@ package server
|
||||
|
||||
import (
|
||||
gocontext "context"
|
||||
"fmt"
|
||||
|
||||
"github.com/containerd/containerd"
|
||||
"github.com/containerd/containerd/containers"
|
||||
@@ -28,7 +29,6 @@ import (
|
||||
"github.com/containerd/containerd/log"
|
||||
"github.com/containerd/typeurl"
|
||||
runtimespec "github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/pkg/errors"
|
||||
"golang.org/x/net/context"
|
||||
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
|
||||
|
||||
@@ -40,7 +40,7 @@ import (
|
||||
func (c *criService) UpdateContainerResources(ctx context.Context, r *runtime.UpdateContainerResourcesRequest) (retRes *runtime.UpdateContainerResourcesResponse, retErr error) {
|
||||
container, err := c.containerStore.Get(r.GetContainerId())
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find container")
|
||||
return nil, fmt.Errorf("failed to find container: %w", err)
|
||||
}
|
||||
// Update resources in status update transaction, so that:
|
||||
// 1) There won't be race condition with container start.
|
||||
@@ -48,7 +48,7 @@ func (c *criService) UpdateContainerResources(ctx context.Context, r *runtime.Up
|
||||
if err := container.Status.Update(func(status containerstore.Status) (containerstore.Status, error) {
|
||||
return status, c.updateContainerResources(ctx, container, r, status)
|
||||
}); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to update resources")
|
||||
return nil, fmt.Errorf("failed to update resources: %w", err)
|
||||
}
|
||||
return &runtime.UpdateContainerResourcesResponse{}, nil
|
||||
}
|
||||
@@ -60,7 +60,7 @@ func (c *criService) updateContainerResources(ctx context.Context,
|
||||
id := cntr.ID
|
||||
// Do not update the container when there is a removal in progress.
|
||||
if status.Removing {
|
||||
return errors.Errorf("container %q is in removing state", id)
|
||||
return fmt.Errorf("container %q is in removing state", id)
|
||||
}
|
||||
|
||||
// Update container spec. If the container is not started yet, updating
|
||||
@@ -69,11 +69,11 @@ func (c *criService) updateContainerResources(ctx context.Context,
|
||||
// the spec will become our source of truth for resource limits.
|
||||
oldSpec, err := cntr.Container.Spec(ctx)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to get container spec")
|
||||
return fmt.Errorf("failed to get container spec: %w", err)
|
||||
}
|
||||
newSpec, err := updateOCIResource(ctx, oldSpec, r, c.config)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to update resource in spec")
|
||||
return fmt.Errorf("failed to update resource in spec: %w", err)
|
||||
}
|
||||
|
||||
if err := updateContainerSpec(ctx, cntr.Container, newSpec); err != nil {
|
||||
@@ -102,7 +102,7 @@ func (c *criService) updateContainerResources(ctx context.Context,
|
||||
// Task exited already.
|
||||
return nil
|
||||
}
|
||||
return errors.Wrap(err, "failed to get task")
|
||||
return fmt.Errorf("failed to get task: %w", err)
|
||||
}
|
||||
// newSpec.Linux / newSpec.Windows won't be nil
|
||||
if err := task.Update(ctx, containerd.WithResources(getResources(newSpec))); err != nil {
|
||||
@@ -110,7 +110,7 @@ func (c *criService) updateContainerResources(ctx context.Context,
|
||||
// Task exited already.
|
||||
return nil
|
||||
}
|
||||
return errors.Wrap(err, "failed to update resources")
|
||||
return fmt.Errorf("failed to update resources: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -119,13 +119,13 @@ func (c *criService) updateContainerResources(ctx context.Context,
|
||||
func updateContainerSpec(ctx context.Context, cntr containerd.Container, spec *runtimespec.Spec) error {
|
||||
any, err := typeurl.MarshalAny(spec)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to marshal spec %+v", spec)
|
||||
return fmt.Errorf("failed to marshal spec %+v: %w", spec, err)
|
||||
}
|
||||
if err := cntr.Update(ctx, func(ctx gocontext.Context, client *containerd.Client, c *containers.Container) error {
|
||||
c.Spec = any
|
||||
return nil
|
||||
}); err != nil {
|
||||
return errors.Wrap(err, "failed to update container spec")
|
||||
return fmt.Errorf("failed to update container spec: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user