diff --git a/plugin/ipam/driver.go b/plugin/ipam/driver.go index 106ba5aa..e4098cf1 100644 --- a/plugin/ipam/driver.go +++ b/plugin/ipam/driver.go @@ -7,10 +7,8 @@ import ( "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" ) const ( @@ -18,19 +16,11 @@ const ( ) type ipam struct { - client *docker.Client - weave *api.Client + weave *api.Client } -func NewIpam(client *docker.Client, version string) (ipamapi.Ipam, error) { - 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 +func NewIpam(weave *api.Client) ipamapi.Ipam { + return &ipam{weave: weave} } func (i *ipam) GetDefaultAddressSpaces() (string, string, error) { diff --git a/plugin/net/driver.go b/plugin/net/driver.go index 0af2c1be..ab292b7e 100644 --- a/plugin/net/driver.go +++ b/plugin/net/driver.go @@ -7,6 +7,7 @@ import ( "github.com/docker/libnetwork/drivers/remote/api" "github.com/docker/libnetwork/types" + weaveapi "github.com/weaveworks/weave/api" . "github.com/weaveworks/weave/common" "github.com/weaveworks/weave/common/docker" "github.com/weaveworks/weave/common/odp" @@ -21,22 +22,20 @@ const ( ) type driver struct { - version string scope string noMulticastRoute bool sync.RWMutex endpoints map[string]struct{} } -func New(client *docker.Client, version string, scope string, noMulticastRoute bool) (skel.Driver, error) { +func New(client *docker.Client, weave *weaveapi.Client, scope string, noMulticastRoute bool) (skel.Driver, error) { driver := &driver{ noMulticastRoute: noMulticastRoute, - version: version, scope: scope, endpoints: make(map[string]struct{}), } - _, err := NewWatcher(client, driver) + _, err := NewWatcher(client, weave, driver) if err != nil { return nil, err } diff --git a/plugin/net/watcher.go b/plugin/net/watcher.go index 935d4ed8..6bcb9ee6 100644 --- a/plugin/net/watcher.go +++ b/plugin/net/watcher.go @@ -21,16 +21,9 @@ type watcher struct { type Watcher interface { } -func NewWatcher(client *docker.Client, driver *driver) (Watcher, error) { - resolver := func() (string, error) { return client.GetContainerIP(WeaveContainer) } - w := &watcher{client: client, driver: driver, - weave: weaveapi.NewClientWithResolver(resolver)} - err := client.AddObserver(w) - if err != nil { - return nil, err - } - - return w, nil +func NewWatcher(client *docker.Client, weave *weaveapi.Client, driver *driver) (Watcher, error) { + w := &watcher{client: client, weave: weave, driver: driver} + return w, client.AddObserver(w) } func (w *watcher) ContainerStarted(id string) { diff --git a/prog/plugin/main.go b/prog/plugin/main.go index 84440fee..846311b4 100644 --- a/prog/plugin/main.go +++ b/prog/plugin/main.go @@ -9,6 +9,7 @@ import ( "syscall" "github.com/docker/libnetwork/ipamapi" + weaveapi "github.com/weaveworks/weave/api" . "github.com/weaveworks/weave/common" "github.com/weaveworks/weave/common/docker" ipamplugin "github.com/weaveworks/weave/plugin/ipam" @@ -48,19 +49,21 @@ func main() { Log.Fatalf("unable to connect to docker: %s", err) } + weave := weaveapi.NewClient(os.Getenv("WEAVE_HTTP_ADDR")) + Log.Println("Weave plugin", version, "Command line options:", os.Args[1:]) Log.Info(dockerClient.Info()) - err = run(dockerClient, address, meshAddress, noMulticastRoute) + err = run(dockerClient, weave, address, meshAddress, noMulticastRoute) if err != nil { Log.Fatal(err) } } -func run(dockerClient *docker.Client, address, meshAddress string, noMulticastRoute bool) error { +func run(dockerClient *docker.Client, weave *weaveapi.Client, address, meshAddress string, noMulticastRoute bool) error { endChan := make(chan error, 1) if address != "" { - globalListener, err := listenAndServe(dockerClient, address, noMulticastRoute, endChan, "global", false) + globalListener, err := listenAndServe(dockerClient, weave, address, noMulticastRoute, endChan, "global", false) if err != nil { return err } @@ -68,7 +71,7 @@ func run(dockerClient *docker.Client, address, meshAddress string, noMulticastRo defer globalListener.Close() } if meshAddress != "" { - meshListener, err := listenAndServe(dockerClient, meshAddress, noMulticastRoute, endChan, "local", true) + meshListener, err := listenAndServe(dockerClient, weave, meshAddress, noMulticastRoute, endChan, "local", true) if err != nil { return err } @@ -88,17 +91,15 @@ func run(dockerClient *docker.Client, address, meshAddress string, noMulticastRo } } -func listenAndServe(dockerClient *docker.Client, address string, noMulticastRoute bool, endChan chan<- error, scope string, withIpam bool) (net.Listener, error) { - d, err := netplugin.New(dockerClient, version, scope, noMulticastRoute) +func listenAndServe(dockerClient *docker.Client, weave *weaveapi.Client, address string, noMulticastRoute bool, endChan chan<- error, scope string, withIpam bool) (net.Listener, error) { + d, err := netplugin.New(dockerClient, weave, scope, noMulticastRoute) if err != nil { return nil, err } var i ipamapi.Ipam if withIpam { - if i, err = ipamplugin.NewIpam(dockerClient, version); err != nil { - return nil, err - } + i = ipamplugin.NewIpam(weave) } var listener net.Listener diff --git a/weave b/weave index 92f77ad6..60cdfb62 100755 --- a/weave +++ b/weave @@ -1686,6 +1686,7 @@ launch_plugin_if_not_running() { --net=host \ $(docker_sock_options) \ -v /run/docker/plugins:/run/docker/plugins \ + -e WEAVE_HTTP_ADDR \ $PLUGIN_IMAGE "$@") ; then return 1 fi