diff --git a/go.mod b/go.mod index d45991fae..95891170e 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,6 @@ require ( github.com/k8stopologyawareschedwg/noderesourcetopology-api v0.1.0 github.com/onsi/ginkgo/v2 v2.9.1 github.com/onsi/gomega v1.27.4 - github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.16.0 github.com/prometheus/client_model v0.3.0 github.com/prometheus/common v0.42.0 diff --git a/go.sum b/go.sum index 7fe0fa3d8..d5df93501 100644 --- a/go.sum +++ b/go.sum @@ -287,7 +287,6 @@ github.com/opencontainers/runtime-spec v1.0.3-0.20220825212826-86290f6a00fb/go.m github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= diff --git a/pkg/pidfile/pidfile.go b/pkg/pidfile/pidfile.go index 373940dc2..b5b3cb38b 100644 --- a/pkg/pidfile/pidfile.go +++ b/pkg/pidfile/pidfile.go @@ -21,8 +21,6 @@ import ( "strconv" "strings" "syscall" - - "github.com/pkg/errors" ) var ( @@ -51,18 +49,18 @@ func Write() error { err := os.MkdirAll(filepath.Dir(pidFilePath), 0755) if err != nil { - return errors.Wrap(err, "failed to create PID file") + return fmt.Errorf("failed to create PID file: %w", err) } pidFile, err = os.OpenFile(pidFilePath, os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0644) if err != nil { - return errors.Wrap(err, "failed to create PID file") + return fmt.Errorf("failed to create PID file: %w", err) } _, err = pidFile.Write([]byte(fmt.Sprintf("%d\n", os.Getpid()))) if err != nil { close() - return errors.Wrap(err, "failed to write PID file") + return fmt.Errorf("failed to write PID file: %w", err) } return nil @@ -82,11 +80,11 @@ func Read() (int, error) { if os.IsNotExist(err) { return 0, nil } - return -1, errors.Wrap(err, "failed to read PID file") + return -1, fmt.Errorf("failed to read PID file: %w", err) } if pid, err = strconv.Atoi(strings.TrimRight(string(buf), "\n")); err != nil { - return -1, errors.Wrapf(err, "invalid PID (%q) in PID file", string(buf)) + return -1, fmt.Errorf("invalid PID (%q) in PID file: %w", string(buf), err) } return pid, nil @@ -134,7 +132,7 @@ func OwnerPid() (int, error) { p, err = os.FindProcess(pid) if err != nil { - return -1, errors.Wrapf(err, "FindProcess() failed for PID %d", pid) + return -1, fmt.Errorf("FindProcess() failed for PID %d: %w", pid, err) } err = p.Signal(syscall.Signal(0)) @@ -145,7 +143,7 @@ func OwnerPid() (int, error) { return pid, nil } - return -1, errors.Wrapf(err, "failed to check process %d", pid) + return -1, fmt.Errorf("failed to check process %d: %w", pid, err) } // defaultPath returns the default pidfile path. diff --git a/pkg/pidfile/pidfile_test.go b/pkg/pidfile/pidfile_test.go index bf3ee2bdb..d969ed992 100644 --- a/pkg/pidfile/pidfile_test.go +++ b/pkg/pidfile/pidfile_test.go @@ -15,12 +15,12 @@ package pidfile import ( + "fmt" "io/ioutil" "os" "path/filepath" "testing" - "github.com/pkg/errors" "github.com/stretchr/testify/require" ) @@ -244,7 +244,7 @@ func TestOwnerPid(t *testing.T) { func mkTestDir(t *testing.T) (string, error) { tmp, err := ioutil.TempDir("", ".pidfile-test*") if err != nil { - return "", errors.Wrapf(err, "failed to create test directory") + return "", fmt.Errorf("failed to create test directory: %w", err) } t.Cleanup(func() { diff --git a/pkg/resmgr/cache/container_test.go b/pkg/resmgr/cache/container_test.go index 633873d24..f13ec97c1 100644 --- a/pkg/resmgr/cache/container_test.go +++ b/pkg/resmgr/cache/container_test.go @@ -29,7 +29,6 @@ import ( corev1 "k8s.io/api/core/v1" nri "github.com/containerd/nri/pkg/api" - "github.com/pkg/errors" "golang.org/x/sys/unix" "sigs.k8s.io/yaml" ) @@ -871,9 +870,9 @@ func setupSysFsDevice(dev string) error { fi, err := os.Stat(dev) if err != nil { if os.IsNotExist(err) { - return errors.Wrapf(err, "no such file %s", dev) + return fmt.Errorf("no such file %s: %w", dev, err) } - return errors.Wrapf(err, "unable to get stat for %s", dev) + return fmt.Errorf("unable to get stat for %s: %w", dev, err) } devType := "block" @@ -888,12 +887,12 @@ func setupSysFsDevice(dev string) error { major := int64(unix.Major(rdev)) minor := int64(unix.Minor(rdev)) if major == 0 { - return errors.Errorf("%s is a virtual device node", dev) + return fmt.Errorf("%s is a virtual device node", dev) } err = createSysFsDevice(devType, major, minor) if err != nil { - return errors.Wrapf(err, "failed to find sysfs device for %s", dev) + return fmt.Errorf("failed to find sysfs device for %s: %w", dev, err) } return nil diff --git a/pkg/resmgr/nri.go b/pkg/resmgr/nri.go index 2c27c9c1f..b8e51da78 100644 --- a/pkg/resmgr/nri.go +++ b/pkg/resmgr/nri.go @@ -23,7 +23,6 @@ import ( "github.com/containers/nri-plugins/pkg/resmgr/cache" "github.com/containers/nri-plugins/pkg/resmgr/events" "github.com/containers/nri-plugins/pkg/resmgr/policy" - "github.com/pkg/errors" "sigs.k8s.io/yaml" "github.com/containerd/nri/pkg/api" @@ -61,7 +60,7 @@ func (p *nriPlugin) createStub() error { p.Info("creating plugin stub...") if p.stub, err = stub.New(p, opts...); err != nil { - return errors.Wrap(err, "failed to create NRI plugin stub") + return fmt.Errorf("failed to create NRI plugin stub: %w", err) } return nil @@ -79,7 +78,7 @@ func (p *nriPlugin) start() error { } if err := p.stub.Start(context.Background()); err != nil { - return errors.Wrap(err, "failed to start NRI plugin") + return fmt.Errorf("failed to start NRI plugin: %w", err) } return nil @@ -199,8 +198,7 @@ func (p *nriPlugin) Synchronize(ctx context.Context, pods []*api.PodSandbox, con } if err := m.policy.Start(allocated, released); err != nil { - return nil, errors.Wrapf(err, - "failed to start policy %s", policy.ActivePolicy()) + return nil, fmt.Errorf("failed to start policy %s: %w", policy.ActivePolicy(), err) } m.updateTopologyZones() @@ -328,13 +326,13 @@ func (p *nriPlugin) CreateContainer(ctx context.Context, podSandbox *api.PodSand c, err := m.cache.InsertContainer(container) if err != nil { - return nil, nil, errors.Wrap(err, "failed to cache container") + return nil, nil, fmt.Errorf("failed to cache container: %w", err) } c.UpdateState(cache.ContainerStateCreating) if err := m.policy.AllocateResources(c); err != nil { c.UpdateState(cache.ContainerStateStale) - return nil, nil, errors.Wrap(err, "failed to allocate resources") + return nil, nil, fmt.Errorf("failed to allocate resources: %w", err) } c.UpdateState(cache.ContainerStateCreated) @@ -349,7 +347,7 @@ func (p *nriPlugin) CreateContainer(ctx context.Context, podSandbox *api.PodSand m.Error("%s: failed to run post-allocate hooks for %s: %v", event, container.GetName(), err) p.runPostReleaseHooks(event, c) - return nil, nil, errors.Wrap(err, "failed to allocate container resources") + return nil, nil, fmt.Errorf("failed to allocate container resources: %w", err) } m.policy.ExportResourceData(c) @@ -440,7 +438,7 @@ func (p *nriPlugin) UpdateContainer(ctx context.Context, pod *api.PodSandbox, co //r := cache.EstimateResourceRequirements(res, c.GetQOSClass()) if err := m.policy.UpdateResources(c); err != nil { - return nil, errors.Wrap(err, "failed to update resources") + return nil, fmt.Errorf("failed to update resources: %w", err) } return p.getPendingUpdates(nil), nil @@ -473,7 +471,7 @@ func (p *nriPlugin) StopContainer(ctx context.Context, pod *api.PodSandbox, cont } if err := m.policy.ReleaseResources(c); err != nil { - return nil, errors.Wrap(err, "failed to release resources") + return nil, fmt.Errorf("failed to release resources: %w", err) } c.UpdateState(cache.ContainerStateExited) diff --git a/pkg/topology/go.mod b/pkg/topology/go.mod index 0cd38e599..9abf59a3c 100644 --- a/pkg/topology/go.mod +++ b/pkg/topology/go.mod @@ -2,7 +2,4 @@ module github.com/containers/nri-plugins/pkg/topology go 1.19 -require ( - github.com/pkg/errors v0.9.1 - golang.org/x/sys v0.1.0 -) +require golang.org/x/sys v0.1.0 diff --git a/pkg/topology/go.sum b/pkg/topology/go.sum index 3e48b7dad..b69ea8575 100644 --- a/pkg/topology/go.sum +++ b/pkg/topology/go.sum @@ -1,4 +1,2 @@ -github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= -github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/pkg/topology/topology.go b/pkg/topology/topology.go index 27f34f29c..8dc90c227 100644 --- a/pkg/topology/topology.go +++ b/pkg/topology/topology.go @@ -21,7 +21,6 @@ import ( "strings" "syscall" - "github.com/pkg/errors" "golang.org/x/sys/unix" ) @@ -73,11 +72,11 @@ func ResetLogger() { func getDevicesFromVirtual(realDevPath string) (devs []string, err error) { relPath, err := filepath.Rel("/sys/devices/virtual", realDevPath) if err != nil { - return nil, errors.Wrap(err, "unable to find relative path") + return nil, fmt.Errorf("unable to find relative path: %w", err) } if strings.HasPrefix(relPath, "..") { - return nil, errors.Errorf("%s is not a virtual device", realDevPath) + return nil, fmt.Errorf("%s is not a virtual device", realDevPath) } dir, file := filepath.Split(relPath) @@ -86,12 +85,12 @@ func getDevicesFromVirtual(realDevPath string) (devs []string, err error) { iommuGroup := filepath.Join(sysRoot, "/sys/kernel/iommu_groups", file, "devices") files, err := os.ReadDir(iommuGroup) if err != nil { - return nil, errors.Wrapf(err, "failed to read IOMMU group %s", iommuGroup) + return nil, fmt.Errorf("failed to read IOMMU group %s: %w", iommuGroup, err) } for _, file := range files { realDev, err := filepath.EvalSymlinks(filepath.Join(iommuGroup, file.Name())) if err != nil { - return nil, errors.Wrapf(err, "failed to get real path for %s", file.Name()) + return nil, fmt.Errorf("failed to get real path for %s: %w", file.Name(), err) } devs = append(devs, realDev) } @@ -160,7 +159,7 @@ func NewTopologyHints(devPath string) (hints Hints, err error) { hints = make(Hints) realDevPath, err := filepath.EvalSymlinks(devPath) if err != nil { - return nil, errors.Wrapf(err, "failed get realpath for %s", devPath) + return nil, fmt.Errorf("failed get realpath for %s: %w", devPath, err) } for p := realDevPath; strings.HasPrefix(p, sysRoot+"/sys/devices/"); p = filepath.Dir(p) { hint, err := getTopologyHint(p) @@ -230,7 +229,7 @@ func FindSysFsDevice(dev string) (string, error) { if os.IsNotExist(err) { return "", nil } - return "", errors.Wrapf(err, "unable to get stat for %s", dev) + return "", fmt.Errorf("unable to get stat for %s: %w", dev, err) } devType := "block" @@ -245,12 +244,12 @@ func FindSysFsDevice(dev string) (string, error) { major := int64(unix.Major(rdev)) minor := int64(unix.Minor(rdev)) if major == 0 { - return "", errors.Errorf("%s is a virtual device node", dev) + return "", fmt.Errorf("%s is a virtual device node: %w", dev, err) } realDevPath, err := findSysFsDevice(devType, major, minor) if err != nil { - return "", errors.Wrapf(err, "failed to find sysfs device for %s", dev) + return "", fmt.Errorf("failed to find sysfs device for %s: %w", dev, err) } return realDevPath, nil @@ -271,8 +270,8 @@ func FindGivenSysFsDevice(devType string, major, minor int64) (string, error) { realDevPath, err := findSysFsDevice(devType, major, minor) if err != nil { - return "", errors.Wrapf(err, "failed find sysfs device for %s device %d/%d", - devType, major, minor) + return "", fmt.Errorf("failed find sysfs device for %s device %d/%d: %w", + devType, major, minor, err) } return realDevPath, nil @@ -282,7 +281,7 @@ func findSysFsDevice(devType string, major, minor int64) (string, error) { devPath := fmt.Sprintf("/sys/dev/%s/%d:%d", devType, major, minor) realDevPath, err := filepath.EvalSymlinks(devPath) if err != nil { - return "", errors.Wrapf(err, "failed to get realpath for %s", devPath) + return "", fmt.Errorf("failed to get realpath for %s: %w", devPath, err) } return filepath.Join(sysRoot, realDevPath), nil } @@ -295,7 +294,7 @@ func readFilesInDirectory(fileMap map[string]*string, dir string) error { if os.IsNotExist(err) { continue } - return errors.Wrapf(err, "%s: unable to read file %q", dir, k) + return fmt.Errorf("%s: unable to read file %q: %w", dir, k, err) } *v = strings.TrimSpace(string(b)) }