Skip to content

Commit

Permalink
netlink.LinkByName: elegant error handling
Browse files Browse the repository at this point in the history
use &netlink.LinkNotFoundError{} handling netlink.LinkByName returned not found error.

Signed-off-by: tanberBro <pengfei.song@daocloud.io>
  • Loading branch information
tanberBro committed Jan 10, 2023
1 parent 5b9188b commit 3127217
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pkg/netns/netns.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package netns

import (
"errors"
"fmt"
"os"
"os/exec"
Expand All @@ -22,7 +23,7 @@ func RemoveIfFromNetNSIfExists(netNS ns.NetNS, ifName string) error {
return netNS.Do(func(_ ns.NetNS) error {
l, err := netlink.LinkByName(ifName)
if err != nil {
if strings.Contains(err.Error(), "Link not found") {
if errors.As(err, &netlink.LinkNotFoundError{}) {
return nil
}
return err
Expand Down

0 comments on commit 3127217

Please sign in to comment.