sandbox: replace github.com/pkg/errors with native errors
PR #6366 implemented a tree-wide change to replace github.com/pkg/errors to errors. The new sandbox API PR #6703 had few errors.Wrap*() leftovers and pulled github.com/pkg/errors back. This commit replaces those leftovers by following the pattern in #6366. Signed-off-by: Mikko Ylinen <mikko.ylinen@intel.com>
This commit is contained in:
parent
e85b5a0b81
commit
523d069a25
2
go.mod
2
go.mod
@ -46,7 +46,6 @@ require (
|
|||||||
github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417
|
github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417
|
||||||
github.com/opencontainers/selinux v1.10.1
|
github.com/opencontainers/selinux v1.10.1
|
||||||
github.com/pelletier/go-toml v1.9.3
|
github.com/pelletier/go-toml v1.9.3
|
||||||
github.com/pkg/errors v0.9.1
|
|
||||||
github.com/prometheus/client_golang v1.12.1
|
github.com/prometheus/client_golang v1.12.1
|
||||||
github.com/sirupsen/logrus v1.8.1
|
github.com/sirupsen/logrus v1.8.1
|
||||||
github.com/stretchr/testify v1.7.0
|
github.com/stretchr/testify v1.7.0
|
||||||
@ -104,6 +103,7 @@ require (
|
|||||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||||
github.com/opencontainers/runtime-tools v0.0.0-20190417131837-cd1349b7c47e // indirect
|
github.com/opencontainers/runtime-tools v0.0.0-20190417131837-cd1349b7c47e // indirect
|
||||||
|
github.com/pkg/errors v0.9.1 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
github.com/prometheus/client_model v0.2.0 // indirect
|
github.com/prometheus/client_model v0.2.0 // indirect
|
||||||
github.com/prometheus/common v0.32.1 // indirect
|
github.com/prometheus/common v0.32.1 // indirect
|
||||||
|
@ -18,6 +18,7 @@ package metadata
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -29,7 +30,6 @@ import (
|
|||||||
"github.com/containerd/containerd/namespaces"
|
"github.com/containerd/containerd/namespaces"
|
||||||
api "github.com/containerd/containerd/sandbox"
|
api "github.com/containerd/containerd/sandbox"
|
||||||
"github.com/containerd/typeurl"
|
"github.com/containerd/typeurl"
|
||||||
"github.com/pkg/errors"
|
|
||||||
"go.etcd.io/bbolt"
|
"go.etcd.io/bbolt"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ func (s *sandboxStore) Create(ctx context.Context, sandbox api.Sandbox) (api.San
|
|||||||
sandbox.UpdatedAt = sandbox.CreatedAt
|
sandbox.UpdatedAt = sandbox.CreatedAt
|
||||||
|
|
||||||
if err := s.validate(&sandbox); err != nil {
|
if err := s.validate(&sandbox); err != nil {
|
||||||
return api.Sandbox{}, errors.Wrap(err, "failed to validate sandbox")
|
return api.Sandbox{}, fmt.Errorf("failed to validate sandbox: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := s.db.Update(func(tx *bbolt.Tx) error {
|
if err := s.db.Update(func(tx *bbolt.Tx) error {
|
||||||
@ -87,7 +87,7 @@ func (s *sandboxStore) Update(ctx context.Context, sandbox api.Sandbox, fieldpat
|
|||||||
if err := update(ctx, s.db, func(tx *bbolt.Tx) error {
|
if err := update(ctx, s.db, func(tx *bbolt.Tx) error {
|
||||||
parent := getSandboxBucket(tx, ns)
|
parent := getSandboxBucket(tx, ns)
|
||||||
if parent == nil {
|
if parent == nil {
|
||||||
return errors.Wrap(errdefs.ErrNotFound, "no sandbox buckets")
|
return fmt.Errorf("no sandbox buckets: %w", errdefs.ErrNotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
updated, err := s.read(parent, []byte(sandbox.ID))
|
updated, err := s.read(parent, []byte(sandbox.ID))
|
||||||
@ -99,7 +99,7 @@ func (s *sandboxStore) Update(ctx context.Context, sandbox api.Sandbox, fieldpat
|
|||||||
fieldpaths = []string{"labels", "extensions", "spec", "runtime"}
|
fieldpaths = []string{"labels", "extensions", "spec", "runtime"}
|
||||||
|
|
||||||
if updated.Runtime.Name != sandbox.Runtime.Name {
|
if updated.Runtime.Name != sandbox.Runtime.Name {
|
||||||
return errors.Wrapf(errdefs.ErrInvalidArgument, "sandbox.Runtime.Name field is immutable")
|
return fmt.Errorf("sandbox.Runtime.Name field is immutable: %w", errdefs.ErrInvalidArgument)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,7 +132,7 @@ func (s *sandboxStore) Update(ctx context.Context, sandbox api.Sandbox, fieldpat
|
|||||||
case "spec":
|
case "spec":
|
||||||
updated.Spec = sandbox.Spec
|
updated.Spec = sandbox.Spec
|
||||||
default:
|
default:
|
||||||
return errors.Wrapf(errdefs.ErrInvalidArgument, "cannot update %q field on sandbox %q", path, sandbox.ID)
|
return fmt.Errorf("cannot update %q field on sandbox %q: %w", path, sandbox.ID, errdefs.ErrInvalidArgument)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,7 +166,7 @@ func (s *sandboxStore) Get(ctx context.Context, id string) (api.Sandbox, error)
|
|||||||
if err := view(ctx, s.db, func(tx *bbolt.Tx) error {
|
if err := view(ctx, s.db, func(tx *bbolt.Tx) error {
|
||||||
bucket := getSandboxBucket(tx, ns)
|
bucket := getSandboxBucket(tx, ns)
|
||||||
if bucket == nil {
|
if bucket == nil {
|
||||||
return errors.Wrap(errdefs.ErrNotFound, "no sandbox buckets")
|
return fmt.Errorf("no sandbox buckets: %w", errdefs.ErrNotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
out, err := s.read(bucket, []byte(id))
|
out, err := s.read(bucket, []byte(id))
|
||||||
@ -192,7 +192,7 @@ func (s *sandboxStore) List(ctx context.Context, fields ...string) ([]api.Sandbo
|
|||||||
|
|
||||||
filter, err := filters.ParseAll(fields...)
|
filter, err := filters.ParseAll(fields...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(errdefs.ErrInvalidArgument, err.Error())
|
return nil, fmt.Errorf("%s: %w", err.Error(), errdefs.ErrInvalidArgument)
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -209,7 +209,7 @@ func (s *sandboxStore) List(ctx context.Context, fields ...string) ([]api.Sandbo
|
|||||||
if err := bucket.ForEach(func(k, v []byte) error {
|
if err := bucket.ForEach(func(k, v []byte) error {
|
||||||
info, err := s.read(bucket, k)
|
info, err := s.read(bucket, k)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "failed to read bucket %q", string(k))
|
return fmt.Errorf("failed to read bucket %q: %w", string(k), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if filter.Match(adaptSandbox(&info)) {
|
if filter.Match(adaptSandbox(&info)) {
|
||||||
@ -239,11 +239,11 @@ func (s *sandboxStore) Delete(ctx context.Context, id string) error {
|
|||||||
if err := update(ctx, s.db, func(tx *bbolt.Tx) error {
|
if err := update(ctx, s.db, func(tx *bbolt.Tx) error {
|
||||||
buckets := getSandboxBucket(tx, ns)
|
buckets := getSandboxBucket(tx, ns)
|
||||||
if buckets == nil {
|
if buckets == nil {
|
||||||
return errors.Wrap(errdefs.ErrNotFound, "no sandbox buckets")
|
return fmt.Errorf("no sandbox buckets: %w", errdefs.ErrNotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := buckets.DeleteBucket([]byte(id)); err != nil {
|
if err := buckets.DeleteBucket([]byte(id)); err != nil {
|
||||||
return errors.Wrapf(err, "failed to delete sandbox %q", id)
|
return fmt.Errorf("failed to delete sandbox %q: %w", id, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -269,7 +269,7 @@ func (s *sandboxStore) write(parent *bbolt.Bucket, instance *api.Sandbox, overwr
|
|||||||
} else {
|
} else {
|
||||||
bucket = parent.Bucket(id)
|
bucket = parent.Bucket(id)
|
||||||
if bucket != nil {
|
if bucket != nil {
|
||||||
return errors.Wrapf(errdefs.ErrAlreadyExists, "sandbox bucket %q already exists", instance.ID)
|
return fmt.Errorf("sandbox bucket %q already exists: %w", instance.ID, errdefs.ErrAlreadyExists)
|
||||||
}
|
}
|
||||||
|
|
||||||
bucket, err = parent.CreateBucket(id)
|
bucket, err = parent.CreateBucket(id)
|
||||||
@ -318,7 +318,7 @@ func (s *sandboxStore) read(parent *bbolt.Bucket, id []byte) (api.Sandbox, error
|
|||||||
|
|
||||||
bucket := parent.Bucket(id)
|
bucket := parent.Bucket(id)
|
||||||
if bucket == nil {
|
if bucket == nil {
|
||||||
return api.Sandbox{}, errors.Wrapf(errdefs.ErrNotFound, "bucket %q not found", id)
|
return api.Sandbox{}, fmt.Errorf("bucket %q not found: %w", id, errdefs.ErrNotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
inst.ID = string(id)
|
inst.ID = string(id)
|
||||||
@ -358,19 +358,19 @@ func (s *sandboxStore) read(parent *bbolt.Bucket, id []byte) (api.Sandbox, error
|
|||||||
|
|
||||||
func (s *sandboxStore) validate(new *api.Sandbox) error {
|
func (s *sandboxStore) validate(new *api.Sandbox) error {
|
||||||
if err := identifiers.Validate(new.ID); err != nil {
|
if err := identifiers.Validate(new.ID); err != nil {
|
||||||
return errors.Wrap(err, "invalid sandbox ID")
|
return fmt.Errorf("invalid sandbox ID: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if new.CreatedAt.IsZero() {
|
if new.CreatedAt.IsZero() {
|
||||||
return errors.Wrap(errdefs.ErrInvalidArgument, "creation date must not be zero")
|
return fmt.Errorf("creation date must not be zero: %w", errdefs.ErrInvalidArgument)
|
||||||
}
|
}
|
||||||
|
|
||||||
if new.UpdatedAt.IsZero() {
|
if new.UpdatedAt.IsZero() {
|
||||||
return errors.Wrap(errdefs.ErrInvalidArgument, "updated date must not be zero")
|
return fmt.Errorf("updated date must not be zero: %w", errdefs.ErrInvalidArgument)
|
||||||
}
|
}
|
||||||
|
|
||||||
if new.Runtime.Name == "" {
|
if new.Runtime.Name == "" {
|
||||||
return errors.Wrapf(errdefs.ErrInvalidArgument, "sandbox.Runtime.Name must be set")
|
return fmt.Errorf("sandbox.Runtime.Name must be set: %w", errdefs.ErrInvalidArgument)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -18,6 +18,7 @@ package containerd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -27,7 +28,6 @@ import (
|
|||||||
"github.com/containerd/containerd/protobuf/types"
|
"github.com/containerd/containerd/protobuf/types"
|
||||||
api "github.com/containerd/containerd/sandbox"
|
api "github.com/containerd/containerd/sandbox"
|
||||||
"github.com/containerd/typeurl"
|
"github.com/containerd/typeurl"
|
||||||
"github.com/pkg/errors"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Sandbox is a high level client to containerd's sandboxes.
|
// Sandbox is a high level client to containerd's sandboxes.
|
||||||
@ -183,7 +183,7 @@ func WithSandboxRuntime(name string, options interface{}) NewSandboxOpts {
|
|||||||
|
|
||||||
opts, err := typeurl.MarshalAny(options)
|
opts, err := typeurl.MarshalAny(options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to marshal sandbox runtime options")
|
return fmt.Errorf("failed to marshal sandbox runtime options: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
s.Runtime = api.RuntimeOpts{
|
s.Runtime = api.RuntimeOpts{
|
||||||
@ -206,7 +206,7 @@ func WithSandboxSpec(s *oci.Spec, opts ...oci.SpecOpts) NewSandboxOpts {
|
|||||||
|
|
||||||
spec, err := typeurl.MarshalAny(s)
|
spec, err := typeurl.MarshalAny(s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to marshal spec")
|
return fmt.Errorf("failed to marshal spec: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
sandbox.Spec = spec
|
sandbox.Spec = spec
|
||||||
@ -223,7 +223,7 @@ func WithSandboxExtension(name string, ext interface{}) NewSandboxOpts {
|
|||||||
|
|
||||||
any, err := typeurl.MarshalAny(ext)
|
any, err := typeurl.MarshalAny(ext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to marshal sandbox extension")
|
return fmt.Errorf("failed to marshal sandbox extension: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
s.Extensions[name] = any
|
s.Extensions[name] = any
|
||||||
|
Loading…
Reference in New Issue
Block a user