make plugin pay attention to WEAVE_HTTP_ADDR

This commit is contained in:
Matthias Radestock committed 2016-02-03 11:54:05 +00:00
1 parent dde244160b
commit ae725e333a
5 files changed
+20 -36

No files matched your search

+3 -13
View File
@@ -7,10 +7,8 @@ import (
"github.com/docker/libnetwork/ipamapi" "github.com/docker/libnetwork/ipamapi"
"github.com/docker/libnetwork/netlabel" "github.com/docker/libnetwork/netlabel"
godocker "github.com/fsouza/go-dockerclient"
"github.com/weaveworks/weave/api" "github.com/weaveworks/weave/api"
. "github.com/weaveworks/weave/common" . "github.com/weaveworks/weave/common"
"github.com/weaveworks/weave/common/docker"
) )
const ( const (
@@ -18,19 +16,11 @@ const (
) )
type ipam struct { type ipam struct {
client *docker.Client weave *api.Client
weave *api.Client
} }
func NewIpam(client *docker.Client, version string) (ipamapi.Ipam, error) { func NewIpam(weave *api.Client) ipamapi.Ipam {
resolver := func() (string, error) { return &ipam{weave: weave}
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 (i *ipam) GetDefaultAddressSpaces() (string, string, error) { func (i *ipam) GetDefaultAddressSpaces() (string, string, error) {
+3 -4
View File
@@ -7,6 +7,7 @@ import (
"github.com/docker/libnetwork/drivers/remote/api" "github.com/docker/libnetwork/drivers/remote/api"
"github.com/docker/libnetwork/types" "github.com/docker/libnetwork/types"
weaveapi "github.com/weaveworks/weave/api"
. "github.com/weaveworks/weave/common" . "github.com/weaveworks/weave/common"
"github.com/weaveworks/weave/common/docker" "github.com/weaveworks/weave/common/docker"
"github.com/weaveworks/weave/common/odp" "github.com/weaveworks/weave/common/odp"
@@ -21,22 +22,20 @@ const (
) )
type driver struct { type driver struct {
version string
scope string scope string
noMulticastRoute bool noMulticastRoute bool
sync.RWMutex sync.RWMutex
endpoints map[string]struct{} 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{ driver := &driver{
noMulticastRoute: noMulticastRoute, noMulticastRoute: noMulticastRoute,
version: version,
scope: scope, scope: scope,
endpoints: make(map[string]struct{}), endpoints: make(map[string]struct{}),
} }
_, err := NewWatcher(client, driver) _, err := NewWatcher(client, weave, driver)
if err != nil { if err != nil {
return nil, err return nil, err
} }
+3 -10
View File
@@ -21,16 +21,9 @@ type watcher struct {
type Watcher interface { type Watcher interface {
} }
func NewWatcher(client *docker.Client, driver *driver) (Watcher, error) { func NewWatcher(client *docker.Client, weave *weaveapi.Client, driver *driver) (Watcher, error) {
resolver := func() (string, error) { return client.GetContainerIP(WeaveContainer) } w := &watcher{client: client, weave: weave, driver: driver}
w := &watcher{client: client, driver: driver, return w, client.AddObserver(w)
weave: weaveapi.NewClientWithResolver(resolver)}
err := client.AddObserver(w)
if err != nil {
return nil, err
}
return w, nil
} }
func (w *watcher) ContainerStarted(id string) { func (w *watcher) ContainerStarted(id string) {
+10 -9
View File
@@ -9,6 +9,7 @@ import (
"syscall" "syscall"
"github.com/docker/libnetwork/ipamapi" "github.com/docker/libnetwork/ipamapi"
weaveapi "github.com/weaveworks/weave/api"
. "github.com/weaveworks/weave/common" . "github.com/weaveworks/weave/common"
"github.com/weaveworks/weave/common/docker" "github.com/weaveworks/weave/common/docker"
ipamplugin "github.com/weaveworks/weave/plugin/ipam" ipamplugin "github.com/weaveworks/weave/plugin/ipam"
@@ -48,19 +49,21 @@ func main() {
Log.Fatalf("unable to connect to docker: %s", err) 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.Println("Weave plugin", version, "Command line options:", os.Args[1:])
Log.Info(dockerClient.Info()) Log.Info(dockerClient.Info())
err = run(dockerClient, address, meshAddress, noMulticastRoute) err = run(dockerClient, weave, address, meshAddress, noMulticastRoute)
if err != nil { if err != nil {
Log.Fatal(err) 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) endChan := make(chan error, 1)
if address != "" { if address != "" {
globalListener, err := listenAndServe(dockerClient, address, noMulticastRoute, endChan, "global", false) globalListener, err := listenAndServe(dockerClient, weave, address, noMulticastRoute, endChan, "global", false)
if err != nil { if err != nil {
return err return err
} }
@@ -68,7 +71,7 @@ func run(dockerClient *docker.Client, address, meshAddress string, noMulticastRo
defer globalListener.Close() defer globalListener.Close()
} }
if meshAddress != "" { if meshAddress != "" {
meshListener, err := listenAndServe(dockerClient, meshAddress, noMulticastRoute, endChan, "local", true) meshListener, err := listenAndServe(dockerClient, weave, meshAddress, noMulticastRoute, endChan, "local", true)
if err != nil { if err != nil {
return err 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) { 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, version, scope, noMulticastRoute) d, err := netplugin.New(dockerClient, weave, scope, noMulticastRoute)
if err != nil { if err != nil {
return nil, err return nil, err
} }
var i ipamapi.Ipam var i ipamapi.Ipam
if withIpam { if withIpam {
if i, err = ipamplugin.NewIpam(dockerClient, version); err != nil { i = ipamplugin.NewIpam(weave)
return nil, err
}
} }
var listener net.Listener var listener net.Listener
+1
View File
@@ -1686,6 +1686,7 @@ launch_plugin_if_not_running() {
--net=host \ --net=host \
$(docker_sock_options) \ $(docker_sock_options) \
-v /run/docker/plugins:/run/docker/plugins \ -v /run/docker/plugins:/run/docker/plugins \
-e WEAVE_HTTP_ADDR \
$PLUGIN_IMAGE "$@") ; then $PLUGIN_IMAGE "$@") ; then
return 1 return 1
fi fi