From fd0a7efa2305f722907756b76bf21eda177be222 Mon Sep 17 00:00:00 2001 From: Martynas Pumputis Date: Thu, 14 Jul 2016 14:25:22 +0100 Subject: [PATCH] Fix "weave ps" output when weave is not running The #2418 has changed a behaviour of "weave ps" which outputs "Link not found" in the case of weave not running. The previous behaviour was to output an empty line. --- net/netns.go | 6 ++++++ prog/weaveutil/addrs.go | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/net/netns.go b/net/netns.go index b0676909..25e956d0 100644 --- a/net/netns.go +++ b/net/netns.go @@ -1,12 +1,15 @@ package net import ( + "errors" "runtime" "github.com/vishvananda/netlink" "github.com/vishvananda/netns" ) +var ErrLinkNotFound = errors.New("Link not found") + // NB: The following function is unsafe, because: // - It changes a network namespace (netns) of an OS thread which runs // the function. During execution, the Go runtime might clone a new OS thread @@ -42,6 +45,9 @@ func WithNetNSLinkUnsafe(ns netns.NsHandle, ifName string, work func(link netlin return WithNetNSUnsafe(ns, func() error { link, err := netlink.LinkByName(ifName) if err != nil { + if err.Error() == errors.New("Link not found").Error() { + return ErrLinkNotFound + } return err } return work(link) diff --git a/prog/weaveutil/addrs.go b/prog/weaveutil/addrs.go index efdf5357..fdcad785 100644 --- a/prog/weaveutil/addrs.go +++ b/prog/weaveutil/addrs.go @@ -5,7 +5,9 @@ import ( "github.com/fsouza/go-dockerclient" "github.com/vishvananda/netlink" + "github.com/weaveworks/weave/common" + weavenet "github.com/weaveworks/weave/net" ) func containerAddrs(args []string) error { @@ -21,6 +23,9 @@ func containerAddrs(args []string) error { pred, err := common.ConnectedToBridgePredicate(bridgeName) if err != nil { + if err == weavenet.ErrLinkNotFound { + return nil + } return err }