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:
1 parent
bdfa06dbe9
commit
cfe26ae346
2 files changed
+29
-17
No files matched your search
+14
-14
@@ -28,23 +28,23 @@ type network struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type driver struct {
|
type driver struct {
|
||||||
name string
|
|
||||||
scope string
|
|
||||||
docker *docker.Client
|
|
||||||
dns bool
|
|
||||||
isPluginV2 bool
|
|
||||||
sync.RWMutex
|
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{
|
driver := &driver{
|
||||||
name: name,
|
scope: scope,
|
||||||
scope: scope,
|
docker: client,
|
||||||
docker: client,
|
dns: dns,
|
||||||
dns: dns,
|
isPluginV2: isPluginV2,
|
||||||
isPluginV2: isPluginV2,
|
networks: make(map[string]network),
|
||||||
networks: make(map[string]network),
|
isNetworkOur: isNetworkOur,
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := NewWatcher(client, weave, driver)
|
_, err := NewWatcher(client, weave, driver)
|
||||||
@@ -193,7 +193,7 @@ func (driver *driver) findNetworkInfo(id string) (network, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return network, err
|
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) {
|
func (driver *driver) setupNetworkInfo(id string, isOurs bool, options map[string]string) (network, error) {
|
||||||
|
|||||||
+15
-3
@@ -18,6 +18,8 @@ import (
|
|||||||
"github.com/weaveworks/weave/plugin/skel"
|
"github.com/weaveworks/weave/plugin/skel"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const pluginV2Name = "net-plugin"
|
||||||
|
|
||||||
var Log = common.Log
|
var Log = common.Log
|
||||||
|
|
||||||
func Start(weaveAPIAddr string, dockerClient *docker.Client, address string, meshAddress string, dns bool, isPluginV2 bool) {
|
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) {
|
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")
|
var isNetworkOur func(string) bool
|
||||||
// TODO(mp) fix plugin name, as it is used to determine whether network is our
|
if isPluginV2 {
|
||||||
d, err := netplugin.New(dockerClient, weave, name, scope, dns, 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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user