Skip to content

Commit

Permalink
Allow CNI netns to be blank on DEL
Browse files Browse the repository at this point in the history
Also don't error on DEL with no namespace and no addresses
  • Loading branch information
bboreham committed Mar 15, 2017
1 parent 699bde9 commit b406d11
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions plugin/net/cni.go
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"net"
"strings"
"syscall"

"github.com/containernetworking/cni/pkg/ipam"
Expand Down Expand Up @@ -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
Expand All @@ -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)
}
Expand Down

0 comments on commit b406d11

Please sign in to comment.