diff --git a/plugins/main/vlan/vlan.go b/plugins/main/vlan/vlan.go index 8f4240697..5a19a6e1a 100644 --- a/plugins/main/vlan/vlan.go +++ b/plugins/main/vlan/vlan.go @@ -207,7 +207,7 @@ func cmdDel(args *skel.CmdArgs) error { err = ns.WithNetNSPath(args.Netns, func(_ ns.NetNS) error { err = ip.DelLinkByName(args.IfName) - if err != nil && err != ip.ErrLinkNotFound { + if err != nil && err == ip.ErrLinkNotFound { return nil } return err diff --git a/plugins/main/vlan/vlan_test.go b/plugins/main/vlan/vlan_test.go index 17e4f39df..01b7a7344 100644 --- a/plugins/main/vlan/vlan_test.go +++ b/plugins/main/vlan/vlan_test.go @@ -292,6 +292,19 @@ var _ = Describe("vlan Operations", func() { return nil }) Expect(err).NotTo(HaveOccurred()) + + // DEL can be called multiple times, make sure no error is returned + // if the device is already removed. + err = originalNS.Do(func(ns.NetNS) error { + defer GinkgoRecover() + + err = testutils.CmdDelWithArgs(args, func() error { + return cmdDel(args) + }) + Expect(err).NotTo(HaveOccurred()) + return nil + }) + Expect(err).NotTo(HaveOccurred()) }) It("configures and deconfigures an CNI V4 vlan link with ADD/CHECK/DEL", func() {