Skip to content

Commit 47210e3

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

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

manager/allocator/cnmallocator/networkallocator.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,24 @@ 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 driver configurations and notification
111+
// functions as of now.
112+
return fn(nil, pg)
113+
case legacyConstructor:
114+
return fn(nil, nil, nil, nil, pg)
115+
default:
116+
return nil, fmt.Errorf("invalid constructor signature: %T", newFn)
117+
}
118+
}
119+
102120
// New returns a new NetworkAllocator handle
103121
func New(pg plugingetter.PluginGetter, netConfig *NetworkConfig) (networkallocator.NetworkAllocator, error) {
104122
na := &cnmNetworkAllocator{
@@ -108,9 +126,8 @@ func New(pg plugingetter.PluginGetter, netConfig *NetworkConfig) (networkallocat
108126
nodes: make(map[string]map[string]struct{}),
109127
}
110128

111-
// There are no driver configurations and notification
112-
// functions as of now.
113-
reg, err := drvregistry.New(nil, nil, nil, nil, pg)
129+
// 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.
130+
reg, err := newDriverRegistry(drvregistry.New, pg)
114131
if err != nil {
115132
return nil, err
116133
}

0 commit comments

Comments
 (0)