From 998be42a5203ac61e0df61276563cc01d1c624c4 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Wed, 20 Jan 2016 15:33:23 +0000 Subject: [PATCH 1/3] Don't crash if no default subnet available --- plugin/ipam/driver.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugin/ipam/driver.go b/plugin/ipam/driver.go index 766aa9a1..8cd6142f 100644 --- a/plugin/ipam/driver.go +++ b/plugin/ipam/driver.go @@ -33,6 +33,9 @@ func (i *ipam) RequestPool(addressSpace, pool, subPool string, options map[strin Log.Debugln("RequestPool", addressSpace, pool, subPool, options) cidr, err := i.weave.DefaultSubnet() Log.Debugln("RequestPool returning ", cidr, err) + if err != nil { + return "", nil, nil, err + } // Pass back a fake "gateway address"; we don't actually use it, // so just give the network address. data := map[string]string{netlabel.Gateway: cidr.String()} From a23813061308fc076ef8f35731a5cd5bc44ea7af Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Wed, 20 Jan 2016 15:33:56 +0000 Subject: [PATCH 2/3] Give more explanation if we can't find weave to talk to --- plugin/ipam/driver.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/plugin/ipam/driver.go b/plugin/ipam/driver.go index 8cd6142f..59273d73 100644 --- a/plugin/ipam/driver.go +++ b/plugin/ipam/driver.go @@ -1,10 +1,12 @@ package ipamplugin import ( + "fmt" "net" "github.com/docker/libnetwork/ipamapi" "github.com/docker/libnetwork/netlabel" + godocker "github.com/fsouza/go-dockerclient" "github.com/weaveworks/weave/api" . "github.com/weaveworks/weave/common" "github.com/weaveworks/weave/common/docker" @@ -20,7 +22,13 @@ type ipam struct { } func NewIpam(client *docker.Client, version string) (ipamapi.Ipam, error) { - resolver := func() (string, error) { return client.GetContainerIP(WeaveContainer) } + resolver := func() (string, error) { + addr, err := client.GetContainerIP(WeaveContainer) + if _, ok := err.(*godocker.NoSuchContainer); ok { + return "", fmt.Errorf("%s container is not present. Have you launched it?", WeaveContainer) + } + return addr, err + } return &ipam{client: client, weave: api.NewClientWithResolver(resolver)}, nil } From 6035b542775b78f36e868724e953fcc5679e011b Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Wed, 20 Jan 2016 15:34:34 +0000 Subject: [PATCH 3/3] Send back an http error code in case of error, so Docker is clear something went wrong --- plugin/skel/listener.go | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin/skel/listener.go b/plugin/skel/listener.go index 2b4deb71..afe0584e 100644 --- a/plugin/skel/listener.go +++ b/plugin/skel/listener.go @@ -265,6 +265,7 @@ func sendError(w http.ResponseWriter, msg string, code int) { } func errorResponse(w http.ResponseWriter, fmtString string, item ...interface{}) { + w.WriteHeader(http.StatusInternalServerError) json.NewEncoder(w).Encode(map[string]string{ "Err": fmt.Sprintf(fmtString, item...), })