diff --git a/libnetwork/drivers/remote/driver.go b/libnetwork/drivers/remote/driver.go index 04be60124f..209a28be52 100644 --- a/libnetwork/drivers/remote/driver.go +++ b/libnetwork/drivers/remote/driver.go @@ -29,12 +29,7 @@ func newDriver(name string, client *plugins.Client) driverapi.Driver { // Init makes sure a remote driver is registered when a network driver // plugin is activated. func Init(dc driverapi.DriverCallback, config map[string]interface{}) error { - // Unit test code is unaware of a true PluginStore. So we fall back to v1 plugins. - handleFunc := plugins.Handle - if pg := dc.GetPluginGetter(); pg != nil { - handleFunc = pg.Handle - } - handleFunc(driverapi.NetworkPluginEndpointType, func(name string, client *plugins.Client) { + newPluginHandler := func(name string, client *plugins.Client) { // negotiate driver capability with client d := newDriver(name, client) c, err := d.(*driver).getCapabilities() @@ -45,7 +40,19 @@ func Init(dc driverapi.DriverCallback, config map[string]interface{}) error { if err = dc.RegisterDriver(name, d, *c); err != nil { logrus.Errorf("error registering driver for %s due to %v", name, err) } - }) + } + + // Unit test code is unaware of a true PluginStore. So we fall back to v1 plugins. + handleFunc := plugins.Handle + if pg := dc.GetPluginGetter(); pg != nil { + handleFunc = pg.Handle + activePlugins, _ := pg.GetAllByCap(driverapi.NetworkPluginEndpointType) + for _, ap := range activePlugins { + newPluginHandler(ap.Name(), ap.Client()) + } + } + handleFunc(driverapi.NetworkPluginEndpointType, newPluginHandler) + return nil } diff --git a/libnetwork/ipams/remote/remote.go b/libnetwork/ipams/remote/remote.go index b23c52a6d0..ecaf10c2f1 100644 --- a/libnetwork/ipams/remote/remote.go +++ b/libnetwork/ipams/remote/remote.go @@ -31,12 +31,7 @@ func newAllocator(name string, client *plugins.Client) ipamapi.Ipam { // Init registers a remote ipam when its plugin is activated func Init(cb ipamapi.Callback, l, g interface{}) error { - // Unit test code is unaware of a true PluginStore. So we fall back to v1 plugins. - handleFunc := plugins.Handle - if pg := cb.GetPluginGetter(); pg != nil { - handleFunc = pg.Handle - } - handleFunc(ipamapi.PluginEndpointType, func(name string, client *plugins.Client) { + newPluginHandler := func(name string, client *plugins.Client) { a := newAllocator(name, client) if cps, err := a.(*allocator).getCapabilities(); err == nil { if err := cb.RegisterIpamDriverWithCapabilities(name, a, cps); err != nil { @@ -49,7 +44,18 @@ func Init(cb ipamapi.Callback, l, g interface{}) error { logrus.Errorf("error registering remote ipam driver %s due to %v", name, err) } } - }) + } + + // Unit test code is unaware of a true PluginStore. So we fall back to v1 plugins. + handleFunc := plugins.Handle + if pg := cb.GetPluginGetter(); pg != nil { + handleFunc = pg.Handle + activePlugins, _ := pg.GetAllByCap(ipamapi.PluginEndpointType) + for _, ap := range activePlugins { + newPluginHandler(ap.Name(), ap.Client()) + } + } + handleFunc(ipamapi.PluginEndpointType, newPluginHandler) return nil }