-
Notifications
You must be signed in to change notification settings - Fork 619
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: add temporary adaptor for constructor #3139
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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. The only consumers of libnetwork/idm are this file and libnetwork's ovmanager driver. Notably, ovmanager initializes its idm with start=0, which means the idm transparently delegates everything to the underlying bitmap and can therefore be trivially replaced with a |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -3,6 +3,7 @@ package cnmallocator | |||||
import ( | ||||||
"fmt" | ||||||
|
||||||
"github.com/docker/docker/libnetwork/datastore" | ||||||
"github.com/docker/docker/libnetwork/idm" | ||||||
"github.com/moby/swarmkit/v2/api" | ||||||
) | ||||||
|
@@ -117,16 +118,30 @@ func newPortAllocator() (*portAllocator, error) { | |||||
return &portAllocator{portSpaces: portSpaces}, nil | ||||||
} | ||||||
|
||||||
func newPortSpace(protocol api.PortConfig_Protocol) (*portSpace, error) { | ||||||
masterName := fmt.Sprintf("%s-master-ports", protocol) | ||||||
dynamicName := fmt.Sprintf("%s-dynamic-ports", protocol) | ||||||
type ( | ||||||
// these are deliberately aliases, otherwise we'd only match the same type, not signature. | ||||||
legacyIdmConstructor = func(ds datastore.DataStore, id string, start, end uint64) (*idm.Idm, error) | ||||||
idmConstructor = func(id string, start, end uint64) (*idm.Idm, error) | ||||||
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.
Suggested change
Without the datastore, |
||||||
) | ||||||
|
||||||
func newIdm(newFn any, id string, start, end uint64) (*idm.Idm, error) { | ||||||
switch fn := newFn.(type) { | ||||||
case idmConstructor: | ||||||
return fn(id, start, end) | ||||||
case legacyIdmConstructor: | ||||||
return fn(nil, id, start, end) | ||||||
default: | ||||||
return nil, fmt.Errorf("invalid constructor signature: %T", newFn) | ||||||
} | ||||||
} | ||||||
|
||||||
master, err := idm.New(nil, masterName, masterPortStart, masterPortEnd) | ||||||
func newPortSpace(protocol api.PortConfig_Protocol) (*portSpace, error) { | ||||||
master, err := newIdm(idm.New, protocol.String()+"-master-ports", masterPortStart, masterPortEnd) | ||||||
if err != nil { | ||||||
return nil, err | ||||||
} | ||||||
|
||||||
dynamic, err := idm.New(nil, dynamicName, dynamicPortStart, dynamicPortEnd) | ||||||
dynamic, err := newIdm(idm.New, protocol.String()+"-dynamic-ports", dynamicPortStart, dynamicPortEnd) | ||||||
if err != nil { | ||||||
return nil, err | ||||||
} | ||||||
|
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 damn right there is no way to pass a PluginGetter when constructing the non-deprecated
drvregistry
types. That's because they don't need one. See also moby/moby@28edc8e