Add an ugly way to match whether network is ours to plugin

Docker Plugin V2 does not expose a plugin name to the plugin, so we
check for "net-plugin" within driver name of a network to detect
whether network is ours.
This commit is contained in:
Martynas Pumputis authored and Bryan Boreham committed 2017-04-12 13:05:40 +00:00
1 parent bdfa06dbe9
commit cfe26ae346
2 files changed
+29 -17

No files matched your search

+14 -14
View File
@@ -28,23 +28,23 @@ type network struct {
}
type driver struct {
name string
scope string
docker *docker.Client
dns bool
isPluginV2 bool
sync.RWMutex
networks map[string]network
scope string
docker *docker.Client
dns bool
isPluginV2 bool
networks map[string]network
isNetworkOur func(driverName string) bool
}
func New(client *docker.Client, weave *weaveapi.Client, name, scope string, dns, isPluginV2 bool) (skel.Driver, error) {
func New(client *docker.Client, weave *weaveapi.Client, scope string, dns, isPluginV2 bool, isNetworkOur func(string) bool) (skel.Driver, error) {
driver := &driver{
name: name,
scope: scope,
docker: client,
dns: dns,
isPluginV2: isPluginV2,
networks: make(map[string]network),
scope: scope,
docker: client,
dns: dns,
isPluginV2: isPluginV2,
networks: make(map[string]network),
isNetworkOur: isNetworkOur,
}
_, err := NewWatcher(client, weave, driver)
@@ -193,7 +193,7 @@ func (driver *driver) findNetworkInfo(id string) (network, error) {
if err != nil {
return network, err
}
return driver.setupNetworkInfo(id, info.Driver == driver.name, info.Options)
return driver.setupNetworkInfo(id, driver.isNetworkOur(info.Driver), info.Options)
}
func (driver *driver) setupNetworkInfo(id string, isOurs bool, options map[string]string) (network, error) {
+15 -3
View File
@@ -18,6 +18,8 @@ import (
"github.com/weaveworks/weave/plugin/skel"
)
const pluginV2Name = "net-plugin"
var Log = common.Log
func Start(weaveAPIAddr string, dockerClient *docker.Client, address string, meshAddress string, dns bool, isPluginV2 bool) {
@@ -62,9 +64,19 @@ func run(dockerClient *docker.Client, weave *weaveapi.Client, address, meshAddre
}
func listenAndServe(dockerClient *docker.Client, weave *weaveapi.Client, address string, endChan chan<- error, scope string, withIpam, dns bool, isPluginV2 bool) (net.Listener, error) {
name := strings.TrimSuffix(path.Base(address), ".sock")
// TODO(mp) fix plugin name, as it is used to determine whether network is our
d, err := netplugin.New(dockerClient, weave, name, scope, dns, isPluginV2)
var isNetworkOur func(string) bool
if isPluginV2 {
isNetworkOur = func(driverName string) bool {
return strings.Contains(driverName, pluginV2Name)
}
} else {
name := strings.TrimSuffix(path.Base(address), ".sock")
isNetworkOur = func(driverName string) bool {
return driverName == name
}
}
d, err := netplugin.New(dockerClient, weave, scope, dns, isPluginV2, isNetworkOur)
if err != nil {
return nil, err
}