-
Notifications
You must be signed in to change notification settings - Fork 621
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
manager/allocator/cnmallocator: remove uses of deprecated Init() funcs #3138
Changes from all commits
470f0b5
d98f63b
df35053
cecae4a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,19 +11,18 @@ type manager struct { | |
networkType string | ||
} | ||
|
||
func StubManagerInit(networkType string) func(dc driverapi.DriverCallback, config map[string]interface{}) error { | ||
return func(dc driverapi.DriverCallback, config map[string]interface{}) error { | ||
func StubManagerInit(networkType string) func(dc driverapi.DriverCallback, _ map[string]interface{}) error { | ||
return func(dc driverapi.DriverCallback, _ map[string]interface{}) error { | ||
return RegisterManager(dc, networkType) | ||
} | ||
} | ||
Comment on lines
+14
to
18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this now dead code? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DOH! I think it is now yes; originally I had to adjust the DriverCallback, but that's no longer true, so yup. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I see that PR was closed though, but I wasn't sure if it was still needed (to be revived); do you know? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It is not needed. |
||
|
||
// Register registers a new instance of the manager driver for networkType with r. | ||
func RegisterManager(r driverapi.DriverCallback, networkType string) error { | ||
c := driverapi.Capability{ | ||
// RegisterManager registers a new instance of the manager driver for networkType with r. | ||
func RegisterManager(r driverapi.Registerer, networkType string) error { | ||
return r.RegisterDriver(networkType, &manager{networkType: networkType}, driverapi.Capability{ | ||
DataScope: datastore.LocalScope, | ||
ConnectivityScope: datastore.LocalScope, | ||
} | ||
return r.RegisterDriver(networkType, &manager{networkType: networkType}, c) | ||
}) | ||
} | ||
|
||
func (d *manager) NetworkAllocate(id string, option map[string]string, ipV4Data, ipV6Data []driverapi.IPAMData) (map[string]string, error) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please please please just special-case the registration of the remote driver so that Swarmkit can stop depending on the deprecated
drvregistry.DrvRegistry
. And I'd really like to get rid of theDriverCallback
interface in libnetwork as well (which I overlooked annotating as deprecated, whoops)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to check that last one; while working on #3139 (reviews welcome on that one as well 😅), I found that the
plugingetter
field is not exported, but looks to be used, so the only way to set it is through the (deprecated)drvregistry.New
I may need to have a deeper look "how" it's used, and if there's other ways to pass it around though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
plugingetter field?
cnmallocator.New
takes the PluginGetter as an argument, constructs aDrvRegistry
using it, and passes it to each theinitializers
in the slice/map. Simply cut out the middleman by passing the PluginGetter directly into a call toremote.Register
fromcnmallocator.New
. That's what I meant by special-casing the registration.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah! Gotcha (I think) I'll have another look tomorrow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right that the
DrvRegistry.pluginGetter
field is used. It serves one purpose: implementing theGetPluginGetter()
method, which is only used to indirectly pass the PluginGetter intoremote.Init()
. As I explained in the commit message of moby/moby@5595311, I very deliberately omitted any PluginGetter stuff from the replacement types.