From 31b303a419c2229d9d3a414b88864a15d72a9f79 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Fri, 15 Jan 2016 08:10:01 +0000 Subject: [PATCH] move plugin network creation into weaveutil Note that we remove the ability to set the weavemesh network name, or disabling it altogether. This was always poorly support, since the removal operation only ever operated on the default name. The option was also not listed in the usage, though it was in the docs. --- prog/plugin/main.go | 29 ----------------------------- prog/weaveutil/main.go | 1 + prog/weaveutil/plugin_network.go | 30 ++++++++++++++++++++++++++++++ site/plugin.md | 2 -- weave | 7 +++++-- 5 files changed, 36 insertions(+), 33 deletions(-) diff --git a/prog/plugin/main.go b/prog/plugin/main.go index 62623d84..0415f4c8 100644 --- a/prog/plugin/main.go +++ b/prog/plugin/main.go @@ -5,10 +5,8 @@ import ( "fmt" "net" "os" - "strings" "github.com/docker/libnetwork/ipamapi" - go_docker "github.com/fsouza/go-dockerclient" . "github.com/weaveworks/weave/common" "github.com/weaveworks/weave/common/docker" ipamplugin "github.com/weaveworks/weave/plugin/ipam" @@ -25,7 +23,6 @@ func main() { nameserver string meshAddress string logLevel string - meshNetworkName string noMulticastRoute bool ) @@ -34,7 +31,6 @@ func main() { flag.StringVar(&address, "socket", "/run/docker/plugins/weave.sock", "socket on which to listen") flag.StringVar(&nameserver, "nameserver", "", "nameserver to provide to containers") flag.StringVar(&meshAddress, "meshsocket", "/run/docker/plugins/weavemesh.sock", "socket on which to listen in mesh mode") - flag.StringVar(&meshNetworkName, "mesh-network-name", "weave", "network name to create in mesh mode") flag.BoolVar(&noMulticastRoute, "no-multicast-route", false, "do not add a multicast route to network endpoints") flag.Parse() @@ -72,10 +68,6 @@ func main() { defer meshListener.Close() } - if meshNetworkName != "" { - createNetwork(dockerClient, meshNetworkName, meshAddress) - } - err = <-endChan if err != nil { Log.Errorf("Error from listener: %s", err) @@ -116,24 +108,3 @@ func listenAndServe(dockerClient *docker.Client, address, nameserver string, noM return listener, nil } - -func createNetwork(dockerClient *docker.Client, networkName, address string) { - if _, err := dockerClient.Client.NetworkInfo(networkName); err == nil { - Log.Printf("Docker network '%s' already exists", networkName) - } else if _, ok := err.(*go_docker.NoSuchNetwork); ok { - driverName := strings.TrimSuffix(address, ".sock") - if i := strings.LastIndex(driverName, "/"); i >= 0 { - driverName = driverName[i+1:] - } - options := go_docker.CreateNetworkOptions{ - Name: networkName, - CheckDuplicate: true, - Driver: driverName, - IPAM: go_docker.IPAMOptions{Driver: driverName}, - } - _, err := dockerClient.Client.CreateNetwork(options) - if err != nil { - Log.Fatalf("Error creating network: %s", err) - } - } -} diff --git a/prog/weaveutil/main.go b/prog/weaveutil/main.go index ab2187b0..2cdf02d7 100644 --- a/prog/weaveutil/main.go +++ b/prog/weaveutil/main.go @@ -16,6 +16,7 @@ func init() { "create-datapath": createDatapath, "delete-datapath": deleteDatapath, "add-datapath-interface": addDatapathInterface, + "create-plugin-network": createPluginNetwork, "remove-plugin-network": removePluginNetwork, } } diff --git a/prog/weaveutil/plugin_network.go b/prog/weaveutil/plugin_network.go index 012a2af6..ef9ea04a 100644 --- a/prog/weaveutil/plugin_network.go +++ b/prog/weaveutil/plugin_network.go @@ -7,6 +7,36 @@ import ( "github.com/fsouza/go-dockerclient" ) +func createPluginNetwork(args []string) error { + if len(args) != 2 { + cmdUsage("create-plugin-network", " ") + } + networkName := args[0] + driverName := args[1] + d, err := newDockerClient() + if err != nil { + return err + } + _, err = d.NetworkInfo(networkName) + if err == nil { + return nil + } + if _, ok := err.(*docker.NoSuchNetwork); !ok { + return nil // TODO is this right? + } + _, err = d.CreateNetwork( + docker.CreateNetworkOptions{ + Name: networkName, + CheckDuplicate: true, + Driver: driverName, + IPAM: docker.IPAMOptions{Driver: driverName}, + }) + if err != nil { + return fmt.Errorf("unable to create network: %s", err) + } + return nil +} + func removePluginNetwork(args []string) error { if len(args) != 1 { cmdUsage("remove-plugin-network", "") diff --git a/site/plugin.md b/site/plugin.md index 85ab3b2e..b5b449ee 100644 --- a/site/plugin.md +++ b/site/plugin.md @@ -73,8 +73,6 @@ The plugin command-line arguments are: * `--log-level=debug|info|warning|error`, which tells the plugin how much information to emit for debugging. - * `--mesh-network-name=`: set it to blank to disable creation - of a default network, or a name of your own choice. * `--no-multicast-route`: stop weave adding a static IP route for multicast traffic on its interface diff --git a/weave b/weave index 4ac0b049..2de5a231 100755 --- a/weave +++ b/weave @@ -1683,12 +1683,15 @@ launch_plugin_if_not_running() { # Any other kind of error code from check_not_running is a failure. [ $retval -gt 0 ] && return $retval - PLUGIN_CONTAINER=$(docker run --privileged -d --name=$PLUGIN_CONTAINER_NAME \ + if ! PLUGIN_CONTAINER=$(docker run --privileged -d --name=$PLUGIN_CONTAINER_NAME \ --restart=always \ --net=host \ $(docker_sock_options) \ -v /run/docker/plugins:/run/docker/plugins \ - $PLUGIN_IMAGE "$@") + $PLUGIN_IMAGE "$@") ; then + return 1 + fi + util_op create-plugin-network weave weavemesh } plugin_disabled() {