Skip to content

Commit

Permalink
cnitool: add extra checks for the existence of the NETCONFPATH direct…
Browse files Browse the repository at this point in the history
…ory.

Signed-off-by: Nashwan Azhari <nazhari@cloudbasesolutions.com>
  • Loading branch information
aznashwan committed Nov 23, 2024
1 parent 3b4dfc5 commit f813281
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions cnitool/cnitool.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,23 @@ func main() {
if netdir == "" {
netdir = DefaultNetDir
}

if !filepath.IsAbs(netdir) {
var err error
netdir, err = filepath.Abs(netdir)
if err != nil {
exit(fmt.Errorf("error converting the provided CNI config path ($%s) %q to an absolute path: %s", EnvNetDir, netdir, err))
}
}

if stat, err := os.Stat(netdir); err == nil {
if !stat.IsDir() {
exit(fmt.Errorf("the provided CNI config path ($%s) is not a directory: %q", EnvNetDir, netdir))
}
} else {
exit(fmt.Errorf("the provided CNI config path ($%s) does not exist: %q", EnvNetDir, netdir))
}

netconf, err := libcni.LoadNetworkConf(netdir, os.Args[2])
if err != nil {
exit(err)
Expand Down

0 comments on commit f813281

Please sign in to comment.