libnet/ipams: register all drivers

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
This commit is contained in:
Albin Kerouanton 2024-04-18 11:22:02 +02:00
parent 9d26d5cccd
commit ee76ba99bb
5 changed files with 24 additions and 37 deletions

View file

@ -7,8 +7,7 @@ import (
"github.com/containerd/log"
"github.com/docker/docker/libnetwork/ipamapi"
builtinIpam "github.com/docker/docker/libnetwork/ipams"
nullIpam "github.com/docker/docker/libnetwork/ipams/null"
"github.com/docker/docker/libnetwork/ipams"
"github.com/docker/docker/libnetwork/ipamutils"
"github.com/moby/swarmkit/v2/manager/allocator/networkallocator"
)
@ -40,10 +39,7 @@ func initIPAMDrivers(r ipamapi.Registerer, netConfig *networkallocator.Config) e
log.G(context.TODO()).Infof("Swarm initialized global default address pool to: " + str.String())
}
if err := builtinIpam.Register(r, []*ipamutils.NetworkToSplit(nil)); err != nil {
return err
}
if err := nullIpam.Register(r); err != nil {
if err := ipams.Register(r, nil, []*ipamutils.NetworkToSplit(nil)); err != nil {
return err
}

View file

@ -63,6 +63,7 @@ import (
remotedriver "github.com/docker/docker/libnetwork/drivers/remote"
"github.com/docker/docker/libnetwork/drvregistry"
"github.com/docker/docker/libnetwork/ipamapi"
"github.com/docker/docker/libnetwork/ipams"
"github.com/docker/docker/libnetwork/netlabel"
"github.com/docker/docker/libnetwork/osl"
"github.com/docker/docker/libnetwork/scope"
@ -132,7 +133,7 @@ func New(cfgOptions ...config.Option) (*Controller, error) {
return nil, err
}
if err := initIPAMDrivers(&c.ipamRegistry, c.cfg.PluginGetter, c.cfg.DefaultAddressPool); err != nil {
if err := ipams.Register(&c.ipamRegistry, c.cfg.PluginGetter, c.cfg.DefaultAddressPool); err != nil {
return nil, err
}

View file

@ -1,20 +0,0 @@
package libnetwork
import (
"github.com/docker/docker/libnetwork/ipamapi"
builtinIpam "github.com/docker/docker/libnetwork/ipams"
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 {
if err := builtinIpam.Register(r, addressPool); err != nil {
return err
}
if err := nullIpam.Register(r); err != nil {
return err
}
return remoteIpam.Register(r, pg)
}

View file

@ -6,9 +6,7 @@ import (
"testing"
"github.com/docker/docker/libnetwork/ipamapi"
builtinIpam "github.com/docker/docker/libnetwork/ipams"
nullIpam "github.com/docker/docker/libnetwork/ipams/null"
remoteIpam "github.com/docker/docker/libnetwork/ipams/remote"
"github.com/docker/docker/libnetwork/ipams"
"github.com/docker/docker/libnetwork/ipamutils"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
@ -17,9 +15,7 @@ import (
func getNewIPAMs(t *testing.T) *IPAMs {
r := &IPAMs{}
assert.Assert(t, builtinIpam.Register(r, []*ipamutils.NetworkToSplit(nil)))
assert.Assert(t, remoteIpam.Register(r, nil))
assert.Assert(t, nullIpam.Register(r))
assert.Assert(t, ipams.Register(r, nil, []*ipamutils.NetworkToSplit(nil)))
return r
}

View file

@ -3,15 +3,29 @@ package ipams
import (
"github.com/docker/docker/libnetwork/ipamapi"
"github.com/docker/docker/libnetwork/ipams/defaultipam"
"github.com/docker/docker/libnetwork/ipams/null"
remoteIpam "github.com/docker/docker/libnetwork/ipams/remote"
"github.com/docker/docker/libnetwork/ipams/windowsipam"
"github.com/docker/docker/libnetwork/ipamutils"
"github.com/docker/docker/pkg/plugingetter"
)
// Register registers the built-in ipam services with libnetwork.
func Register(r ipamapi.Registerer, addressPools []*ipamutils.NetworkToSplit) error {
// Register registers all the builtin drivers (ie. default, windowsipam, null
// and remote). If 'pg' is nil, the remote driver won't be registered.
func Register(r ipamapi.Registerer, pg plugingetter.PluginGetter, addressPools []*ipamutils.NetworkToSplit) error {
if err := defaultipam.Register(r, addressPools); err != nil {
return err
}
return windowsipam.Register(r)
if err := windowsipam.Register(r); err != nil {
return err
}
if err := null.Register(r); err != nil {
return err
}
if pg != nil {
if err := remoteIpam.Register(r, pg); err != nil {
return err
}
}
return nil
}