Skip to content

Commit 4ff5113

Browse files
authored
Merge pull request #208 from zouyee/replaceerror
replace pkg/errors from vendor
2 parents 90010ec + 0072297 commit 4ff5113

File tree

10 files changed

+40
-39
lines changed

10 files changed

+40
-39
lines changed

.github/workflows/ci.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ jobs:
2323
# Install Go
2424
#
2525
- name: Install Go
26-
uses: actions/setup-go@v1
26+
uses: actions/setup-go@v2
2727
with:
28-
go-version: '1.15'
28+
go-version: '1.16.x'
2929

3030
- name: Set env
3131
shell: bash
@@ -88,9 +88,9 @@ jobs:
8888

8989
steps:
9090
- name: Install Go
91-
uses: actions/setup-go@v1
91+
uses: actions/setup-go@v2
9292
with:
93-
go-version: '1.15'
93+
go-version: '1.16.x'
9494

9595
- name: Set env
9696
shell: bash

cgroup.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package cgroups
1818

1919
import (
20+
"errors"
2021
"fmt"
2122
"os"
2223
"path/filepath"
@@ -25,8 +26,8 @@ import (
2526
"sync"
2627

2728
v1 "github.com/containerd/cgroups/stats/v1"
28-
specs "github.com/opencontainers/runtime-spec/specs-go"
29-
"github.com/pkg/errors"
29+
30+
"github.com/opencontainers/runtime-spec/specs-go"
3031
)
3132

3233
// New returns a new control via the cgroup cgroups interface
@@ -83,7 +84,7 @@ func Load(hierarchy Hierarchy, path Path, opts ...InitOpts) (Cgroup, error) {
8384
for _, s := range pathers(subsystems) {
8485
p, err := path(s.Name())
8586
if err != nil {
86-
if os.IsNotExist(errors.Cause(err)) {
87+
if errors.Is(err, os.ErrNotExist) {
8788
return nil, ErrCgroupDeleted
8889
}
8990
if err == ErrControllerNotActive {

go.mod

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/containerd/cgroups
22

3-
go 1.13
3+
go 1.16
44

55
require (
66
github.com/cilium/ebpf v0.4.0
@@ -10,8 +10,7 @@ require (
1010
github.com/godbus/dbus/v5 v5.0.4
1111
github.com/gogo/protobuf v1.3.2
1212
github.com/opencontainers/runtime-spec v1.0.2
13-
github.com/pkg/errors v0.9.1
14-
github.com/sirupsen/logrus v1.7.0
13+
github.com/sirupsen/logrus v1.8.1
1514
github.com/stretchr/testify v1.6.1
1615
github.com/urfave/cli v1.22.2
1716
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c

go.sum

+2-4
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,14 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
2828
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
2929
github.com/opencontainers/runtime-spec v1.0.2 h1:UfAcuLBJB9Coz72x1hgl8O5RVzTdNiaglX6v2DM6FI0=
3030
github.com/opencontainers/runtime-spec v1.0.2/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
31-
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
32-
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
3331
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
3432
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
3533
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
3634
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
3735
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
3836
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
39-
github.com/sirupsen/logrus v1.7.0 h1:ShrD1U9pZB12TX0cVy0DtePoCH97K8EtX+mg7ZARUtM=
40-
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
37+
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
38+
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
4139
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
4240
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
4341
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=

opts.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package cgroups
1818

1919
import (
20-
"github.com/pkg/errors"
20+
"errors"
2121
)
2222

2323
var (

paths.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717
package cgroups
1818

1919
import (
20+
"errors"
2021
"fmt"
2122
"path/filepath"
22-
23-
"github.com/pkg/errors"
2423
)
2524

2625
type Path func(subsystem Name) (string, error)
@@ -52,7 +51,7 @@ func PidPath(pid int) Path {
5251
p := fmt.Sprintf("/proc/%d/cgroup", pid)
5352
paths, err := ParseCgroupFile(p)
5453
if err != nil {
55-
return errorPath(errors.Wrapf(err, "parse cgroup file %s", p))
54+
return errorPath(fmt.Errorf("parse cgroup file %s: %w", p, err))
5655
}
5756
return existingPath(paths, "")
5857
}

v2/devicefilter.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,16 @@
2323
//
2424
// This particular Go implementation based on runc version
2525
// https://github.com/opencontainers/runc/blob/master/libcontainer/cgroups/ebpf/devicefilter/devicefilter.go
26+
2627
package v2
2728

2829
import (
30+
"errors"
2931
"fmt"
3032
"math"
3133

3234
"github.com/cilium/ebpf/asm"
3335
"github.com/opencontainers/runtime-spec/specs-go"
34-
"github.com/pkg/errors"
3536
"golang.org/x/sys/unix"
3637
)
3738

@@ -106,13 +107,13 @@ func (p *program) appendDevice(dev specs.LinuxDeviceCgroup) error {
106107
hasType = false
107108
default:
108109
// if not specified in OCI json, typ is set to DeviceTypeAll
109-
return errors.Errorf("invalid DeviceType %q", dev.Type)
110+
return fmt.Errorf("invalid DeviceType %q", dev.Type)
110111
}
111112
if *dev.Major > math.MaxUint32 {
112-
return errors.Errorf("invalid major %d", *dev.Major)
113+
return fmt.Errorf("invalid major %d", *dev.Major)
113114
}
114115
if *dev.Minor > math.MaxUint32 {
115-
return errors.Errorf("invalid minor %d", *dev.Major)
116+
return fmt.Errorf("invalid minor %d", *dev.Major)
116117
}
117118
hasMajor := *dev.Major >= 0 // if not specified in OCI json, major is set to -1
118119
hasMinor := *dev.Minor >= 0
@@ -126,7 +127,7 @@ func (p *program) appendDevice(dev specs.LinuxDeviceCgroup) error {
126127
case 'm':
127128
bpfAccess |= unix.BPF_DEVCG_ACC_MKNOD
128129
default:
129-
return errors.Errorf("unknown device access %v", r)
130+
return fmt.Errorf("unknown device access %v", r)
130131
}
131132
}
132133
// If the access is rwm, skip the check.

v2/ebpf.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717
package v2
1818

1919
import (
20+
"fmt"
21+
2022
"github.com/cilium/ebpf"
2123
"github.com/cilium/ebpf/asm"
2224
"github.com/cilium/ebpf/link"
2325
"github.com/opencontainers/runtime-spec/specs-go"
24-
"github.com/pkg/errors"
2526
"golang.org/x/sys/unix"
2627
)
2728

@@ -50,7 +51,7 @@ func LoadAttachCgroupDeviceFilter(insts asm.Instructions, license string, dirFD
5051
Flags: unix.BPF_F_ALLOW_MULTI,
5152
})
5253
if err != nil {
53-
return nilCloser, errors.Wrap(err, "failed to call BPF_PROG_ATTACH (BPF_CGROUP_DEVICE, BPF_F_ALLOW_MULTI)")
54+
return nilCloser, fmt.Errorf("failed to call BPF_PROG_ATTACH (BPF_CGROUP_DEVICE, BPF_F_ALLOW_MULTI): %w", err)
5455
}
5556
closer := func() error {
5657
err = link.RawDetachProgram(link.RawDetachProgramOptions{
@@ -59,7 +60,7 @@ func LoadAttachCgroupDeviceFilter(insts asm.Instructions, license string, dirFD
5960
Attach: ebpf.AttachCGroupDevice,
6061
})
6162
if err != nil {
62-
return errors.Wrap(err, "failed to call BPF_PROG_DETACH (BPF_CGROUP_DEVICE)")
63+
return fmt.Errorf("failed to call BPF_PROG_DETACH (BPF_CGROUP_DEVICE): %w", err)
6364
}
6465
return nil
6566
}

v2/manager.go

+13-11
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ package v2
1919
import (
2020
"bufio"
2121
"context"
22+
"errors"
23+
"fmt"
2224
"io/ioutil"
2325
"math"
2426
"os"
@@ -29,10 +31,10 @@ import (
2931
"time"
3032

3133
"github.com/containerd/cgroups/v2/stats"
34+
3235
systemdDbus "github.com/coreos/go-systemd/v22/dbus"
3336
"github.com/godbus/dbus/v5"
3437
"github.com/opencontainers/runtime-spec/specs-go"
35-
"github.com/pkg/errors"
3638
"github.com/sirupsen/logrus"
3739
"golang.org/x/sys/unix"
3840
)
@@ -271,7 +273,7 @@ func (c *Manager) ToggleControllers(controllers []string, t ControllerToggle) er
271273
// When running as rootless, the user may face EPERM on parent groups, but it is neglible when the
272274
// controller is already written.
273275
// So we only return the last error.
274-
lastErr = errors.Wrapf(err, "failed to write subtree controllers %+v to %q", controllers, filePath)
276+
lastErr = fmt.Errorf("failed to write subtree controllers %+v to %q: %w", controllers, filePath, err)
275277
} else {
276278
lastErr = nil
277279
}
@@ -526,7 +528,7 @@ func readKVStatsFile(path string, file string, out map[string]interface{}) error
526528
for s.Scan() {
527529
name, value, err := parseKV(s.Text())
528530
if err != nil {
529-
return errors.Wrapf(err, "error while parsing %s (line=%q)", filepath.Join(path, file), s.Text())
531+
return fmt.Errorf("error while parsing %s (line=%q): %w", filepath.Join(path, file), s.Text(), err)
530532
}
531533
out[name] = value
532534
}
@@ -563,12 +565,12 @@ func (c *Manager) MemoryEventFD() (int, uint32, error) {
563565
fpath := filepath.Join(c.path, "memory.events")
564566
fd, err := syscall.InotifyInit()
565567
if err != nil {
566-
return 0, 0, errors.Errorf("Failed to create inotify fd")
568+
return 0, 0, errors.New("failed to create inotify fd")
567569
}
568570
wd, err := syscall.InotifyAddWatch(fd, fpath, unix.IN_MODIFY)
569571
if wd < 0 {
570572
syscall.Close(fd)
571-
return 0, 0, errors.Errorf("Failed to add inotify watch for %q", fpath)
573+
return 0, 0, fmt.Errorf("failed to add inotify watch for %q", fpath)
572574
}
573575

574576
return fd, uint32(wd), nil
@@ -607,35 +609,35 @@ func (c *Manager) waitForEvents(ec chan<- Event, errCh chan<- error) {
607609
if v, ok := out["high"]; ok {
608610
e.High, ok = v.(uint64)
609611
if !ok {
610-
errCh <- errors.Errorf("cannot convert high to uint64: %+v", v)
612+
errCh <- fmt.Errorf("cannot convert high to uint64: %+v", v)
611613
return
612614
}
613615
}
614616
if v, ok := out["low"]; ok {
615617
e.Low, ok = v.(uint64)
616618
if !ok {
617-
errCh <- errors.Errorf("cannot convert low to uint64: %+v", v)
619+
errCh <- fmt.Errorf("cannot convert low to uint64: %+v", v)
618620
return
619621
}
620622
}
621623
if v, ok := out["max"]; ok {
622624
e.Max, ok = v.(uint64)
623625
if !ok {
624-
errCh <- errors.Errorf("cannot convert max to uint64: %+v", v)
626+
errCh <- fmt.Errorf("cannot convert max to uint64: %+v", v)
625627
return
626628
}
627629
}
628630
if v, ok := out["oom"]; ok {
629631
e.OOM, ok = v.(uint64)
630632
if !ok {
631-
errCh <- errors.Errorf("cannot convert oom to uint64: %+v", v)
633+
errCh <- fmt.Errorf("cannot convert oom to uint64: %+v", v)
632634
return
633635
}
634636
}
635637
if v, ok := out["oom_kill"]; ok {
636638
e.OOMKill, ok = v.(uint64)
637639
if !ok {
638-
errCh <- errors.Errorf("cannot convert oom_kill to uint64: %+v", v)
640+
errCh <- fmt.Errorf("cannot convert oom_kill to uint64: %+v", v)
639641
return
640642
}
641643
}
@@ -658,7 +660,7 @@ func setDevices(path string, devices []specs.LinuxDeviceCgroup) error {
658660
}
659661
dirFD, err := unix.Open(path, unix.O_DIRECTORY|unix.O_RDONLY, 0600)
660662
if err != nil {
661-
return errors.Errorf("cannot get dir FD for %s", path)
663+
return fmt.Errorf("cannot get dir FD for %s", path)
662664
}
663665
defer unix.Close(dirFD)
664666
if _, err := LoadAttachCgroupDeviceFilter(insts, license, dirFD); err != nil {

v2/utils.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ import (
2929
"time"
3030

3131
"github.com/containerd/cgroups/v2/stats"
32+
3233
"github.com/godbus/dbus/v5"
3334
"github.com/opencontainers/runtime-spec/specs-go"
34-
"github.com/pkg/errors"
3535
"github.com/sirupsen/logrus"
3636
)
3737

@@ -61,7 +61,7 @@ func remove(path string) error {
6161
return nil
6262
}
6363
}
64-
return errors.Wrapf(err, "cgroups: unable to remove path %q", path)
64+
return fmt.Errorf("cgroups: unable to remove path %q: %w", path, err)
6565
}
6666

6767
// parseCgroupProcsFile parses /sys/fs/cgroup/$GROUPPATH/cgroup.procs

0 commit comments

Comments
 (0)