From 5a6cb8e7080350e06ffa297fb3e3d4fc5aa72381 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Wed, 15 Mar 2017 16:20:41 +0000 Subject: [PATCH] Allow CNI netns to be blank on DEL Also don't error on DEL with no namespace and no addresses --- plugin/net/cni.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/plugin/net/cni.go b/plugin/net/cni.go index 5cb47e91..452b1b83 100644 --- a/plugin/net/cni.go +++ b/plugin/net/cni.go @@ -5,6 +5,7 @@ import ( "encoding/json" "fmt" "net" + "strings" "syscall" "github.com/containernetworking/cni/pkg/ipam" @@ -180,8 +181,11 @@ func (c *CNIPlugin) CmdDel(args *skel.CmdArgs) error { return err } - if _, err = weavenet.WithNetNS(args.Netns, "del-iface", args.IfName); err != nil { - return fmt.Errorf("error removing interface %q: %s", args.IfName, err) + // As of CNI 0.3 spec, runtimes can send blank if they just want the address deallocated + if args.Netns != "" { + if _, err = weavenet.WithNetNS(args.Netns, "del-iface", args.IfName); err != nil { + return fmt.Errorf("error removing interface %q: %s", args.IfName, err) + } } // Default IPAM is Weave's own @@ -190,6 +194,10 @@ func (c *CNIPlugin) CmdDel(args *skel.CmdArgs) error { } else { err = ipam.ExecDel(conf.IPAM.Type, args.StdinData) } + // Hack - don't know how we should detect this situation properly + if args.Netns == "" && strings.Contains(err.Error(), "no addresses") { + err = nil + } if err != nil { return fmt.Errorf("unable to release IP address: %s", err) }