mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
Before that change, we were passing the datastore to network drivers
through a `map[string]interface{}`. Then, each driver that needed the
store would cast the datastore to the correct type.
This was not a good design, as it was not clear which drivers were using
the store and which were not. Not all unit tests were passing the store,
leading to logs about uninitialized store being written.
This change makes the store a parameter of the `RegisterX` functions.
All unit tests are now passing a valid datastore to the drivers. A new
testutil func is added for that purpose.
Signed-off-by: Albin Kerouanton <albinker@gmail.com>
41 lines
1.5 KiB
Go
41 lines
1.5 KiB
Go
package libnetwork
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/docker/docker/libnetwork/datastore"
|
|
"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"
|
|
"github.com/docker/docker/libnetwork/drivers/macvlan"
|
|
"github.com/docker/docker/libnetwork/drivers/null"
|
|
"github.com/docker/docker/libnetwork/drivers/overlay"
|
|
)
|
|
|
|
func registerNetworkDrivers(r driverapi.Registerer, store *datastore.Store, driverConfig func(string) map[string]interface{}) error {
|
|
for _, nr := range []struct {
|
|
ntype string
|
|
register func(driverapi.Registerer, *datastore.Store, map[string]interface{}) error
|
|
}{
|
|
{ntype: bridge.NetworkType, register: bridge.Register},
|
|
{ntype: host.NetworkType, register: func(r driverapi.Registerer, _ *datastore.Store, _ map[string]interface{}) error {
|
|
return host.Register(r)
|
|
}},
|
|
{ntype: ipvlan.NetworkType, register: ipvlan.Register},
|
|
{ntype: macvlan.NetworkType, register: macvlan.Register},
|
|
{ntype: null.NetworkType, register: func(r driverapi.Registerer, _ *datastore.Store, _ map[string]interface{}) error {
|
|
return null.Register(r)
|
|
}},
|
|
{ntype: overlay.NetworkType, register: func(r driverapi.Registerer, _ *datastore.Store, config map[string]interface{}) error {
|
|
return overlay.Register(r, config)
|
|
}},
|
|
} {
|
|
if err := nr.register(r, store, driverConfig(nr.ntype)); err != nil {
|
|
return fmt.Errorf("failed to register %q driver: %w", nr.ntype, err)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|