Allow CNI netns to be blank on DEL

Also don't error on DEL with no namespace and no addresses
This commit is contained in:
Bryan Boreham authored and Marc Carré committed 2017-03-16 18:23:20 +00:00
1 parent c3c28ea27e
commit 5a6cb8e708
1 file changed
+10 -2
+10 -2
View File
@@ -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)
}