From 1980deffaeed881e04abe48aba6295fd67d84f4a Mon Sep 17 00:00:00 2001 From: Cory Snider Date: Tue, 4 Jul 2023 13:30:54 -0400 Subject: [PATCH 1/2] libn: refactor platform driver registration Hide knowledge of the network driver initializer functions from controller. Signed-off-by: Cory Snider --- libnetwork/controller.go | 11 +----- libnetwork/drivers/bridge/bridge.go | 6 +-- libnetwork/drivers/host/host.go | 10 ++--- libnetwork/drivers/host/host_test.go | 2 +- libnetwork/drivers/ipvlan/ipvlan.go | 6 +-- libnetwork/drivers/macvlan/macvlan.go | 6 +-- libnetwork/drivers/null/null.go | 10 ++--- libnetwork/drivers/null/null_test.go | 2 +- libnetwork/drivers/overlay/overlay.go | 6 +-- .../windows/overlay/overlay_windows.go | 8 ++-- libnetwork/drivers/windows/windows.go | 39 ++++++++++--------- libnetwork/drivers_freebsd.go | 6 +-- libnetwork/drivers_linux.go | 29 +++++++++----- libnetwork/drivers_unsupported.go | 2 +- libnetwork/drivers_windows.go | 27 +++++++------ 15 files changed, 90 insertions(+), 80 deletions(-) diff --git a/libnetwork/controller.go b/libnetwork/controller.go index 6daaec7ce3..279bf15bbc 100644 --- a/libnetwork/controller.go +++ b/libnetwork/controller.go @@ -110,11 +110,6 @@ type Controller struct { mu sync.Mutex } -type initializer struct { - fn func(driverapi.Registerer, map[string]interface{}) error - ntype string -} - // New creates a new instance of network controller. func New(cfgOptions ...config.Option) (*Controller, error) { c := &Controller{ @@ -141,10 +136,8 @@ func New(cfgOptions ...config.Option) (*Controller, error) { return nil, err } - for _, i := range getInitializers() { - if err := i.fn(&c.drvRegistry, c.makeDriverConfig(i.ntype)); err != nil { - return nil, err - } + if err := registerNetworkDrivers(&c.drvRegistry, c.makeDriverConfig); err != nil { + return nil, err } if err := initIPAMDrivers(&c.ipamRegistry, c.cfg.PluginGetter, c.cfg.DefaultAddressPool); err != nil { diff --git a/libnetwork/drivers/bridge/bridge.go b/libnetwork/drivers/bridge/bridge.go index e3039e15dc..639169890e 100644 --- a/libnetwork/drivers/bridge/bridge.go +++ b/libnetwork/drivers/bridge/bridge.go @@ -28,7 +28,7 @@ import ( ) const ( - networkType = "bridge" + NetworkType = "bridge" vethPrefix = "veth" vethLen = len(vethPrefix) + 7 defaultContainerVethPrefix = "eth" @@ -174,7 +174,7 @@ func Register(r driverapi.Registerer, config map[string]interface{}) error { if err := d.configure(config); err != nil { return err } - return r.RegisterDriver(networkType, d, driverapi.Capability{ + return r.RegisterDriver(NetworkType, d, driverapi.Capability{ DataScope: datastore.LocalScope, ConnectivityScope: datastore.LocalScope, }) @@ -1433,7 +1433,7 @@ func (d *driver) link(network *bridgeNetwork, endpoint *bridgeEndpoint, enable b } func (d *driver) Type() string { - return networkType + return NetworkType } func (d *driver) IsBuiltIn() bool { diff --git a/libnetwork/drivers/host/host.go b/libnetwork/drivers/host/host.go index 9eb596ce14..7681541066 100644 --- a/libnetwork/drivers/host/host.go +++ b/libnetwork/drivers/host/host.go @@ -9,7 +9,7 @@ import ( "github.com/docker/docker/libnetwork/types" ) -const networkType = "host" +const NetworkType = "host" type driver struct { network string @@ -24,7 +24,7 @@ func Init(dc driverapi.DriverCallback, _ map[string]interface{}) error { } func Register(r driverapi.Registerer, _ map[string]interface{}) error { - return r.RegisterDriver(networkType, &driver{}, driverapi.Capability{ + return r.RegisterDriver(NetworkType, &driver{}, driverapi.Capability{ DataScope: datastore.LocalScope, ConnectivityScope: datastore.LocalScope, }) @@ -50,7 +50,7 @@ func (d *driver) CreateNetwork(id string, option map[string]interface{}, nInfo d defer d.Unlock() if d.network != "" { - return types.ForbiddenErrorf("only one instance of \"%s\" network is allowed", networkType) + return types.ForbiddenErrorf("only one instance of \"%s\" network is allowed", NetworkType) } d.network = id @@ -59,7 +59,7 @@ func (d *driver) CreateNetwork(id string, option map[string]interface{}, nInfo d } func (d *driver) DeleteNetwork(nid string) error { - return types.ForbiddenErrorf("network of type \"%s\" cannot be deleted", networkType) + return types.ForbiddenErrorf("network of type \"%s\" cannot be deleted", NetworkType) } func (d *driver) CreateEndpoint(nid, eid string, ifInfo driverapi.InterfaceInfo, epOptions map[string]interface{}) error { @@ -93,7 +93,7 @@ func (d *driver) RevokeExternalConnectivity(nid, eid string) error { } func (d *driver) Type() string { - return networkType + return NetworkType } func (d *driver) IsBuiltIn() bool { diff --git a/libnetwork/drivers/host/host_test.go b/libnetwork/drivers/host/host_test.go index caa77df7c5..29aad9483e 100644 --- a/libnetwork/drivers/host/host_test.go +++ b/libnetwork/drivers/host/host_test.go @@ -9,7 +9,7 @@ import ( func TestDriver(t *testing.T) { d := &driver{} - if d.Type() != networkType { + if d.Type() != NetworkType { t.Fatal("Unexpected network type returned by driver") } diff --git a/libnetwork/drivers/ipvlan/ipvlan.go b/libnetwork/drivers/ipvlan/ipvlan.go index c61ebe6a76..84d7822cf3 100644 --- a/libnetwork/drivers/ipvlan/ipvlan.go +++ b/libnetwork/drivers/ipvlan/ipvlan.go @@ -18,7 +18,7 @@ const ( vethPrefix = "veth" vethLen = len(vethPrefix) + 7 - driverName = "ipvlan" // driver type name + NetworkType = "ipvlan" // driver type name parentOpt = "parent" // parent interface -o parent driverModeOpt = "ipvlan_mode" // mode -o ipvlan_mode driverFlagOpt = "ipvlan_flag" // flag -o ipvlan_flag @@ -70,7 +70,7 @@ func Register(r driverapi.Registerer, config map[string]interface{}) error { if err := d.initStore(config); err != nil { return err } - return r.RegisterDriver(driverName, d, driverapi.Capability{ + return r.RegisterDriver(NetworkType, d, driverapi.Capability{ DataScope: datastore.LocalScope, ConnectivityScope: datastore.GlobalScope, }) @@ -89,7 +89,7 @@ func (d *driver) EndpointOperInfo(nid, eid string) (map[string]interface{}, erro } func (d *driver) Type() string { - return driverName + return NetworkType } func (d *driver) IsBuiltIn() bool { diff --git a/libnetwork/drivers/macvlan/macvlan.go b/libnetwork/drivers/macvlan/macvlan.go index a8216413b5..a5c9121835 100644 --- a/libnetwork/drivers/macvlan/macvlan.go +++ b/libnetwork/drivers/macvlan/macvlan.go @@ -17,7 +17,7 @@ const ( containerVethPrefix = "eth" vethPrefix = "veth" vethLen = len(vethPrefix) + 7 - driverName = "macvlan" // driver type name + NetworkType = "macvlan" // driver type name modePrivate = "private" // macvlan mode private modeVepa = "vepa" // macvlan mode vepa modeBridge = "bridge" // macvlan mode bridge @@ -64,7 +64,7 @@ func Register(r driverapi.Registerer, config map[string]interface{}) error { if err := d.initStore(config); err != nil { return err } - return r.RegisterDriver(driverName, d, driverapi.Capability{ + return r.RegisterDriver(NetworkType, d, driverapi.Capability{ DataScope: datastore.LocalScope, ConnectivityScope: datastore.GlobalScope, }) @@ -83,7 +83,7 @@ func (d *driver) EndpointOperInfo(nid, eid string) (map[string]interface{}, erro } func (d *driver) Type() string { - return driverName + return NetworkType } func (d *driver) IsBuiltIn() bool { diff --git a/libnetwork/drivers/null/null.go b/libnetwork/drivers/null/null.go index b226e5032b..e275cf33b9 100644 --- a/libnetwork/drivers/null/null.go +++ b/libnetwork/drivers/null/null.go @@ -9,7 +9,7 @@ import ( "github.com/docker/docker/libnetwork/types" ) -const networkType = "null" +const NetworkType = "null" type driver struct { network string @@ -18,7 +18,7 @@ type driver struct { // Register registers a new instance of the null driver. func Register(r driverapi.Registerer, _ map[string]interface{}) error { - return r.RegisterDriver(networkType, &driver{}, driverapi.Capability{ + return r.RegisterDriver(NetworkType, &driver{}, driverapi.Capability{ DataScope: datastore.LocalScope, }) } @@ -43,7 +43,7 @@ func (d *driver) CreateNetwork(id string, option map[string]interface{}, nInfo d defer d.Unlock() if d.network != "" { - return types.ForbiddenErrorf("only one instance of \"%s\" network is allowed", networkType) + return types.ForbiddenErrorf("only one instance of \"%s\" network is allowed", NetworkType) } d.network = id @@ -52,7 +52,7 @@ func (d *driver) CreateNetwork(id string, option map[string]interface{}, nInfo d } func (d *driver) DeleteNetwork(nid string) error { - return types.ForbiddenErrorf("network of type \"%s\" cannot be deleted", networkType) + return types.ForbiddenErrorf("network of type \"%s\" cannot be deleted", NetworkType) } func (d *driver) CreateEndpoint(nid, eid string, ifInfo driverapi.InterfaceInfo, epOptions map[string]interface{}) error { @@ -86,7 +86,7 @@ func (d *driver) RevokeExternalConnectivity(nid, eid string) error { } func (d *driver) Type() string { - return networkType + return NetworkType } func (d *driver) IsBuiltIn() bool { diff --git a/libnetwork/drivers/null/null_test.go b/libnetwork/drivers/null/null_test.go index 1c76d3760b..fe1cd59d81 100644 --- a/libnetwork/drivers/null/null_test.go +++ b/libnetwork/drivers/null/null_test.go @@ -9,7 +9,7 @@ import ( func TestDriver(t *testing.T) { d := &driver{} - if d.Type() != networkType { + if d.Type() != NetworkType { t.Fatalf("Unexpected network type returned by driver") } diff --git a/libnetwork/drivers/overlay/overlay.go b/libnetwork/drivers/overlay/overlay.go index 48a5d2e9ea..2d6a82d401 100644 --- a/libnetwork/drivers/overlay/overlay.go +++ b/libnetwork/drivers/overlay/overlay.go @@ -16,7 +16,7 @@ import ( ) const ( - networkType = "overlay" + NetworkType = "overlay" vethPrefix = "veth" vethLen = len(vethPrefix) + 7 vxlanEncap = 50 @@ -47,7 +47,7 @@ func Register(r driverapi.Registerer, config map[string]interface{}) error { secMap: &encrMap{nodes: map[string][]*spi{}}, config: config, } - return r.RegisterDriver(networkType, d, driverapi.Capability{ + return r.RegisterDriver(NetworkType, d, driverapi.Capability{ DataScope: datastore.GlobalScope, ConnectivityScope: datastore.GlobalScope, }) @@ -61,7 +61,7 @@ func (d *driver) configure() error { } func (d *driver) Type() string { - return networkType + return NetworkType } func (d *driver) IsBuiltIn() bool { diff --git a/libnetwork/drivers/windows/overlay/overlay_windows.go b/libnetwork/drivers/windows/overlay/overlay_windows.go index 96baea2cd7..73c2e722de 100644 --- a/libnetwork/drivers/windows/overlay/overlay_windows.go +++ b/libnetwork/drivers/windows/overlay/overlay_windows.go @@ -17,7 +17,7 @@ import ( ) const ( - networkType = "overlay" + NetworkType = "overlay" ) type driver struct { @@ -33,7 +33,7 @@ func Register(r driverapi.Registerer, _ map[string]interface{}) error { d.restoreHNSNetworks() - return r.RegisterDriver(networkType, d, driverapi.Capability{ + return r.RegisterDriver(NetworkType, d, driverapi.Capability{ DataScope: datastore.GlobalScope, ConnectivityScope: datastore.GlobalScope, }) @@ -48,7 +48,7 @@ func (d *driver) restoreHNSNetworks() error { } for _, v := range hnsresponse { - if v.Type != networkType { + if v.Type != NetworkType { continue } @@ -105,7 +105,7 @@ func (d *driver) convertToOverlayNetwork(v *hcsshim.HNSNetwork) *network { } func (d *driver) Type() string { - return networkType + return NetworkType } func (d *driver) IsBuiltIn() bool { diff --git a/libnetwork/drivers/windows/windows.go b/libnetwork/drivers/windows/windows.go index 4f01f074a9..e18cc8a83b 100644 --- a/libnetwork/drivers/windows/windows.go +++ b/libnetwork/drivers/windows/windows.go @@ -109,16 +109,20 @@ const ( errNotFound = "HNS failed with error : The object identifier does not represent a valid object. " ) +var builtinLocalDrivers = map[string]struct{}{ + "transparent": {}, + "l2bridge": {}, + "l2tunnel": {}, + "nat": {}, + "internal": {}, + "private": {}, + "ics": {}, +} + // IsBuiltinLocalDriver validates if network-type is a builtin local-scoped driver func IsBuiltinLocalDriver(networkType string) bool { - if "l2bridge" == networkType || "l2tunnel" == networkType || - "nat" == networkType || "ics" == networkType || - "transparent" == networkType || "internal" == networkType || - "private" == networkType { - return true - } - - return false + _, ok := builtinLocalDrivers[networkType] + return ok } // New constructs a new bridge driver @@ -127,24 +131,23 @@ func newDriver(networkType string) *driver { } // GetInit returns an initializer for the given network type -func GetInit(networkType string) func(dc driverapi.Registerer, config map[string]interface{}) error { - return func(dc driverapi.Registerer, config map[string]interface{}) error { - if !IsBuiltinLocalDriver(networkType) { - return types.BadRequestErrorf("Network type not supported: %s", networkType) - } - +func RegisterBuiltinLocalDrivers(r driverapi.Registerer, driverConfig func(string) map[string]interface{}) error { + for networkType := range builtinLocalDrivers { d := newDriver(networkType) - - err := d.initStore(config) + err := d.initStore(driverConfig(networkType)) if err != nil { - return err + return fmt.Errorf("failed to initialize %q driver: %w", networkType, err) } - return dc.RegisterDriver(networkType, d, driverapi.Capability{ + err = r.RegisterDriver(networkType, d, driverapi.Capability{ DataScope: datastore.LocalScope, ConnectivityScope: datastore.LocalScope, }) + if err != nil { + return fmt.Errorf("failed to register %q driver: %w", networkType, err) + } } + return nil } func (d *driver) getNetwork(id string) (*hnsNetwork, error) { diff --git a/libnetwork/drivers_freebsd.go b/libnetwork/drivers_freebsd.go index f1a06f698c..937115690a 100644 --- a/libnetwork/drivers_freebsd.go +++ b/libnetwork/drivers_freebsd.go @@ -4,8 +4,6 @@ import ( "github.com/docker/docker/libnetwork/drivers/null" ) -func getInitializers() []initializer { - return []initializer{ - {null.Register, "null"}, - } +func registerNetworkDrivers(r driverapi.Registerer, driverConfig func(string) map[string]interface{}) error { + return null.Register(r, driverConfig(null.NetworkType)) } diff --git a/libnetwork/drivers_linux.go b/libnetwork/drivers_linux.go index 553b0d9e2d..a179d668c8 100644 --- a/libnetwork/drivers_linux.go +++ b/libnetwork/drivers_linux.go @@ -1,6 +1,9 @@ package libnetwork import ( + "fmt" + + "github.com/docker/docker/libnetwork/driverapi" "github.com/docker/docker/libnetwork/drivers/bridge" "github.com/docker/docker/libnetwork/drivers/host" "github.com/docker/docker/libnetwork/drivers/ipvlan" @@ -9,14 +12,22 @@ import ( "github.com/docker/docker/libnetwork/drivers/overlay" ) -func getInitializers() []initializer { - in := []initializer{ - {bridge.Register, "bridge"}, - {host.Register, "host"}, - {ipvlan.Register, "ipvlan"}, - {macvlan.Register, "macvlan"}, - {null.Register, "null"}, - {overlay.Register, "overlay"}, +func registerNetworkDrivers(r driverapi.Registerer, driverConfig func(string) map[string]interface{}) error { + for _, nr := range []struct { + ntype string + register func(driverapi.Registerer, map[string]interface{}) error + }{ + {ntype: bridge.NetworkType, register: bridge.Register}, + {ntype: host.NetworkType, register: host.Register}, + {ntype: ipvlan.NetworkType, register: ipvlan.Register}, + {ntype: macvlan.NetworkType, register: macvlan.Register}, + {ntype: null.NetworkType, register: null.Register}, + {ntype: overlay.NetworkType, register: overlay.Register}, + } { + if err := nr.register(r, driverConfig(nr.ntype)); err != nil { + return fmt.Errorf("failed to register %q driver: %w", nr.ntype, err) + } } - return in + + return nil } diff --git a/libnetwork/drivers_unsupported.go b/libnetwork/drivers_unsupported.go index 3157a4a32e..f99448f360 100644 --- a/libnetwork/drivers_unsupported.go +++ b/libnetwork/drivers_unsupported.go @@ -2,6 +2,6 @@ package libnetwork -func getInitializers() []initializer { +func registerNetworkDrivers(r driverapi.Registerer, driverConfig func(string) map[string]interface{}) error { return nil } diff --git a/libnetwork/drivers_windows.go b/libnetwork/drivers_windows.go index e5ec388091..f104ed88c1 100644 --- a/libnetwork/drivers_windows.go +++ b/libnetwork/drivers_windows.go @@ -1,21 +1,26 @@ package libnetwork import ( + "fmt" + + "github.com/docker/docker/libnetwork/driverapi" "github.com/docker/docker/libnetwork/drivers/null" "github.com/docker/docker/libnetwork/drivers/windows" "github.com/docker/docker/libnetwork/drivers/windows/overlay" ) -func getInitializers() []initializer { - return []initializer{ - {null.Register, "null"}, - {overlay.Register, "overlay"}, - {windows.GetInit("transparent"), "transparent"}, - {windows.GetInit("l2bridge"), "l2bridge"}, - {windows.GetInit("l2tunnel"), "l2tunnel"}, - {windows.GetInit("nat"), "nat"}, - {windows.GetInit("internal"), "internal"}, - {windows.GetInit("private"), "private"}, - {windows.GetInit("ics"), "ics"}, +func registerNetworkDrivers(r driverapi.Registerer, driverConfig func(string) map[string]interface{}) error { + for _, nr := range []struct { + ntype string + register func(driverapi.Registerer, map[string]interface{}) error + }{ + {ntype: null.NetworkType, register: null.Register}, + {ntype: overlay.NetworkType, register: overlay.Register}, + } { + if err := nr.register(r, driverConfig(nr.ntype)); err != nil { + return fmt.Errorf("failed to register %q driver: %w", nr.ntype, err) + } } + + return windows.RegisterBuiltinLocalDrivers(r, driverConfig) } From d519bde5daf8562a947df4a55731c48e86a5f3f4 Mon Sep 17 00:00:00 2001 From: Cory Snider Date: Tue, 4 Jul 2023 13:43:16 -0400 Subject: [PATCH 2/2] libnet/drivers: stop passing config to drivers... ...which ignore the config argument. Notably, none of the network drivers referenced by Swarmkit use config, which is good as Swarmkit unconditionally passes nil for the config when registering drivers. Signed-off-by: Cory Snider --- libnetwork/drivers/bridge/brmanager/brmanager.go | 4 ++-- libnetwork/drivers/host/host.go | 4 ++-- libnetwork/drivers/ipvlan/ivmanager/ivmanager.go | 4 ++-- libnetwork/drivers/macvlan/mvmanager/mvmanager.go | 4 ++-- libnetwork/drivers/null/null.go | 2 +- libnetwork/drivers/overlay/ovmanager/ovmanager.go | 4 ++-- libnetwork/drivers/windows/overlay/overlay_windows.go | 2 +- libnetwork/drivers_freebsd.go | 2 +- libnetwork/drivers_linux.go | 8 ++++++-- libnetwork/drivers_windows.go | 4 ++-- 10 files changed, 21 insertions(+), 17 deletions(-) diff --git a/libnetwork/drivers/bridge/brmanager/brmanager.go b/libnetwork/drivers/bridge/brmanager/brmanager.go index 22922d8253..e90d6febf6 100644 --- a/libnetwork/drivers/bridge/brmanager/brmanager.go +++ b/libnetwork/drivers/bridge/brmanager/brmanager.go @@ -15,11 +15,11 @@ type driver struct{} // // Deprecated: use [Register]. func Init(dc driverapi.DriverCallback, _ map[string]interface{}) error { - return Register(dc, nil) + return Register(dc) } // Register registers a new instance of the bridge manager driver with r. -func Register(r driverapi.Registerer, _ map[string]interface{}) error { +func Register(r driverapi.Registerer) error { return r.RegisterDriver(networkType, &driver{}, driverapi.Capability{ DataScope: datastore.LocalScope, ConnectivityScope: datastore.LocalScope, diff --git a/libnetwork/drivers/host/host.go b/libnetwork/drivers/host/host.go index 7681541066..ee9adbc4d8 100644 --- a/libnetwork/drivers/host/host.go +++ b/libnetwork/drivers/host/host.go @@ -20,10 +20,10 @@ type driver struct { // // Deprecated: use [Register]. func Init(dc driverapi.DriverCallback, _ map[string]interface{}) error { - return Register(dc, nil) + return Register(dc) } -func Register(r driverapi.Registerer, _ map[string]interface{}) error { +func Register(r driverapi.Registerer) error { return r.RegisterDriver(NetworkType, &driver{}, driverapi.Capability{ DataScope: datastore.LocalScope, ConnectivityScope: datastore.LocalScope, diff --git a/libnetwork/drivers/ipvlan/ivmanager/ivmanager.go b/libnetwork/drivers/ipvlan/ivmanager/ivmanager.go index e7e5a285d2..d3d841ecb3 100644 --- a/libnetwork/drivers/ipvlan/ivmanager/ivmanager.go +++ b/libnetwork/drivers/ipvlan/ivmanager/ivmanager.go @@ -15,11 +15,11 @@ type driver struct{} // // Deprecated: use [Register]. func Init(dc driverapi.DriverCallback, _ map[string]interface{}) error { - return Register(dc, nil) + return Register(dc) } // Register registers a new instance of the ipvlan manager driver. -func Register(r driverapi.Registerer, _ map[string]interface{}) error { +func Register(r driverapi.Registerer) error { return r.RegisterDriver(networkType, &driver{}, driverapi.Capability{ DataScope: datastore.LocalScope, ConnectivityScope: datastore.GlobalScope, diff --git a/libnetwork/drivers/macvlan/mvmanager/mvmanager.go b/libnetwork/drivers/macvlan/mvmanager/mvmanager.go index ba69cd933f..b490c6769e 100644 --- a/libnetwork/drivers/macvlan/mvmanager/mvmanager.go +++ b/libnetwork/drivers/macvlan/mvmanager/mvmanager.go @@ -15,11 +15,11 @@ type driver struct{} // // Deprecated: use [Register]. func Init(dc driverapi.DriverCallback, _ map[string]interface{}) error { - return Register(dc, nil) + return Register(dc) } // Register registers a new instance of the macvlan manager driver. -func Register(r driverapi.Registerer, _ map[string]interface{}) error { +func Register(r driverapi.Registerer) error { return r.RegisterDriver(networkType, &driver{}, driverapi.Capability{ DataScope: datastore.LocalScope, ConnectivityScope: datastore.GlobalScope, diff --git a/libnetwork/drivers/null/null.go b/libnetwork/drivers/null/null.go index e275cf33b9..6246231df9 100644 --- a/libnetwork/drivers/null/null.go +++ b/libnetwork/drivers/null/null.go @@ -17,7 +17,7 @@ type driver struct { } // Register registers a new instance of the null driver. -func Register(r driverapi.Registerer, _ map[string]interface{}) error { +func Register(r driverapi.Registerer) error { return r.RegisterDriver(NetworkType, &driver{}, driverapi.Capability{ DataScope: datastore.LocalScope, }) diff --git a/libnetwork/drivers/overlay/ovmanager/ovmanager.go b/libnetwork/drivers/overlay/ovmanager/ovmanager.go index 127496dfba..256de20207 100644 --- a/libnetwork/drivers/overlay/ovmanager/ovmanager.go +++ b/libnetwork/drivers/overlay/ovmanager/ovmanager.go @@ -50,11 +50,11 @@ type network struct { // // Deprecated: use [Register]. func Init(dc driverapi.DriverCallback, _ map[string]interface{}) error { - return Register(dc, nil) + return Register(dc) } // Register registers a new instance of the overlay driver. -func Register(r driverapi.Registerer, _ map[string]interface{}) error { +func Register(r driverapi.Registerer) error { return r.RegisterDriver(networkType, newDriver(), driverapi.Capability{ DataScope: datastore.GlobalScope, ConnectivityScope: datastore.GlobalScope, diff --git a/libnetwork/drivers/windows/overlay/overlay_windows.go b/libnetwork/drivers/windows/overlay/overlay_windows.go index 73c2e722de..ba02d251d2 100644 --- a/libnetwork/drivers/windows/overlay/overlay_windows.go +++ b/libnetwork/drivers/windows/overlay/overlay_windows.go @@ -26,7 +26,7 @@ type driver struct { } // Register registers a new instance of the overlay driver. -func Register(r driverapi.Registerer, _ map[string]interface{}) error { +func Register(r driverapi.Registerer) error { d := &driver{ networks: networkTable{}, } diff --git a/libnetwork/drivers_freebsd.go b/libnetwork/drivers_freebsd.go index 937115690a..b0e19ea911 100644 --- a/libnetwork/drivers_freebsd.go +++ b/libnetwork/drivers_freebsd.go @@ -5,5 +5,5 @@ import ( ) func registerNetworkDrivers(r driverapi.Registerer, driverConfig func(string) map[string]interface{}) error { - return null.Register(r, driverConfig(null.NetworkType)) + return null.Register(r) } diff --git a/libnetwork/drivers_linux.go b/libnetwork/drivers_linux.go index a179d668c8..59b3f4e731 100644 --- a/libnetwork/drivers_linux.go +++ b/libnetwork/drivers_linux.go @@ -13,15 +13,19 @@ import ( ) func registerNetworkDrivers(r driverapi.Registerer, driverConfig func(string) map[string]interface{}) error { + noConfig := func(fn func(driverapi.Registerer) error) func(driverapi.Registerer, map[string]interface{}) error { + return func(r driverapi.Registerer, _ map[string]interface{}) error { return fn(r) } + } + for _, nr := range []struct { ntype string register func(driverapi.Registerer, map[string]interface{}) error }{ {ntype: bridge.NetworkType, register: bridge.Register}, - {ntype: host.NetworkType, register: host.Register}, + {ntype: host.NetworkType, register: noConfig(host.Register)}, {ntype: ipvlan.NetworkType, register: ipvlan.Register}, {ntype: macvlan.NetworkType, register: macvlan.Register}, - {ntype: null.NetworkType, register: null.Register}, + {ntype: null.NetworkType, register: noConfig(null.Register)}, {ntype: overlay.NetworkType, register: overlay.Register}, } { if err := nr.register(r, driverConfig(nr.ntype)); err != nil { diff --git a/libnetwork/drivers_windows.go b/libnetwork/drivers_windows.go index f104ed88c1..56bab61b59 100644 --- a/libnetwork/drivers_windows.go +++ b/libnetwork/drivers_windows.go @@ -12,12 +12,12 @@ import ( func registerNetworkDrivers(r driverapi.Registerer, driverConfig func(string) map[string]interface{}) error { for _, nr := range []struct { ntype string - register func(driverapi.Registerer, map[string]interface{}) error + register func(driverapi.Registerer) error }{ {ntype: null.NetworkType, register: null.Register}, {ntype: overlay.NetworkType, register: overlay.Register}, } { - if err := nr.register(r, driverConfig(nr.ntype)); err != nil { + if err := nr.register(r); err != nil { return fmt.Errorf("failed to register %q driver: %w", nr.ntype, err) } }