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>
28 lines
824 B
Go
28 lines
824 B
Go
package libnetwork
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/docker/docker/libnetwork/datastore"
|
|
"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 registerNetworkDrivers(r driverapi.Registerer, store *datastore.Store, _ func(string) map[string]interface{}) error {
|
|
for _, nr := range []struct {
|
|
ntype string
|
|
register func(driverapi.Registerer) error
|
|
}{
|
|
{ntype: null.NetworkType, register: null.Register},
|
|
{ntype: overlay.NetworkType, register: overlay.Register},
|
|
} {
|
|
if err := nr.register(r); err != nil {
|
|
return fmt.Errorf("failed to register %q driver: %w", nr.ntype, err)
|
|
}
|
|
}
|
|
|
|
return windows.RegisterBuiltinLocalDrivers(r, store)
|
|
}
|