move plugin network removal into weaveutil
This does require starting containerised weaveutil with docker.sock volume mounts.
This commit is contained in:
1 parent
8061ea4079
commit
9578798ec0
4 files changed
+48
-21
No files matched your search
@@ -27,7 +27,6 @@ func main() {
|
|||||||
logLevel string
|
logLevel string
|
||||||
meshNetworkName string
|
meshNetworkName string
|
||||||
noMulticastRoute bool
|
noMulticastRoute bool
|
||||||
removeNetwork bool
|
|
||||||
)
|
)
|
||||||
|
|
||||||
flag.BoolVar(&justVersion, "version", false, "print version and exit")
|
flag.BoolVar(&justVersion, "version", false, "print version and exit")
|
||||||
@@ -37,7 +36,6 @@ func main() {
|
|||||||
flag.StringVar(&meshAddress, "meshsocket", "/run/docker/plugins/weavemesh.sock", "socket on which to listen in mesh mode")
|
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.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.BoolVar(&noMulticastRoute, "no-multicast-route", false, "do not add a multicast route to network endpoints")
|
||||||
flag.BoolVar(&removeNetwork, "remove-network", false, "remove mesh network and exit")
|
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
@@ -54,16 +52,6 @@ func main() {
|
|||||||
Log.Fatalf("unable to connect to docker: %s", err)
|
Log.Fatalf("unable to connect to docker: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if removeNetwork {
|
|
||||||
if _, err = dockerClient.Client.NetworkInfo(meshNetworkName); err == nil {
|
|
||||||
err = dockerClient.Client.RemoveNetwork(meshNetworkName)
|
|
||||||
if err != nil {
|
|
||||||
Log.Fatalf("unable to remove network: %s", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
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())
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ func init() {
|
|||||||
"create-datapath": createDatapath,
|
"create-datapath": createDatapath,
|
||||||
"delete-datapath": deleteDatapath,
|
"delete-datapath": deleteDatapath,
|
||||||
"add-datapath-interface": addDatapathInterface,
|
"add-datapath-interface": addDatapathInterface,
|
||||||
|
"remove-plugin-network": removePluginNetwork,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
/* various weave docker network plugin operations */
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/fsouza/go-dockerclient"
|
||||||
|
)
|
||||||
|
|
||||||
|
func removePluginNetwork(args []string) error {
|
||||||
|
if len(args) != 1 {
|
||||||
|
cmdUsage("remove-plugin-network", "<network-name>")
|
||||||
|
}
|
||||||
|
networkName := args[0]
|
||||||
|
d, err := newDockerClient()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = d.NetworkInfo(networkName)
|
||||||
|
if err != nil {
|
||||||
|
// network probably doesn't exist; TODO check this better
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
err = d.RemoveNetwork(networkName)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to remove network: %s", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func newDockerClient() (*docker.Client, error) {
|
||||||
|
// API 1.21 is the first version that supports docker network
|
||||||
|
// commands
|
||||||
|
c, err := docker.NewVersionedClientFromEnv("1.21")
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("unable to connect to docker: %s", err)
|
||||||
|
}
|
||||||
|
_, err = c.Version()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("unable to connect to docker: %s", err)
|
||||||
|
}
|
||||||
|
return c, nil
|
||||||
|
}
|
||||||
@@ -448,7 +448,8 @@ util_op() {
|
|||||||
if command_exists weaveutil ; then
|
if command_exists weaveutil ; then
|
||||||
weaveutil "$@"
|
weaveutil "$@"
|
||||||
else
|
else
|
||||||
docker run --rm --privileged --net=host -v /proc:/hostproc -e PROCFS=/hostproc \
|
docker run --rm --privileged --net=host $(docker_sock_options) \
|
||||||
|
-v /proc:/hostproc -e PROCFS=/hostproc \
|
||||||
--entrypoint=/usr/bin/weaveutil $EXEC_IMAGE "$@"
|
--entrypoint=/usr/bin/weaveutil $EXEC_IMAGE "$@"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@@ -1694,14 +1695,8 @@ plugin_disabled() {
|
|||||||
[ -n "$WEAVE_NO_PLUGIN" ] || ! check_docker_server_api_version 1.21
|
[ -n "$WEAVE_NO_PLUGIN" ] || ! check_docker_server_api_version 1.21
|
||||||
}
|
}
|
||||||
|
|
||||||
remove_plugin_network() {
|
|
||||||
docker run --rm --net=host \
|
|
||||||
-v /var/run/docker.sock:/var/run/docker.sock \
|
|
||||||
$PLUGIN_IMAGE --remove-network
|
|
||||||
}
|
|
||||||
|
|
||||||
stop_plugin() {
|
stop_plugin() {
|
||||||
remove_plugin_network
|
util_op remove-plugin-network weave
|
||||||
stop $PLUGIN_CONTAINER_NAME "Plugin"
|
stop $PLUGIN_CONTAINER_NAME "Plugin"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2137,7 +2132,7 @@ EOF
|
|||||||
;;
|
;;
|
||||||
reset)
|
reset)
|
||||||
[ $# -eq 0 ] || usage
|
[ $# -eq 0 ] || usage
|
||||||
plugin_disabled || remove_plugin_network || \
|
plugin_disabled || util_op remove-plugin-network weave || \
|
||||||
echo "WARNING: docker may hang in this state; re-launch weave and remove attached containers before shutting down" >&2
|
echo "WARNING: docker may hang in this state; re-launch weave and remove attached containers before shutting down" >&2
|
||||||
warn_if_stopping_proxy_in_env
|
warn_if_stopping_proxy_in_env
|
||||||
call_weave DELETE /peer >/dev/null 2>&1 || true
|
call_weave DELETE /peer >/dev/null 2>&1 || true
|
||||||
|
|||||||
Reference in new issue
Block a user