@@ -15,6 +15,8 @@ package main
15
15
16
16
import (
17
17
"encoding/json"
18
+ "errors"
19
+ "fmt"
18
20
"os"
19
21
"strconv"
20
22
"strings"
@@ -26,7 +28,6 @@ import (
26
28
"github.com/containernetworking/plugins/pkg/ns"
27
29
"github.com/containernetworking/plugins/pkg/utils/buildversion"
28
30
"github.com/hashicorp/go-multierror"
29
- "github.com/pkg/errors"
30
31
31
32
pluginargs "github.com/awslabs/tc-redirect-tap/cmd/tc-redirect-tap/args"
32
33
"github.com/awslabs/tc-redirect-tap/internal"
@@ -47,7 +48,7 @@ func add(args *skel.CmdArgs) error {
47
48
}
48
49
49
50
if p .netNS == nil {
50
- return errors .Errorf ("netns path %q does not exist" , args .Netns )
51
+ return fmt .Errorf ("netns path %q does not exist" , args .Netns )
51
52
}
52
53
53
54
if p .currentResult == nil {
@@ -84,7 +85,7 @@ func check(args *skel.CmdArgs) error {
84
85
}
85
86
86
87
if p .netNS == nil {
87
- return errors .Errorf ("netns path %q does not exist" , args .Netns )
88
+ return fmt .Errorf ("netns path %q does not exist" , args .Netns )
88
89
}
89
90
90
91
if p .currentResult == nil {
@@ -107,7 +108,7 @@ func newPlugin(args *skel.CmdArgs) (*plugin, error) {
107
108
case ns.NSPathNotExistErr :
108
109
netNS = nil
109
110
default :
110
- return nil , errors . Wrapf ( err , "failed to open netns at path %q" , args .Netns )
111
+ return nil , fmt . Errorf ( "failed to open netns at path %q: %w " , args .Netns , err )
111
112
}
112
113
}
113
114
@@ -117,7 +118,7 @@ func newPlugin(args *skel.CmdArgs) (*plugin, error) {
117
118
case * NoPreviousResultError :
118
119
currentResult = nil
119
120
default :
120
- return nil , errors . Wrapf ( err , "failure parsing previous CNI result" )
121
+ return nil , fmt . Errorf ( "failure parsing previous CNI result: %w" , err )
121
122
}
122
123
}
123
124
@@ -147,15 +148,15 @@ func newPlugin(args *skel.CmdArgs) (*plugin, error) {
147
148
if tapUIDVal , wasDefined := parsedArgs [pluginargs .TCRedirectTapUID ]; wasDefined {
148
149
tapUID , err := strconv .Atoi (tapUIDVal )
149
150
if err != nil {
150
- return nil , errors . Wrapf ( err , "tapUID should be numeric convertible, got %q" , tapUIDVal )
151
+ return nil , fmt . Errorf ( "tapUID should be numeric convertible, got %q: %w " , tapUIDVal , err )
151
152
}
152
153
plugin .tapUID = tapUID
153
154
}
154
155
155
156
if tapGIDVal , wasDefined := parsedArgs [pluginargs .TCRedirectTapGID ]; wasDefined {
156
157
tapGID , err := strconv .Atoi (tapGIDVal )
157
158
if err != nil {
158
- return nil , errors . Wrapf ( err , "tapGID should be numeric convertible, got %q" , tapGIDVal )
159
+ return nil , fmt . Errorf ( "tapGID should be numeric convertible, got %q: %w " , tapGIDVal , err )
159
160
}
160
161
plugin .tapGID = tapGID
161
162
}
@@ -168,12 +169,12 @@ func getCurrentResult(args *skel.CmdArgs) (*current.Result, error) {
168
169
cniConf := types.NetConf {}
169
170
err := json .Unmarshal (args .StdinData , & cniConf )
170
171
if err != nil {
171
- return nil , errors . Wrap ( err , "failure checking for previous result output" )
172
+ return nil , fmt . Errorf ( "failure checking for previous result output: %w" , err )
172
173
}
173
174
174
175
err = version .ParsePrevResult (& cniConf )
175
176
if err != nil {
176
- return nil , errors . Wrap ( err , "failed to parse previous CNI result" )
177
+ return nil , fmt . Errorf ( "failed to parse previous CNI result: %w" , err )
177
178
}
178
179
179
180
if cniConf .PrevResult == nil {
@@ -182,8 +183,7 @@ func getCurrentResult(args *skel.CmdArgs) (*current.Result, error) {
182
183
183
184
currentResult , err := current .NewResultFromResult (cniConf .PrevResult )
184
185
if err != nil {
185
- return nil , errors .Wrap (err ,
186
- "failed to generate current result from previous CNI result" )
186
+ return nil , fmt .Errorf ("failed to generate current result from previous CNI result: %w" , err )
187
187
}
188
188
189
189
return currentResult , nil
@@ -225,8 +225,7 @@ func (p plugin) add() error {
225
225
return p .netNS .Do (func (_ ns.NetNS ) error {
226
226
redirectLink , err := p .GetLink (p .redirectInterfaceName )
227
227
if err != nil {
228
- return errors .Wrapf (err ,
229
- "failed to find redirect interface %q" , p .redirectInterfaceName )
228
+ return fmt .Errorf ("failed to find redirect interface %q: %w" , p .redirectInterfaceName , err )
230
229
}
231
230
232
231
redirectIPs := internal .InterfaceIPs (
@@ -308,16 +307,18 @@ func (p plugin) del() error {
308
307
case nil , * internal.QdiscNotFoundError :
309
308
// we removed successfully or there already wasn't a qdisc, nothing to do
310
309
default :
311
- multiErr = multierror .Append (multiErr , errors .Wrapf (err ,
312
- "failed to remove ingress qdisc from %q" , redirectLink .Attrs ().Name ))
310
+ multiErr = multierror .Append (multiErr ,
311
+ fmt .Errorf ("failed to remove ingres qdisc from %q: %w" , redirectLink .Attrs ().Name , err ),
312
+ )
313
313
}
314
314
315
315
case * internal.LinkNotFoundError :
316
316
// if the link doesn't exist, there's nothing to do
317
317
318
318
default :
319
319
multiErr = multierror .Append (multiErr ,
320
- errors .Wrapf (err , "failure finding device %q" , p .redirectInterfaceName ))
320
+ fmt .Errorf ("failure finding device %q: %w" , p .redirectInterfaceName , err ),
321
+ )
321
322
}
322
323
323
324
// if there was no previous result, we can't find the vm-tap pair, so we are done here
@@ -335,8 +336,9 @@ func (p plugin) del() error {
335
336
case nil , * internal.LinkNotFoundError :
336
337
// we removed successfully or someone else beat us to removing it first
337
338
default :
338
- multiErr = multierror .Append (multiErr , errors .Wrapf (err ,
339
- "failure removing device %q" , tapIface .Name ))
339
+ multiErr = multierror .Append (multiErr ,
340
+ fmt .Errorf ("failure removing device %q: %w" , tapIface .Name , err ),
341
+ )
340
342
}
341
343
342
344
case * internal.LinkNotFoundError :
@@ -406,7 +408,7 @@ func extractArgs(args string) (map[string]string, error) {
406
408
for _ , pairStr := range argumentsPairs {
407
409
pair := strings .SplitN (pairStr , "=" , 2 )
408
410
if len (pair ) < 2 {
409
- return result , errors .Errorf ("Invalid cni arguments format, %q" , pairStr )
411
+ return result , fmt .Errorf ("Invalid cni arguments format, %q" , pairStr )
410
412
}
411
413
result [pair [0 ]] = pair [1 ]
412
414
}
0 commit comments