Skip to content

Commit

Permalink
libnet/ipams: register all drivers
Browse files Browse the repository at this point in the history
Signed-off-by: Albin Kerouanton <albinker@gmail.com>
  • Loading branch information
akerouanton committed Apr 26, 2024
1 parent eda4750 commit 3c97181
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 37 deletions.
8 changes: 2 additions & 6 deletions libnetwork/cnmallocator/drivers_ipam.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
}

Expand Down
3 changes: 2 additions & 1 deletion libnetwork/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand Down
20 changes: 0 additions & 20 deletions libnetwork/drivers_ipam.go

This file was deleted.

8 changes: 2 additions & 6 deletions libnetwork/drvregistry/ipams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
}
Expand Down
22 changes: 18 additions & 4 deletions libnetwork/ipams/drivers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 3c97181

Please sign in to comment.