Skip to content

Commit 9abd4d7

Browse files
committed
manager/allocator/cnmallocator: add adaptor for allocator signature changes
Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent f5aadc3 commit 9abd4d7

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

manager/allocator/cnmallocator/networkallocator.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,23 @@ type NetworkConfig struct {
9999
VXLANUDPPort uint32
100100
}
101101

102+
type (
103+
registryConstructor = func(drvregistry.DriverNotifyFunc, plugingetter.PluginGetter) (*drvregistry.DrvRegistry, error)
104+
legacyConstructor = func(drvregistry.Placeholder, drvregistry.Placeholder, drvregistry.DriverNotifyFunc, drvregistry.Placeholder, plugingetter.PluginGetter) (*drvregistry.DrvRegistry, error)
105+
)
106+
107+
func newDriverRegistry(newFn any, pg plugingetter.PluginGetter) (*drvregistry.DrvRegistry, error) {
108+
switch fn := newFn.(type) {
109+
case registryConstructor:
110+
// There are no notification functions as of now.
111+
return fn(nil, pg)
112+
case legacyConstructor:
113+
return fn(nil, nil, nil, nil, pg)
114+
default:
115+
return nil, fmt.Errorf("invalid constructor signature: %T", newFn)
116+
}
117+
}
118+
102119
// New returns a new NetworkAllocator handle
103120
func New(pg plugingetter.PluginGetter, netConfig *NetworkConfig) (networkallocator.NetworkAllocator, error) {
104121
na := &cnmNetworkAllocator{
@@ -108,9 +125,8 @@ func New(pg plugingetter.PluginGetter, netConfig *NetworkConfig) (networkallocat
108125
nodes: make(map[string]map[string]struct{}),
109126
}
110127

111-
// There are no driver configurations and notification
112-
// functions as of now.
113-
reg, err := drvregistry.New(nil, nil, nil, nil, pg)
128+
// FIXME(thaJeztah): drvregistry.New was deprecated in https://github.com/moby/moby/commit/5595311209cc915e8b0ace0a1bbd8b52a7baecb0, but there's no other way to pass a PluginGetter to it.
129+
reg, err := newDriverRegistry(drvregistry.New, pg)
114130
if err != nil {
115131
return nil, err
116132
}

0 commit comments

Comments
 (0)