Skip to content

Commit bc45d84

Browse files
committed
Handle the case of registering active plugins during remote init
With Plugin-V2, plugins can get activated before remote driver is Initialized. Those plugins fails to get registered with drvRegistry. This fix handles that scenario Signed-off-by: Madhu Venugopal <madhu@docker.com>
1 parent fa65450 commit bc45d84

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

libnetwork/drivers/remote/driver.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,7 @@ func newDriver(name string, client *plugins.Client) driverapi.Driver {
2929
// Init makes sure a remote driver is registered when a network driver
3030
// plugin is activated.
3131
func Init(dc driverapi.DriverCallback, config map[string]interface{}) error {
32-
// Unit test code is unaware of a true PluginStore. So we fall back to v1 plugins.
33-
handleFunc := plugins.Handle
34-
if pg := dc.GetPluginGetter(); pg != nil {
35-
handleFunc = pg.Handle
36-
}
37-
handleFunc(driverapi.NetworkPluginEndpointType, func(name string, client *plugins.Client) {
32+
newPluginHandler := func(name string, client *plugins.Client) {
3833
// negotiate driver capability with client
3934
d := newDriver(name, client)
4035
c, err := d.(*driver).getCapabilities()
@@ -45,7 +40,19 @@ func Init(dc driverapi.DriverCallback, config map[string]interface{}) error {
4540
if err = dc.RegisterDriver(name, d, *c); err != nil {
4641
logrus.Errorf("error registering driver for %s due to %v", name, err)
4742
}
48-
})
43+
}
44+
45+
// Unit test code is unaware of a true PluginStore. So we fall back to v1 plugins.
46+
handleFunc := plugins.Handle
47+
if pg := dc.GetPluginGetter(); pg != nil {
48+
handleFunc = pg.Handle
49+
activePlugins, _ := pg.GetAllByCap(driverapi.NetworkPluginEndpointType)
50+
for _, ap := range activePlugins {
51+
newPluginHandler(ap.Name(), ap.Client())
52+
}
53+
}
54+
handleFunc(driverapi.NetworkPluginEndpointType, newPluginHandler)
55+
4956
return nil
5057
}
5158

libnetwork/ipams/remote/remote.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,7 @@ func newAllocator(name string, client *plugins.Client) ipamapi.Ipam {
3131
// Init registers a remote ipam when its plugin is activated
3232
func Init(cb ipamapi.Callback, l, g interface{}) error {
3333

34-
// Unit test code is unaware of a true PluginStore. So we fall back to v1 plugins.
35-
handleFunc := plugins.Handle
36-
if pg := cb.GetPluginGetter(); pg != nil {
37-
handleFunc = pg.Handle
38-
}
39-
handleFunc(ipamapi.PluginEndpointType, func(name string, client *plugins.Client) {
34+
newPluginHandler := func(name string, client *plugins.Client) {
4035
a := newAllocator(name, client)
4136
if cps, err := a.(*allocator).getCapabilities(); err == nil {
4237
if err := cb.RegisterIpamDriverWithCapabilities(name, a, cps); err != nil {
@@ -49,7 +44,18 @@ func Init(cb ipamapi.Callback, l, g interface{}) error {
4944
logrus.Errorf("error registering remote ipam driver %s due to %v", name, err)
5045
}
5146
}
52-
})
47+
}
48+
49+
// Unit test code is unaware of a true PluginStore. So we fall back to v1 plugins.
50+
handleFunc := plugins.Handle
51+
if pg := cb.GetPluginGetter(); pg != nil {
52+
handleFunc = pg.Handle
53+
activePlugins, _ := pg.GetAllByCap(ipamapi.PluginEndpointType)
54+
for _, ap := range activePlugins {
55+
newPluginHandler(ap.Name(), ap.Client())
56+
}
57+
}
58+
handleFunc(ipamapi.PluginEndpointType, newPluginHandler)
5359
return nil
5460
}
5561

0 commit comments

Comments
 (0)