Do "docker plugin inspect" inside weaveutil
We cannot do it from weaveexec, because the latter is distributed with an old version of Docker client which does not support Plugins API.
This commit is contained in:
1 parent
b3866ebd94
commit
0ff37d3492
3 files changed
+79
-44
No files matched your search
+26
-25
@@ -14,31 +14,32 @@ var commands map[string]func([]string) error
|
||||
|
||||
func init() {
|
||||
commands = map[string]func([]string) error{
|
||||
"help": help,
|
||||
"netcheck": netcheck,
|
||||
"docker-tls-args": dockerTLSArgs,
|
||||
"create-datapath": createDatapath,
|
||||
"delete-datapath": deleteDatapath,
|
||||
"check-datapath": checkDatapath,
|
||||
"add-datapath-interface": addDatapathInterface,
|
||||
"create-plugin-network": createPluginNetwork,
|
||||
"remove-plugin-network": removePluginNetwork,
|
||||
"container-addrs": containerAddrs,
|
||||
"process-addrs": processAddrs,
|
||||
"attach-container": attach,
|
||||
"detach-container": detach,
|
||||
"configure-arp": configureARP,
|
||||
"check-iface": checkIface,
|
||||
"del-iface": delIface,
|
||||
"setup-iface": setupIface,
|
||||
"list-netdevs": listNetDevs,
|
||||
"cni-net": cniNet,
|
||||
"cni-ipam": cniIPAM,
|
||||
"expose-nat": exposeNAT,
|
||||
"bridge-ip": bridgeIP,
|
||||
"unique-id": uniqueID,
|
||||
"swarm-manager-peers": swarmManagerPeers,
|
||||
"is-swarm-manager": isSwarmManager,
|
||||
"help": help,
|
||||
"netcheck": netcheck,
|
||||
"docker-tls-args": dockerTLSArgs,
|
||||
"create-datapath": createDatapath,
|
||||
"delete-datapath": deleteDatapath,
|
||||
"check-datapath": checkDatapath,
|
||||
"add-datapath-interface": addDatapathInterface,
|
||||
"create-plugin-network": createPluginNetwork,
|
||||
"remove-plugin-network": removePluginNetwork,
|
||||
"container-addrs": containerAddrs,
|
||||
"process-addrs": processAddrs,
|
||||
"attach-container": attach,
|
||||
"detach-container": detach,
|
||||
"configure-arp": configureARP,
|
||||
"check-iface": checkIface,
|
||||
"del-iface": delIface,
|
||||
"setup-iface": setupIface,
|
||||
"list-netdevs": listNetDevs,
|
||||
"cni-net": cniNet,
|
||||
"cni-ipam": cniIPAM,
|
||||
"expose-nat": exposeNAT,
|
||||
"bridge-ip": bridgeIP,
|
||||
"unique-id": uniqueID,
|
||||
"swarm-manager-peers": swarmManagerPeers,
|
||||
"is-swarm-manager": isSwarmManager,
|
||||
"is-docker-plugin-enabled": isDockerPluginEnabled,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/docker/docker/client"
|
||||
docker "github.com/fsouza/go-dockerclient"
|
||||
|
||||
"github.com/weaveworks/weave/plugin/net"
|
||||
@@ -71,6 +73,34 @@ while Weave is not running`, networkName, containers)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Exits with 0 if the given plugin (v2) is enabled.
|
||||
func isDockerPluginEnabled(args []string) error {
|
||||
if len(args) != 1 {
|
||||
cmdUsage("is-docker-plugin-enabled", "<plugin-name>")
|
||||
}
|
||||
|
||||
pluginName := args[0]
|
||||
|
||||
// This is messed up: we are using docker/docker/client instead of
|
||||
// fsouza/go-dockerclient because the latter does not support plugins.
|
||||
c, err := client.NewEnvClient()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to connect to docker: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
p, _, err := c.PluginInspectWithRaw(ctx, pluginName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !p.Enabled {
|
||||
return fmt.Errorf("plugin %q is disabled", pluginName)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func newDockerClient() (*docker.Client, error) {
|
||||
// API 1.21 is the first version that supports docker network
|
||||
// commands
|
||||
@@ -82,5 +112,6 @@ func newDockerClient() (*docker.Client, error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to connect to docker: %s", err)
|
||||
}
|
||||
|
||||
return c, nil
|
||||
}
|
||||
@@ -883,6 +883,24 @@ attach() {
|
||||
util_op attach-container $ATTACH_ARGS $CONTAINER $BRIDGE $MTU "$@"
|
||||
}
|
||||
|
||||
check_not_running_v2_plugin() {
|
||||
if is_docker_plugin_enabled $PLUGIN_V2_NAME; then
|
||||
echo "Docker plugin \"$PLUGIN_V2_NAME\" is already running." >&2
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Docker Plugin V2
|
||||
is_docker_plugin_enabled() {
|
||||
util_op is-docker-plugin-enabled $PLUGIN_V2_NAME 2>/dev/null
|
||||
}
|
||||
|
||||
# Docker Plugin (part of weaver process, so V2 or V1).
|
||||
# Assumes that plugin is running inside Docker container.
|
||||
is_plugin_enabled() {
|
||||
docker inspect -f '{{.Config.Cmd}}' $CONTAINER_NAME | grep -q -- "--plugin"
|
||||
}
|
||||
|
||||
######################################################################
|
||||
# functions for interacting with containers
|
||||
######################################################################
|
||||
@@ -1206,21 +1224,6 @@ check_running() {
|
||||
fi
|
||||
}
|
||||
|
||||
check_not_running_v2_plugin() {
|
||||
is_docker_plugin_enabled "$1" && echo "$1 is already running." >&2 && return 1
|
||||
}
|
||||
|
||||
# Docker Plugin V2
|
||||
is_docker_plugin_enabled() {
|
||||
[ "$(docker plugin inspect -f '{{ .Enabled }}' "$1" 2>/dev/null)" = "true" ]
|
||||
}
|
||||
|
||||
# Docker Plugin (part of weaver process, so V2 or V1).
|
||||
# Assumes that plugin is running inside Docker container.
|
||||
is_plugin_enabled() {
|
||||
docker inspect -f '{{.Config.Cmd}}' $CONTAINER_NAME | grep -q -- "--plugin"
|
||||
}
|
||||
|
||||
# Execute $@ only if the weave container is running
|
||||
when_weave_running() {
|
||||
! check_running $CONTAINER_NAME 2>/dev/null || "$@"
|
||||
@@ -1981,7 +1984,7 @@ EOF
|
||||
deprecation_warnings "$@"
|
||||
check_not_running router $CONTAINER_NAME $BASE_IMAGE
|
||||
check_not_running proxy $PROXY_CONTAINER_NAME $BASE_EXEC_IMAGE
|
||||
check_not_running_v2_plugin "$PLUGIN_V2_NAME"
|
||||
check_not_running_v2_plugin
|
||||
COMMON_ARGS=$(common_launch_args "$@")
|
||||
launch_router --plugin "$@"
|
||||
launch_proxy $COMMON_ARGS
|
||||
@@ -1989,7 +1992,7 @@ EOF
|
||||
launch-router)
|
||||
deprecation_warnings "$@"
|
||||
check_not_running router $CONTAINER_NAME $BASE_IMAGE
|
||||
check_not_running_v2_plugin "$PLUGIN_V2_NAME"
|
||||
check_not_running_v2_plugin
|
||||
launch_router "$@"
|
||||
echo $ROUTER_CONTAINER
|
||||
;;
|
||||
@@ -2007,7 +2010,7 @@ EOF
|
||||
launch-proxy)
|
||||
deprecation_warnings "$@"
|
||||
check_not_running proxy $PROXY_CONTAINER_NAME $BASE_EXEC_IMAGE
|
||||
check_not_running_v2_plugin "$PLUGIN_V2_NAME"
|
||||
check_not_running_v2_plugin
|
||||
launch_proxy "$@"
|
||||
echo $PROXY_CONTAINER
|
||||
;;
|
||||
@@ -2052,7 +2055,7 @@ EOF
|
||||
echo " Service: proxy"
|
||||
echo " Address: $PROXY_ADDRS"
|
||||
fi
|
||||
if [ -z "$SUB_STATUS" ] && ( is_docker_plugin_enabled "$PLUGIN_V2_NAME" || is_plugin_enabled ) ; then
|
||||
if [ -z "$SUB_STATUS" ] && ( is_docker_plugin_enabled || is_plugin_enabled ) ; then
|
||||
echo
|
||||
echo " Service: plugin"
|
||||
echo " DriverName: weave"
|
||||
|
||||
Reference in new issue
Block a user