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:
1 parent
c3c28ea27e
commit
5a6cb8e708
1 file changed
+10
-2
+10
-2
@@ -5,6 +5,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/containernetworking/cni/pkg/ipam"
|
"github.com/containernetworking/cni/pkg/ipam"
|
||||||
@@ -180,8 +181,11 @@ func (c *CNIPlugin) CmdDel(args *skel.CmdArgs) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err = weavenet.WithNetNS(args.Netns, "del-iface", args.IfName); err != nil {
|
// As of CNI 0.3 spec, runtimes can send blank if they just want the address deallocated
|
||||||
return fmt.Errorf("error removing interface %q: %s", args.IfName, err)
|
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
|
// Default IPAM is Weave's own
|
||||||
@@ -190,6 +194,10 @@ 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
|
||||||
|
if args.Netns == "" && strings.Contains(err.Error(), "no addresses") {
|
||||||
|
err = nil
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to release IP address: %s", err)
|
return fmt.Errorf("unable to release IP address: %s", err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user