mirror of
https://github.com/rancher/plugins.git
synced 2025-08-11 20:54:11 +00:00
plugins/*: Don't error if the device doesn't exist
I wasn't able to test or update the dhcp plugin but from a code read it should be fine. All the other plugins are tested and fixed
This commit is contained in:
parent
bb322572eb
commit
58b78e72fd
@ -16,6 +16,7 @@ package ip
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
@ -25,6 +26,10 @@ import (
|
|||||||
"github.com/vishvananda/netlink"
|
"github.com/vishvananda/netlink"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
ErrLinkNotFound = errors.New("link not found")
|
||||||
|
)
|
||||||
|
|
||||||
func makeVethPair(name, peer string, mtu int) (netlink.Link, error) {
|
func makeVethPair(name, peer string, mtu int) (netlink.Link, error) {
|
||||||
veth := &netlink.Veth{
|
veth := &netlink.Veth{
|
||||||
LinkAttrs: netlink.LinkAttrs{
|
LinkAttrs: netlink.LinkAttrs{
|
||||||
@ -168,6 +173,9 @@ func DelLinkByName(ifName string) error {
|
|||||||
func DelLinkByNameAddr(ifName string, family int) (*net.IPNet, error) {
|
func DelLinkByNameAddr(ifName string, family int) (*net.IPNet, error) {
|
||||||
iface, err := netlink.LinkByName(ifName)
|
iface, err := netlink.LinkByName(ifName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if err != nil && err.Error() == "Link not found" {
|
||||||
|
return nil, ErrLinkNotFound
|
||||||
|
}
|
||||||
return nil, fmt.Errorf("failed to lookup %q: %v", ifName, err)
|
return nil, fmt.Errorf("failed to lookup %q: %v", ifName, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,6 +127,20 @@ var _ = Describe("Link", func() {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Context("deleting an non-existent device", func() {
|
||||||
|
It("returns known error", func() {
|
||||||
|
_ = containerNetNS.Do(func(ns.NetNS) error {
|
||||||
|
defer GinkgoRecover()
|
||||||
|
|
||||||
|
// This string should match the expected error codes in the cmdDel functions of some of the plugins
|
||||||
|
_, err := ip.DelLinkByNameAddr("THIS_DONT_EXIST", netlink.FAMILY_V4)
|
||||||
|
Expect(err).To(Equal(ip.ErrLinkNotFound))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
Context("when there is no name available for the host-side", func() {
|
Context("when there is no name available for the host-side", func() {
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
//adding different interface to container ns
|
//adding different interface to container ns
|
||||||
|
Loading…
Reference in New Issue
Block a user