فهرست منبع

libnetwork: notify another driver registerer

There is no meaningful distinction between driverapi.Registerer and
drvregistry.DriverNotifyFunc. They are both used to register a network
driver with an interested party. They have the same function signature.
The only difference is that the latter could be satisfied by an
anonymous closure. However, in practice the only implementation of
drvregistry.DriverNotifyFunc is the
(*libnetwork.Controller).RegisterDriver method. This same method also
makes the libnetwork.Controller type satisfy the Registerer interface,
therefore the DriverNotifyFunc type is redundant. Change
drvregistry.Networks to notify a Registerer and drop the
DriverNotifyFunc type.

Signed-off-by: Cory Snider <csnider@mirantis.com>
Cory Snider 1 سال پیش
والد
کامیت
a0a8d9d057
2فایلهای تغییر یافته به همراه3 افزوده شده و 6 حذف شده
  1. 1 1
      libnetwork/controller.go
  2. 2 5
      libnetwork/drvregistry/networks.go

+ 1 - 1
libnetwork/controller.go

@@ -124,7 +124,7 @@ func New(cfgOptions ...config.Option) (*Controller, error) {
 		return nil, err
 		return nil, err
 	}
 	}
 
 
-	c.drvRegistry.Notify = c.RegisterDriver
+	c.drvRegistry.Notify = c
 
 
 	// External plugins don't need config passed through daemon. They can
 	// External plugins don't need config passed through daemon. They can
 	// bootstrap themselves.
 	// bootstrap themselves.

+ 2 - 5
libnetwork/drvregistry/networks.go

@@ -11,9 +11,6 @@ import (
 // DriverWalkFunc defines the network driver table walker function signature.
 // DriverWalkFunc defines the network driver table walker function signature.
 type DriverWalkFunc func(name string, driver driverapi.Driver, capability driverapi.Capability) bool
 type DriverWalkFunc func(name string, driver driverapi.Driver, capability driverapi.Capability) bool
 
 
-// DriverNotifyFunc defines the notify function signature when a new network driver gets registered.
-type DriverNotifyFunc func(name string, driver driverapi.Driver, capability driverapi.Capability) error
-
 type driverData struct {
 type driverData struct {
 	driver     driverapi.Driver
 	driver     driverapi.Driver
 	capability driverapi.Capability
 	capability driverapi.Capability
@@ -23,7 +20,7 @@ type driverData struct {
 // driver registry, ready to use.
 // driver registry, ready to use.
 type Networks struct {
 type Networks struct {
 	// Notify is called whenever a network driver is registered.
 	// Notify is called whenever a network driver is registered.
-	Notify DriverNotifyFunc
+	Notify driverapi.Registerer
 
 
 	mu      sync.Mutex
 	mu      sync.Mutex
 	drivers map[string]driverData
 	drivers map[string]driverData
@@ -76,7 +73,7 @@ func (nr *Networks) RegisterDriver(ntype string, driver driverapi.Driver, capabi
 	}
 	}
 
 
 	if nr.Notify != nil {
 	if nr.Notify != nil {
-		if err := nr.Notify(ntype, driver, capability); err != nil {
+		if err := nr.Notify.RegisterDriver(ntype, driver, capability); err != nil {
 			return err
 			return err
 		}
 		}
 	}
 	}