17
17
package cni
18
18
19
19
import (
20
+ "fmt"
20
21
"sort"
21
22
"strings"
22
23
23
24
cnilibrary "github.com/containernetworking/cni/libcni"
24
- "github.com/pkg/errors"
25
25
)
26
26
27
27
// Opt sets options for a CNI instance
@@ -204,9 +204,9 @@ func loadFromConfDir(c *libcni, max int) error {
204
204
files , err := cnilibrary .ConfFiles (c .pluginConfDir , []string {".conf" , ".conflist" , ".json" })
205
205
switch {
206
206
case err != nil :
207
- return errors . Wrapf ( ErrRead , "failed to read config file: %v" , err )
207
+ return fmt . Errorf ( "failed to read config file: %v: %w " , err , ErrRead )
208
208
case len (files ) == 0 :
209
- return errors . Wrapf ( ErrCNINotInitialized , "no network config found in %s" , c .pluginConfDir )
209
+ return fmt . Errorf ( "no network config found in %s: %w " , c .pluginConfDir , ErrCNINotInitialized )
210
210
}
211
211
212
212
// files contains the network config files associated with cni network.
@@ -224,26 +224,26 @@ func loadFromConfDir(c *libcni, max int) error {
224
224
if strings .HasSuffix (confFile , ".conflist" ) {
225
225
confList , err = cnilibrary .ConfListFromFile (confFile )
226
226
if err != nil {
227
- return errors . Wrapf ( ErrInvalidConfig , "failed to load CNI config list file %s: %v" , confFile , err )
227
+ return fmt . Errorf ( "failed to load CNI config list file %s: %v: %w " , confFile , err , ErrInvalidConfig )
228
228
}
229
229
} else {
230
230
conf , err := cnilibrary .ConfFromFile (confFile )
231
231
if err != nil {
232
- return errors . Wrapf ( ErrInvalidConfig , "failed to load CNI config file %s: %v" , confFile , err )
232
+ return fmt . Errorf ( "failed to load CNI config file %s: %v: %w " , confFile , err , ErrInvalidConfig )
233
233
}
234
234
// Ensure the config has a "type" so we know what plugin to run.
235
235
// Also catches the case where somebody put a conflist into a conf file.
236
236
if conf .Network .Type == "" {
237
- return errors . Wrapf ( ErrInvalidConfig , "network type not found in %s" , confFile )
237
+ return fmt . Errorf ( "network type not found in %s: %w " , confFile , ErrInvalidConfig )
238
238
}
239
239
240
240
confList , err = cnilibrary .ConfListFromConf (conf )
241
241
if err != nil {
242
- return errors . Wrapf ( ErrInvalidConfig , "failed to convert CNI config file %s to CNI config list: %v" , confFile , err )
242
+ return fmt . Errorf ( "failed to convert CNI config file %s to CNI config list: %v: %w " , confFile , err , ErrInvalidConfig )
243
243
}
244
244
}
245
245
if len (confList .Plugins ) == 0 {
246
- return errors . Wrapf ( ErrInvalidConfig , "CNI config list in config file %s has no networks, skipping" , confFile )
246
+ return fmt . Errorf ( "CNI config list in config file %s has no networks, skipping: %w " , confFile , ErrInvalidConfig )
247
247
248
248
}
249
249
networks = append (networks , & Network {
@@ -257,7 +257,7 @@ func loadFromConfDir(c *libcni, max int) error {
257
257
}
258
258
}
259
259
if len (networks ) == 0 {
260
- return errors . Wrapf ( ErrCNINotInitialized , "no valid networks found in %s" , c .pluginDirs )
260
+ return fmt . Errorf ( "no valid networks found in %s: %w " , c .pluginDirs , ErrCNINotInitialized )
261
261
}
262
262
c .networks = append (c .networks , networks ... )
263
263
return nil
0 commit comments