Merge pull request #2928 from weaveworks/issues/2921-ignore-enoent-on-iface-del

Ignore errors on network interface delete during CNI Delete
This commit is contained in:
Bryan Boreham authored and GitHub committed 2017-05-05 20:45:38 +01:00
commit 2c12c4f67e
1 file changed
+14 -10
+14 -10
View File
@@ -6,7 +6,6 @@ import (
"fmt" "fmt"
"net" "net"
"os" "os"
"strings"
"syscall" "syscall"
"github.com/containernetworking/cni/pkg/ipam" "github.com/containernetworking/cni/pkg/ipam"
@@ -183,16 +182,21 @@ func assignBridgeIP(bridgeName string, ipnet net.IPNet) error {
return nil return nil
} }
// As of CNI 0.5 spec:
// "Plugins should generally complete a DEL action without error even if some resources are missing"
// this method should therefore return nil in most, if not all, cases.
func (c *CNIPlugin) CmdDel(args *skel.CmdArgs) error { func (c *CNIPlugin) CmdDel(args *skel.CmdArgs) error {
conf, err := loadNetConf(args.StdinData) conf, err := loadNetConf(args.StdinData)
if err != nil { if err != nil {
return err logOnStderr(err)
return nil
} }
// As of CNI 0.3 spec, runtimes can send blank if they just want the address deallocated // As of CNI 0.3 spec, runtimes can send blank if they just want the address deallocated
if args.Netns != "" { if args.Netns != "" {
if _, err = weavenet.WithNetNS(args.Netns, "del-iface", args.IfName); err != nil { if _, err = weavenet.WithNetNS(args.Netns, "del-iface", args.IfName); err != nil {
return fmt.Errorf("error removing interface %q: %s", args.IfName, err) // We log the error and carry on instead of returning nil, as there may still be resources to free in IPAM.
logOnStderr(fmt.Errorf("error removing interface %q: %s", args.IfName, err))
} }
} }
@@ -202,16 +206,16 @@ func (c *CNIPlugin) CmdDel(args *skel.CmdArgs) error {
} else { } else {
err = ipam.ExecDel(conf.IPAM.Type, args.StdinData) err = ipam.ExecDel(conf.IPAM.Type, args.StdinData)
} }
// Hack - don't know how we should detect this situation properly logOnStderr(fmt.Errorf("unable to release IP address: %s", err))
if args.Netns == "" && strings.Contains(err.Error(), "no addresses") {
err = nil
}
if err != nil {
return fmt.Errorf("unable to release IP address: %s", err)
}
return nil return nil
} }
// Standard error is inherited from the caller (e.g. Kubelet, when running Weave Net's CNI plugin
// under Kubernetes) hence provided errors should eventually appear in the caller's log files.
func logOnStderr(err error) {
fmt.Fprintln(os.Stderr, "weave-cni:", err)
}
type NetConf struct { type NetConf struct {
types.NetConf types.NetConf
BrName string `json:"bridge"` BrName string `json:"bridge"`