Skip to content
Snippets Groups Projects
Commit c3a23ce2 authored by Valentin Rothberg's avatar Valentin Rothberg
Browse files

use errors.Errorf instead of fmt.Errorf

parent 2ca19cca
No related branches found
No related tags found
No related merge requests found
...@@ -10,9 +10,8 @@ import ( ...@@ -10,9 +10,8 @@ import (
"strings" "strings"
"text/template" "text/template"
"github.com/coreos/go-iptables/iptables"
"github.com/containernetworking/plugins/plugins/ipam/host-local/backend/disk" "github.com/containernetworking/plugins/plugins/ipam/host-local/backend/disk"
"github.com/coreos/go-iptables/iptables"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
......
...@@ -28,7 +28,6 @@ package main ...@@ -28,7 +28,6 @@ package main
import ( import (
"encoding/json" "encoding/json"
"fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"os/exec" "os/exec"
...@@ -52,7 +51,7 @@ func cmdAdd(args *skel.CmdArgs) error { ...@@ -52,7 +51,7 @@ func cmdAdd(args *skel.CmdArgs) error {
return errors.Wrap(err, "failed to parse config") return errors.Wrap(err, "failed to parse config")
} }
if netConf.PrevResult == nil { if netConf.PrevResult == nil {
return fmt.Errorf("must be called as chained plugin") return errors.Errorf("must be called as chained plugin")
} }
ips, err := getIPs(result) ips, err := getIPs(result)
if err != nil { if err != nil {
...@@ -163,7 +162,7 @@ func cmdCheck(args *skel.CmdArgs) error { ...@@ -163,7 +162,7 @@ func cmdCheck(args *skel.CmdArgs) error {
// Ensure we have previous result. // Ensure we have previous result.
if result == nil { if result == nil {
return fmt.Errorf("Required prevResult missing") return errors.Errorf("Required prevResult missing")
} }
dnsNameConf, err := newDNSMasqFile(netConf.DomainName, result.Interfaces[0].Name, netConf.Name) dnsNameConf, err := newDNSMasqFile(netConf.DomainName, result.Interfaces[0].Name, netConf.Name)
if err != nil { if err != nil {
...@@ -191,7 +190,7 @@ func cmdCheck(args *skel.CmdArgs) error { ...@@ -191,7 +190,7 @@ func cmdCheck(args *skel.CmdArgs) error {
// Ensure the dnsmasq instance is running // Ensure the dnsmasq instance is running
if !isRunning(pid) { if !isRunning(pid) {
return fmt.Errorf("dnsmasq instance not running") return errors.Errorf("dnsmasq instance not running")
} }
// Above will make sure the pidfile exists // Above will make sure the pidfile exists
files, err := ioutil.ReadDir(dnsNameConfPath) files, err := ioutil.ReadDir(dnsNameConfPath)
...@@ -202,10 +201,10 @@ func cmdCheck(args *skel.CmdArgs) error { ...@@ -202,10 +201,10 @@ func cmdCheck(args *skel.CmdArgs) error {
conffiles = append(conffiles, f.Name()) conffiles = append(conffiles, f.Name())
} }
if !stringInSlice("addnhosts", conffiles) { if !stringInSlice("addnhosts", conffiles) {
return fmt.Errorf("addnhost file missing from configuration") return errors.Errorf("addnhost file missing from configuration")
} }
if !stringInSlice("dnsmasq.conf", conffiles) { if !stringInSlice("dnsmasq.conf", conffiles) {
return fmt.Errorf("dnsmasq.conf file missing from configuration") return errors.Errorf("dnsmasq.conf file missing from configuration")
} }
return nil return nil
} }
......
package main package main
import ( import (
"fmt"
"net" "net"
"github.com/containernetworking/cni/pkg/types/current" "github.com/containernetworking/cni/pkg/types/current"
"github.com/pkg/errors"
) )
// getIPs iterates a result and returns all the IP addresses // getIPs iterates a result and returns all the IP addresses
...@@ -24,7 +24,7 @@ func getIPs(r *current.Result) ([]*net.IPNet, error) { ...@@ -24,7 +24,7 @@ func getIPs(r *current.Result) ([]*net.IPNet, error) {
if isInterfaceIndexSandox(*ip.Interface, r) { if isInterfaceIndexSandox(*ip.Interface, r) {
ips = append(ips, &ip.Address) ips = append(ips, &ip.Address)
} else { } else {
return nil, fmt.Errorf("unable to check if interface has a sandbox due to index being out of range") return nil, errors.Errorf("unable to check if interface has a sandbox due to index being out of range")
} }
} }
} }
......
...@@ -10,6 +10,7 @@ import ( ...@@ -10,6 +10,7 @@ import (
"strings" "strings"
"syscall" "syscall"
"github.com/pkg/errors"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
) )
...@@ -17,7 +18,7 @@ import ( ...@@ -17,7 +18,7 @@ import (
func newDNSMasqFile(domainName, networkInterface, networkName string) (dnsNameFile, error) { func newDNSMasqFile(domainName, networkInterface, networkName string) (dnsNameFile, error) {
dnsMasqBinary, err := exec.LookPath("dnsmasq") dnsMasqBinary, err := exec.LookPath("dnsmasq")
if err != nil { if err != nil {
return dnsNameFile{}, fmt.Errorf("the dnsmasq cni plugin requires the dnsmasq binary be in PATH") return dnsNameFile{}, errors.Errorf("the dnsmasq cni plugin requires the dnsmasq binary be in PATH")
} }
masqConf := dnsNameFile{ masqConf := dnsNameFile{
ConfigFile: makePath(networkName, confFileName), ConfigFile: makePath(networkName, confFileName),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment