Skip to content

Commit

Permalink
manager/allocator/cnmallocator: remove uses of deprecated Init() funcs
Browse files Browse the repository at this point in the history
These functions were deprecated in moby/moby@28edc8e
in favor of the Register functions.

Unfortunately, not all Register functions have the same signature, so
some (temporary) adaptor code was needed for these.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
  • Loading branch information
thaJeztah committed Jun 30, 2023
1 parent c76f025 commit 12e58a0
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 20 deletions.
25 changes: 25 additions & 0 deletions manager/allocator/cnmallocator/drivers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package cnmallocator

import (
"fmt"

"github.com/docker/docker/libnetwork/driverapi"
"github.com/docker/docker/libnetwork/drivers/remote"
)

type driverRegisterFn func(r driverapi.Registerer, config map[string]interface{}) error

func registerRemote(r driverapi.Registerer, _ map[string]interface{}) error {
dc, ok := r.(driverapi.DriverCallback)
if !ok {
return fmt.Errorf(`failed to register "remote" driver: driver does not implement driverapi.DriverCallback`)
}
return remote.Register(dc, dc.GetPluginGetter())
}

//nolint:unused // is currently only used on Windows, but keeping these adaptors together in one file.
func registerNetworkType(networkType string) func(dc driverapi.Registerer, config map[string]interface{}) error {
return func(r driverapi.Registerer, _ map[string]interface{}) error {
return RegisterManager(r, networkType)
}
}
5 changes: 2 additions & 3 deletions manager/allocator/cnmallocator/drivers_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ package cnmallocator

import (
"github.com/docker/docker/libnetwork/drivers/overlay/ovmanager"
"github.com/docker/docker/libnetwork/drivers/remote"
"github.com/moby/swarmkit/v2/manager/allocator/networkallocator"
)

var initializers = map[string]driverRegisterFn{
"remote": remote.Init,
"overlay": ovmanager.Init,
"remote": registerRemote,
"overlay": ovmanager.Register,
}

// PredefinedNetworks returns the list of predefined network structures
Expand Down
16 changes: 7 additions & 9 deletions manager/allocator/cnmallocator/drivers_network_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@ import (
"github.com/docker/docker/libnetwork/drivers/ipvlan/ivmanager"
"github.com/docker/docker/libnetwork/drivers/macvlan/mvmanager"
"github.com/docker/docker/libnetwork/drivers/overlay/ovmanager"
"github.com/docker/docker/libnetwork/drivers/remote"
"github.com/docker/docker/libnetwork/drvregistry"
"github.com/moby/swarmkit/v2/manager/allocator/networkallocator"
)

var initializers = map[string]drvregistry.InitFunc{
"remote": remote.Init,
"overlay": ovmanager.Init,
"macvlan": mvmanager.Init,
"bridge": brmanager.Init,
"ipvlan": ivmanager.Init,
"host": host.Init,
var initializers = map[string]driverRegisterFn{
"remote": registerRemote,
"overlay": ovmanager.Register,
"macvlan": mvmanager.Register,
"bridge": brmanager.Register,
"ipvlan": ivmanager.Register,
"host": host.Register,
}

// PredefinedNetworks returns the list of predefined network structures
Expand Down
14 changes: 6 additions & 8 deletions manager/allocator/cnmallocator/drivers_network_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@ package cnmallocator

import (
"github.com/docker/docker/libnetwork/drivers/overlay/ovmanager"
"github.com/docker/docker/libnetwork/drivers/remote"
"github.com/docker/docker/libnetwork/drvregistry"
"github.com/moby/swarmkit/v2/manager/allocator/networkallocator"
)

var initializers = map[string]drvregistry.InitFunc{
"remote": remote.Init,
"overlay": ovmanager.Init,
"internal": StubManagerInit("internal"),
"l2bridge": StubManagerInit("l2bridge"),
"nat": StubManagerInit("nat"),
var initializers = map[string]driverRegisterFn{
"remote": registerRemote,
"overlay": ovmanager.Register,
"internal": registerNetworkType("internal"),
"l2bridge": registerNetworkType("l2bridge"),
"nat": registerNetworkType("nat"),
}

// PredefinedNetworks returns the list of predefined network structures
Expand Down

0 comments on commit 12e58a0

Please sign in to comment.