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>
| ... | ... |
@@ -29,12 +29,7 @@ func newDriver(name string, client *plugins.Client) driverapi.Driver {
|
| 29 | 29 |
// Init makes sure a remote driver is registered when a network driver |
| 30 | 30 |
// plugin is activated. |
| 31 | 31 |
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) {
|
|
| 38 | 33 |
// negotiate driver capability with client |
| 39 | 34 |
d := newDriver(name, client) |
| 40 | 35 |
c, err := d.(*driver).getCapabilities() |
| ... | ... |
@@ -45,7 +40,19 @@ func Init(dc driverapi.DriverCallback, config map[string]interface{}) error {
|
| 45 | 45 |
if err = dc.RegisterDriver(name, d, *c); err != nil {
|
| 46 | 46 |
logrus.Errorf("error registering driver for %s due to %v", name, err)
|
| 47 | 47 |
} |
| 48 |
- }) |
|
| 48 |
+ } |
|
| 49 |
+ |
|
| 50 |
+ // Unit test code is unaware of a true PluginStore. So we fall back to v1 plugins. |
|
| 51 |
+ handleFunc := plugins.Handle |
|
| 52 |
+ if pg := dc.GetPluginGetter(); pg != nil {
|
|
| 53 |
+ handleFunc = pg.Handle |
|
| 54 |
+ activePlugins, _ := pg.GetAllByCap(driverapi.NetworkPluginEndpointType) |
|
| 55 |
+ for _, ap := range activePlugins {
|
|
| 56 |
+ newPluginHandler(ap.Name(), ap.Client()) |
|
| 57 |
+ } |
|
| 58 |
+ } |
|
| 59 |
+ handleFunc(driverapi.NetworkPluginEndpointType, newPluginHandler) |
|
| 60 |
+ |
|
| 49 | 61 |
return nil |
| 50 | 62 |
} |
| 51 | 63 |
|
| ... | ... |
@@ -31,12 +31,7 @@ func newAllocator(name string, client *plugins.Client) ipamapi.Ipam {
|
| 31 | 31 |
// Init registers a remote ipam when its plugin is activated |
| 32 | 32 |
func Init(cb ipamapi.Callback, l, g interface{}) error {
|
| 33 | 33 |
|
| 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) {
|
|
| 40 | 35 |
a := newAllocator(name, client) |
| 41 | 36 |
if cps, err := a.(*allocator).getCapabilities(); err == nil {
|
| 42 | 37 |
if err := cb.RegisterIpamDriverWithCapabilities(name, a, cps); err != nil {
|
| ... | ... |
@@ -49,7 +44,18 @@ func Init(cb ipamapi.Callback, l, g interface{}) error {
|
| 49 | 49 |
logrus.Errorf("error registering remote ipam driver %s due to %v", name, err)
|
| 50 | 50 |
} |
| 51 | 51 |
} |
| 52 |
- }) |
|
| 52 |
+ } |
|
| 53 |
+ |
|
| 54 |
+ // Unit test code is unaware of a true PluginStore. So we fall back to v1 plugins. |
|
| 55 |
+ handleFunc := plugins.Handle |
|
| 56 |
+ if pg := cb.GetPluginGetter(); pg != nil {
|
|
| 57 |
+ handleFunc = pg.Handle |
|
| 58 |
+ activePlugins, _ := pg.GetAllByCap(ipamapi.PluginEndpointType) |
|
| 59 |
+ for _, ap := range activePlugins {
|
|
| 60 |
+ newPluginHandler(ap.Name(), ap.Client()) |
|
| 61 |
+ } |
|
| 62 |
+ } |
|
| 63 |
+ handleFunc(ipamapi.PluginEndpointType, newPluginHandler) |
|
| 53 | 64 |
return nil |
| 54 | 65 |
} |
| 55 | 66 |
|