d478e13639
The datastore arguments to the IPAM driver Init() functions are always nil, even in Swarmkit. The only IPAM driver which consumed the datastores was builtin; all others (null, remote, windowsipam) simply ignored it. As the signatures of the IPAM driver init functions cannot be changed without breaking the Swarmkit build, they have to be left with the same signatures for the time being. Assert that nil datastores are always passed into the builtin IPAM driver's init function so that there is no ambiguity the datastores are no longer respected. Add new Register functions for the IPAM drivers which are free from the legacy baggage of the Init functions. (The legacy Init functions can be removed once Swarmkit is migrated to using the Register functions.) As the remote IPAM driver is the only one which depends on a PluginGetter, pass it in explicitly as an argument to Register. The other IPAM drivers should not be forced to depend on a GetPluginGetter() method they do not use (Interface Segregation Principle). Signed-off-by: Cory Snider <csnider@mirantis.com>
30 lines
970 B
Go
30 lines
970 B
Go
package libnetwork
|
|
|
|
import (
|
|
"github.com/docker/docker/libnetwork/ipamapi"
|
|
builtinIpam "github.com/docker/docker/libnetwork/ipams/builtin"
|
|
nullIpam "github.com/docker/docker/libnetwork/ipams/null"
|
|
remoteIpam "github.com/docker/docker/libnetwork/ipams/remote"
|
|
"github.com/docker/docker/libnetwork/ipamutils"
|
|
"github.com/docker/docker/pkg/plugingetter"
|
|
)
|
|
|
|
func initIPAMDrivers(r ipamapi.Registerer, pg plugingetter.PluginGetter, addressPool []*ipamutils.NetworkToSplit) error {
|
|
// TODO: pass address pools as arguments to builtinIpam.Init instead of
|
|
// indirectly through global mutable state. Swarmkit references that
|
|
// function so changing its signature breaks the build.
|
|
if err := builtinIpam.SetDefaultIPAddressPool(addressPool); err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, fn := range [](func(ipamapi.Registerer) error){
|
|
builtinIpam.Register,
|
|
nullIpam.Register,
|
|
} {
|
|
if err := fn(r); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return remoteIpam.Register(r, pg)
|
|
}
|