Pass noDNS and isPluginV2 flags to plugin
- "noDNS" controls whether upon ContainerStarted event a container should be registered within the Weave DNS. - "isPluginV2" will be used to determine a path to host's /proc.
This commit is contained in:
1 parent
332762201a
commit
01bfa602ad
5 files changed
+35
-25
No files matched your search
+12
-8
@@ -28,19 +28,23 @@ type network struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type driver struct {
|
type driver struct {
|
||||||
name string
|
name string
|
||||||
scope string
|
scope string
|
||||||
docker *docker.Client
|
docker *docker.Client
|
||||||
|
noDNS bool
|
||||||
|
isPluginV2 bool
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
networks map[string]network
|
networks map[string]network
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(client *docker.Client, weave *weaveapi.Client, name, scope string) (skel.Driver, error) {
|
func New(client *docker.Client, weave *weaveapi.Client, name, scope string, noDNS, isPluginV2 bool) (skel.Driver, error) {
|
||||||
driver := &driver{
|
driver := &driver{
|
||||||
name: name,
|
name: name,
|
||||||
scope: scope,
|
scope: scope,
|
||||||
docker: client,
|
docker: client,
|
||||||
networks: make(map[string]network),
|
noDNS: noDNS,
|
||||||
|
isPluginV2: isPluginV2,
|
||||||
|
networks: make(map[string]network),
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := NewWatcher(client, weave, driver)
|
_, err := NewWatcher(client, weave, driver)
|
||||||
|
|||||||
@@ -41,9 +41,11 @@ func (w *watcher) ContainerStarted(id string) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if network.isOurs {
|
if network.isOurs {
|
||||||
fqdn := fmt.Sprintf("%s.%s", info.Config.Hostname, info.Config.Domainname)
|
if !w.driver.noDNS {
|
||||||
if err := w.weave.RegisterWithDNS(id, fqdn, net.IPAddress); err != nil {
|
fqdn := fmt.Sprintf("%s.%s", info.Config.Hostname, info.Config.Domainname)
|
||||||
w.driver.warn("ContainerStarted", "unable to register %s with weaveDNS: %s", id, err)
|
if err := w.weave.RegisterWithDNS(id, fqdn, net.IPAddress); err != nil {
|
||||||
|
w.driver.warn("ContainerStarted", "unable to register %s with weaveDNS: %s", id, err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if _, err := weavenet.WithNetNSByPid(info.State.Pid, "configure-arp", weavenet.VethName); err != nil {
|
if _, err := weavenet.WithNetNSByPid(info.State.Pid, "configure-arp", weavenet.VethName); err != nil {
|
||||||
w.driver.warn("ContainerStarted", "unable to configure interfaces: %s", err)
|
w.driver.warn("ContainerStarted", "unable to configure interfaces: %s", err)
|
||||||
|
|||||||
+8
-7
@@ -20,23 +20,23 @@ import (
|
|||||||
|
|
||||||
var Log = common.Log
|
var Log = common.Log
|
||||||
|
|
||||||
func Start(weaveAPIAddr string, dockerClient *docker.Client, address string, meshAddress string) {
|
func Start(weaveAPIAddr string, dockerClient *docker.Client, address string, meshAddress string, noDNS bool, isPluginV2 bool) {
|
||||||
weave := weaveapi.NewClient(weaveAPIAddr, Log)
|
weave := weaveapi.NewClient(weaveAPIAddr, Log)
|
||||||
|
|
||||||
Log.Info("Waiting for Weave API Server...")
|
Log.Info("Waiting for Weave API Server...")
|
||||||
weave.WaitAPIServer(30)
|
weave.WaitAPIServer(30)
|
||||||
Log.Info("Finished waiting for Weave API Server")
|
Log.Info("Finished waiting for Weave API Server")
|
||||||
|
|
||||||
if err := run(dockerClient, weave, address, meshAddress); err != nil {
|
if err := run(dockerClient, weave, address, meshAddress, noDNS, isPluginV2); err != nil {
|
||||||
Log.Fatal(err)
|
Log.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func run(dockerClient *docker.Client, weave *weaveapi.Client, address, meshAddress string) error {
|
func run(dockerClient *docker.Client, weave *weaveapi.Client, address, meshAddress string, noDNS, isPluginV2 bool) error {
|
||||||
endChan := make(chan error, 1)
|
endChan := make(chan error, 1)
|
||||||
|
|
||||||
if address != "" {
|
if address != "" {
|
||||||
globalListener, err := listenAndServe(dockerClient, weave, address, endChan, "global", false)
|
globalListener, err := listenAndServe(dockerClient, weave, address, endChan, "global", false, noDNS, isPluginV2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -44,7 +44,7 @@ func run(dockerClient *docker.Client, weave *weaveapi.Client, address, meshAddre
|
|||||||
defer globalListener.Close()
|
defer globalListener.Close()
|
||||||
}
|
}
|
||||||
if meshAddress != "" {
|
if meshAddress != "" {
|
||||||
meshListener, err := listenAndServe(dockerClient, weave, meshAddress, endChan, "local", true)
|
meshListener, err := listenAndServe(dockerClient, weave, meshAddress, endChan, "local", true, noDNS, isPluginV2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -61,9 +61,10 @@ func run(dockerClient *docker.Client, weave *weaveapi.Client, address, meshAddre
|
|||||||
return <-endChan
|
return <-endChan
|
||||||
}
|
}
|
||||||
|
|
||||||
func listenAndServe(dockerClient *docker.Client, weave *weaveapi.Client, address string, endChan chan<- error, scope string, withIpam bool) (net.Listener, error) {
|
func listenAndServe(dockerClient *docker.Client, weave *weaveapi.Client, address string, endChan chan<- error, scope string, withIpam, noDNS bool, isPluginV2 bool) (net.Listener, error) {
|
||||||
name := strings.TrimSuffix(path.Base(address), ".sock")
|
name := strings.TrimSuffix(path.Base(address), ".sock")
|
||||||
d, err := netplugin.New(dockerClient, weave, name, scope)
|
// TODO(mp) fix plugin name, as it is used to determine whether network is our
|
||||||
|
d, err := netplugin.New(dockerClient, weave, name, scope, noDNS, isPluginV2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ echo "Starting launch.sh"
|
|||||||
# Check if the IP range overlaps anything existing on the host
|
# Check if the IP range overlaps anything existing on the host
|
||||||
/usr/bin/weaveutil netcheck $IPALLOC_RANGE weave
|
/usr/bin/weaveutil netcheck $IPALLOC_RANGE weave
|
||||||
|
|
||||||
|
# TODO(mp) add wait for swarm
|
||||||
|
|
||||||
SWARM_MANAGER_PEERS=$(/usr/bin/weaveutil swarm-manager-peers)
|
SWARM_MANAGER_PEERS=$(/usr/bin/weaveutil swarm-manager-peers)
|
||||||
! /usr/bin/weaveutil is-swarm-manager || IS_SWARM_MANAGER=1
|
! /usr/bin/weaveutil is-swarm-manager || IS_SWARM_MANAGER=1
|
||||||
# Prevent from restoring from a persisted peers list
|
# Prevent from restoring from a persisted peers list
|
||||||
@@ -39,10 +41,9 @@ if [ "$(/home/weave/weave --local bridge-type)" = "bridge" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$IPALLOC_INIT" ]; then
|
if [ -z "$IPALLOC_INIT" ]; then
|
||||||
if [ $IS_SWARM_MANAGER == "1" ]; then
|
IPALLOC_INIT="observer"
|
||||||
|
if [ "$IS_SWARM_MANAGER" == "1" ]; then
|
||||||
IPALLOC_INIT="consensus=$(echo $SWARM_MANAGER_PEERS | wc -l)"
|
IPALLOC_INIT="consensus=$(echo $SWARM_MANAGER_PEERS | wc -l)"
|
||||||
else
|
|
||||||
IPALLOC_INIT="observer"
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -54,6 +55,6 @@ exec /home/weave/weaver $EXTRA_ARGS --port=6783 $BRIDGE_OPTIONS \
|
|||||||
--nickname "$(hostname)" \
|
--nickname "$(hostname)" \
|
||||||
--log-level=debug \
|
--log-level=debug \
|
||||||
--db-prefix="$WEAVE_DIR/weave" \
|
--db-prefix="$WEAVE_DIR/weave" \
|
||||||
--plugin \
|
--plugin-v2 \
|
||||||
--plugin-mesh-socket='' \
|
--plugin-mesh-socket='' \
|
||||||
$(echo $SWARM_MANAGER_PEERS | tr '\n' ' ')
|
$(echo $SWARM_MANAGER_PEERS | tr '\n' ' ')
|
||||||
+5
-3
@@ -154,6 +154,7 @@ func main() {
|
|||||||
pluginSocket string
|
pluginSocket string
|
||||||
pluginMeshSocket string
|
pluginMeshSocket string
|
||||||
enablePlugin bool
|
enablePlugin bool
|
||||||
|
enablePluginV2 bool
|
||||||
|
|
||||||
defaultDockerHost = "unix:///var/run/docker.sock"
|
defaultDockerHost = "unix:///var/run/docker.sock"
|
||||||
)
|
)
|
||||||
@@ -199,7 +200,8 @@ func main() {
|
|||||||
mflag.StringVar(&token, []string{"-token"}, "", "token for peer discovery")
|
mflag.StringVar(&token, []string{"-token"}, "", "token for peer discovery")
|
||||||
mflag.StringVar(&advertiseAddress, []string{"-advertise-address"}, "", "address to advertise for peer discovery")
|
mflag.StringVar(&advertiseAddress, []string{"-advertise-address"}, "", "address to advertise for peer discovery")
|
||||||
|
|
||||||
mflag.BoolVar(&enablePlugin, []string{"-plugin"}, false, "enable Docker plugin")
|
mflag.BoolVar(&enablePlugin, []string{"-plugin"}, false, "enable Docker plugin (v1)")
|
||||||
|
mflag.BoolVar(&enablePluginV2, []string{"-plugin-v2"}, false, "enable Docker plugin (v2)")
|
||||||
mflag.StringVar(&pluginSocket, []string{"-plugin-socket"}, "/run/docker/plugins/weave.sock", "plugin socket on which to listen")
|
mflag.StringVar(&pluginSocket, []string{"-plugin-socket"}, "/run/docker/plugins/weave.sock", "plugin socket on which to listen")
|
||||||
mflag.StringVar(&pluginMeshSocket, []string{"-plugin-mesh-socket"}, "/run/docker/plugins/weavemesh.sock", "plugin socket on which to listen in mesh mode")
|
mflag.StringVar(&pluginMeshSocket, []string{"-plugin-mesh-socket"}, "/run/docker/plugins/weavemesh.sock", "plugin socket on which to listen in mesh mode")
|
||||||
|
|
||||||
@@ -404,8 +406,8 @@ func main() {
|
|||||||
go listenAndServeHTTP(statusAddr, statusMux)
|
go listenAndServeHTTP(statusAddr, statusMux)
|
||||||
}
|
}
|
||||||
|
|
||||||
if enablePlugin {
|
if enablePlugin || enablePluginV2 {
|
||||||
go plugin.Start(httpAddr, dockerCli, pluginSocket, pluginMeshSocket)
|
go plugin.Start(httpAddr, dockerCli, pluginSocket, pluginMeshSocket, noDNS, enablePluginV2)
|
||||||
}
|
}
|
||||||
|
|
||||||
signals.SignalHandlerLoop(common.Log, router)
|
signals.SignalHandlerLoop(common.Log, router)
|
||||||
|
|||||||
Reference in new issue
Block a user