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:
@@ -46,7 +46,6 @@ import (
|
||||
"github.com/containerd/typeurl"
|
||||
gogotypes "github.com/gogo/protobuf/types"
|
||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/pkg/errors"
|
||||
exec "golang.org/x/sys/execabs"
|
||||
)
|
||||
|
||||
@@ -1903,7 +1902,7 @@ func TestRegressionIssue4769(t *testing.T) {
|
||||
select {
|
||||
case et := <-statusC:
|
||||
if got := et.ExitCode(); got != 0 {
|
||||
t.Fatal(errors.Errorf("expect zero exit status, but got %v", got))
|
||||
t.Fatal(fmt.Errorf("expect zero exit status, but got %v", got))
|
||||
}
|
||||
case <-time.After(timeout):
|
||||
t.Fatal(fmt.Errorf("failed to get exit event in time"))
|
||||
@@ -1913,21 +1912,21 @@ func TestRegressionIssue4769(t *testing.T) {
|
||||
select {
|
||||
case et := <-eventStream:
|
||||
if et.Event == nil {
|
||||
t.Fatal(errors.Errorf("unexpected empty event: %+v", et))
|
||||
t.Fatal(fmt.Errorf("unexpected empty event: %+v", et))
|
||||
}
|
||||
|
||||
v, err := typeurl.UnmarshalAny(et.Event)
|
||||
if err != nil {
|
||||
t.Fatal(errors.Wrap(err, "failed to unmarshal event"))
|
||||
t.Fatal(fmt.Errorf("failed to unmarshal event: %w", err))
|
||||
}
|
||||
|
||||
if e, ok := v.(*apievents.TaskExit); !ok {
|
||||
t.Fatal(errors.Errorf("unexpected event type: %+v", v))
|
||||
t.Fatal(fmt.Errorf("unexpected event type: %+v", v))
|
||||
} else if e.ExitStatus != 0 {
|
||||
t.Fatal(errors.Errorf("expect zero exit status, but got %v", e.ExitStatus))
|
||||
t.Fatal(fmt.Errorf("expect zero exit status, but got %v", e.ExitStatus))
|
||||
}
|
||||
case err := <-errC:
|
||||
t.Fatal(errors.Wrap(err, "unexpected error from event service"))
|
||||
t.Fatal(fmt.Errorf("unexpected error from event service: %w", err))
|
||||
|
||||
case <-time.After(timeout):
|
||||
t.Fatal(fmt.Errorf("failed to get exit event in time"))
|
||||
@@ -1940,9 +1939,9 @@ func TestRegressionIssue4769(t *testing.T) {
|
||||
// check duplicate event should not show up
|
||||
select {
|
||||
case event := <-eventStream:
|
||||
t.Fatal(errors.Errorf("unexpected exit event: %+v", event))
|
||||
t.Fatal(fmt.Errorf("unexpected exit event: %+v", event))
|
||||
case err := <-errC:
|
||||
t.Fatal(errors.Wrap(err, "unexpected error from event service"))
|
||||
t.Fatal(fmt.Errorf("unexpected error from event service: %w", err))
|
||||
case <-time.After(timeout):
|
||||
}
|
||||
}
|
||||
|
@@ -27,7 +27,6 @@ import (
|
||||
"github.com/containerd/containerd/content/testsuite"
|
||||
"github.com/containerd/containerd/errdefs"
|
||||
"github.com/containerd/containerd/namespaces"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func newContentStore(ctx context.Context, root string) (context.Context, content.Store, func() error, error) {
|
||||
@@ -59,7 +58,7 @@ func newContentStore(ctx context.Context, root string) (context.Context, content
|
||||
}
|
||||
for _, st := range statuses {
|
||||
if err := cs.Abort(ctx, st.Ref); err != nil && !errdefs.IsNotFound(err) {
|
||||
return errors.Wrapf(err, "failed to abort %s", st.Ref)
|
||||
return fmt.Errorf("failed to abort %s: %w", st.Ref, err)
|
||||
}
|
||||
}
|
||||
err = cs.Walk(ctx, func(info content.Info) error {
|
||||
|
@@ -18,13 +18,14 @@ package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"runtime"
|
||||
"sync"
|
||||
"syscall"
|
||||
|
||||
. "github.com/containerd/containerd"
|
||||
"github.com/pkg/errors"
|
||||
exec "golang.org/x/sys/execabs"
|
||||
)
|
||||
|
||||
@@ -46,7 +47,7 @@ func (d *daemon) start(name, address string, args []string, stdout, stderr io.Wr
|
||||
cmd.Stderr = stderr
|
||||
if err := cmd.Start(); err != nil {
|
||||
cmd.Wait()
|
||||
return errors.Wrap(err, "failed to start daemon")
|
||||
return fmt.Errorf("failed to start daemon: %w", err)
|
||||
}
|
||||
d.addr = address
|
||||
d.cmd = cmd
|
||||
@@ -117,7 +118,7 @@ func (d *daemon) Restart(stopCb func()) error {
|
||||
}
|
||||
var err error
|
||||
if err = d.cmd.Process.Signal(signal); err != nil {
|
||||
return errors.Wrap(err, "failed to signal daemon")
|
||||
return fmt.Errorf("failed to signal daemon: %w", err)
|
||||
}
|
||||
|
||||
d.cmd.Wait()
|
||||
@@ -131,7 +132,7 @@ func (d *daemon) Restart(stopCb func()) error {
|
||||
cmd.Stderr = d.cmd.Stderr
|
||||
if err := cmd.Start(); err != nil {
|
||||
cmd.Wait()
|
||||
return errors.Wrap(err, "failed to start new daemon instance")
|
||||
return fmt.Errorf("failed to start new daemon instance: %w", err)
|
||||
}
|
||||
d.cmd = cmd
|
||||
|
||||
|
@@ -16,7 +16,6 @@ require (
|
||||
github.com/opencontainers/go-digest v1.0.0
|
||||
github.com/opencontainers/image-spec v1.0.2-0.20211117181255-693428a734f5
|
||||
github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/sirupsen/logrus v1.8.1
|
||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e
|
||||
gotest.tools/v3 v3.0.3
|
||||
|
@@ -17,12 +17,12 @@
|
||||
package integration
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
goruntime "runtime"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
|
||||
@@ -372,7 +372,7 @@ func TestContainerListStatsWithIdSandboxIdFilter(t *testing.T) {
|
||||
return false, err
|
||||
}
|
||||
if len(stats) != 1 {
|
||||
return false, errors.Errorf("expected only one stat, but got %v", stats)
|
||||
return false, fmt.Errorf("expected only one stat, but got %v", stats)
|
||||
}
|
||||
if stats[0].GetWritableLayer().GetUsedBytes().GetValue() != 0 {
|
||||
return true, nil
|
||||
|
@@ -17,17 +17,17 @@
|
||||
package integration
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
|
||||
"github.com/containerd/containerd"
|
||||
"github.com/containerd/containerd/errdefs"
|
||||
"github.com/containerd/containerd/namespaces"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"golang.org/x/net/context"
|
||||
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
|
||||
)
|
||||
|
||||
@@ -77,10 +77,10 @@ func TestContainerdImage(t *testing.T) {
|
||||
}
|
||||
if len(img.RepoTags) != 1 {
|
||||
// RepoTags must have been populated correctly.
|
||||
return false, errors.Errorf("unexpected repotags: %+v", img.RepoTags)
|
||||
return false, fmt.Errorf("unexpected repotags: %+v", img.RepoTags)
|
||||
}
|
||||
if img.RepoTags[0] != testImage {
|
||||
return false, errors.Errorf("unexpected repotag %q", img.RepoTags[0])
|
||||
return false, fmt.Errorf("unexpected repotag %q", img.RepoTags[0])
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
@@ -17,11 +17,11 @@
|
||||
package integration
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
|
||||
@@ -47,7 +47,7 @@ func TestImageFSInfo(t *testing.T) {
|
||||
return false, nil
|
||||
}
|
||||
if len(stats) >= 2 {
|
||||
return false, errors.Errorf("unexpected stats length: %d", len(stats))
|
||||
return false, fmt.Errorf("unexpected stats length: %d", len(stats))
|
||||
}
|
||||
info = stats[0]
|
||||
if info.GetTimestamp() != 0 &&
|
||||
|
@@ -19,6 +19,7 @@ package integration
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
@@ -37,7 +38,6 @@ import (
|
||||
"github.com/containerd/containerd/pkg/cri/constants"
|
||||
"github.com/containerd/containerd/pkg/cri/server"
|
||||
"github.com/containerd/containerd/pkg/cri/util"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -78,29 +78,29 @@ func ConnectDaemons() error {
|
||||
var err error
|
||||
runtimeService, err = remote.NewRuntimeService(*criEndpoint, timeout)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to create runtime service")
|
||||
return fmt.Errorf("failed to create runtime service: %w", err)
|
||||
}
|
||||
imageService, err = remote.NewImageService(*criEndpoint, timeout)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to create image service")
|
||||
return fmt.Errorf("failed to create image service: %w", err)
|
||||
}
|
||||
// Since CRI grpc client doesn't have `WithBlock` specified, we
|
||||
// need to check whether it is actually connected.
|
||||
// TODO(#6069) Use grpc options to block on connect and remove for this list containers request.
|
||||
_, err = runtimeService.ListContainers(&runtime.ContainerFilter{})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to list containers")
|
||||
return fmt.Errorf("failed to list containers: %w", err)
|
||||
}
|
||||
_, err = imageService.ListImages(&runtime.ImageFilter{})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to list images")
|
||||
return fmt.Errorf("failed to list images: %w", err)
|
||||
}
|
||||
// containerdEndpoint is the same with criEndpoint now
|
||||
containerdEndpoint = strings.TrimPrefix(*criEndpoint, "unix://")
|
||||
containerdEndpoint = strings.TrimPrefix(containerdEndpoint, "npipe:")
|
||||
containerdClient, err = containerd.New(containerdEndpoint, containerd.WithDefaultNamespace(k8sNamespace))
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to connect containerd")
|
||||
return fmt.Errorf("failed to connect containerd: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -371,7 +371,7 @@ func KillProcess(name string) error {
|
||||
|
||||
output, err := exec.Command(command[0], command[1:]...).CombinedOutput()
|
||||
if err != nil {
|
||||
return errors.Errorf("failed to kill %q - error: %v, output: %q", name, err, output)
|
||||
return fmt.Errorf("failed to kill %q - error: %v, output: %q", name, err, output)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -380,7 +380,7 @@ func KillProcess(name string) error {
|
||||
func KillPid(pid int) error { //nolint:unused
|
||||
output, err := exec.Command("kill", strconv.Itoa(pid)).CombinedOutput()
|
||||
if err != nil {
|
||||
return errors.Errorf("failed to kill %d - error: %v, output: %q", pid, err, output)
|
||||
return fmt.Errorf("failed to kill %d - error: %v, output: %q", pid, err, output)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -391,7 +391,7 @@ func PidOf(name string) (int, error) {
|
||||
output := strings.TrimSpace(string(b))
|
||||
if err != nil {
|
||||
if len(output) != 0 {
|
||||
return 0, errors.Errorf("failed to run pidof %q - error: %v, output: %q", name, err, output)
|
||||
return 0, fmt.Errorf("failed to run pidof %q - error: %v, output: %q", name, err, output)
|
||||
}
|
||||
return 0, nil
|
||||
}
|
||||
@@ -402,7 +402,7 @@ func PidOf(name string) (int, error) {
|
||||
func RawRuntimeClient() (runtime.RuntimeServiceClient, error) {
|
||||
addr, dialer, err := dialer.GetAddressAndDialer(*criEndpoint)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to get dialer")
|
||||
return nil, fmt.Errorf("failed to get dialer: %w", err)
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||
defer cancel()
|
||||
@@ -411,7 +411,7 @@ func RawRuntimeClient() (runtime.RuntimeServiceClient, error) {
|
||||
grpc.WithContextDialer(dialer),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to connect cri endpoint")
|
||||
return nil, fmt.Errorf("failed to connect cri endpoint: %w", err)
|
||||
}
|
||||
return runtime.NewRuntimeServiceClient(conn), nil
|
||||
}
|
||||
@@ -420,15 +420,15 @@ func RawRuntimeClient() (runtime.RuntimeServiceClient, error) {
|
||||
func CRIConfig() (*criconfig.Config, error) {
|
||||
client, err := RawRuntimeClient()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to get raw runtime client")
|
||||
return nil, fmt.Errorf("failed to get raw runtime client: %w", err)
|
||||
}
|
||||
resp, err := client.Status(context.Background(), &runtime.StatusRequest{Verbose: true})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to get status")
|
||||
return nil, fmt.Errorf("failed to get status: %w", err)
|
||||
}
|
||||
config := &criconfig.Config{}
|
||||
if err := json.Unmarshal([]byte(resp.Info["config"]), config); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to unmarshal config")
|
||||
return nil, fmt.Errorf("failed to unmarshal config: %w", err)
|
||||
}
|
||||
return config, nil
|
||||
}
|
||||
@@ -437,19 +437,19 @@ func CRIConfig() (*criconfig.Config, error) {
|
||||
func SandboxInfo(id string) (*runtime.PodSandboxStatus, *server.SandboxInfo, error) { //nolint:unused
|
||||
client, err := RawRuntimeClient()
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(err, "failed to get raw runtime client")
|
||||
return nil, nil, fmt.Errorf("failed to get raw runtime client: %w", err)
|
||||
}
|
||||
resp, err := client.PodSandboxStatus(context.Background(), &runtime.PodSandboxStatusRequest{
|
||||
PodSandboxId: id,
|
||||
Verbose: true,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(err, "failed to get sandbox status")
|
||||
return nil, nil, fmt.Errorf("failed to get sandbox status: %w", err)
|
||||
}
|
||||
status := resp.GetStatus()
|
||||
var info server.SandboxInfo
|
||||
if err := json.Unmarshal([]byte(resp.GetInfo()["info"]), &info); err != nil {
|
||||
return nil, nil, errors.Wrap(err, "failed to unmarshal sandbox info")
|
||||
return nil, nil, fmt.Errorf("failed to unmarshal sandbox info: %w", err)
|
||||
}
|
||||
return status, &info, nil
|
||||
}
|
||||
|
@@ -21,6 +21,7 @@ package integration
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -33,7 +34,6 @@ import (
|
||||
v1shimcli "github.com/containerd/containerd/runtime/v1/shim/client"
|
||||
v2shimcli "github.com/containerd/containerd/runtime/v2/shim"
|
||||
"github.com/containerd/ttrpc"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const abstractSocketPrefix = "\x00"
|
||||
|
Reference in New Issue
Block a user