ソースを参照

libnet/ipams: register all drivers

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
Albin Kerouanton 1 年間 前
コミット
ee76ba99bb

+ 2 - 6
libnetwork/cnmallocator/drivers_ipam.go

@@ -7,8 +7,7 @@ import (
 
 
 	"github.com/containerd/log"
 	"github.com/containerd/log"
 	"github.com/docker/docker/libnetwork/ipamapi"
 	"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/docker/docker/libnetwork/ipamutils"
 	"github.com/moby/swarmkit/v2/manager/allocator/networkallocator"
 	"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())
 		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
 		return err
 	}
 	}
 
 

+ 2 - 1
libnetwork/controller.go

@@ -63,6 +63,7 @@ import (
 	remotedriver "github.com/docker/docker/libnetwork/drivers/remote"
 	remotedriver "github.com/docker/docker/libnetwork/drivers/remote"
 	"github.com/docker/docker/libnetwork/drvregistry"
 	"github.com/docker/docker/libnetwork/drvregistry"
 	"github.com/docker/docker/libnetwork/ipamapi"
 	"github.com/docker/docker/libnetwork/ipamapi"
+	"github.com/docker/docker/libnetwork/ipams"
 	"github.com/docker/docker/libnetwork/netlabel"
 	"github.com/docker/docker/libnetwork/netlabel"
 	"github.com/docker/docker/libnetwork/osl"
 	"github.com/docker/docker/libnetwork/osl"
 	"github.com/docker/docker/libnetwork/scope"
 	"github.com/docker/docker/libnetwork/scope"
@@ -132,7 +133,7 @@ func New(cfgOptions ...config.Option) (*Controller, error) {
 		return nil, err
 		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
 		return nil, err
 	}
 	}
 
 

+ 0 - 20
libnetwork/drivers_ipam.go

@@ -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)
-}

+ 2 - 6
libnetwork/drvregistry/ipams_test.go

@@ -6,9 +6,7 @@ import (
 	"testing"
 	"testing"
 
 
 	"github.com/docker/docker/libnetwork/ipamapi"
 	"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"
 	"github.com/docker/docker/libnetwork/ipamutils"
 	"gotest.tools/v3/assert"
 	"gotest.tools/v3/assert"
 	is "gotest.tools/v3/assert/cmp"
 	is "gotest.tools/v3/assert/cmp"
@@ -17,9 +15,7 @@ import (
 func getNewIPAMs(t *testing.T) *IPAMs {
 func getNewIPAMs(t *testing.T) *IPAMs {
 	r := &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
 	return r
 }
 }

+ 18 - 4
libnetwork/ipams/drivers.go

@@ -3,15 +3,29 @@ package ipams
 import (
 import (
 	"github.com/docker/docker/libnetwork/ipamapi"
 	"github.com/docker/docker/libnetwork/ipamapi"
 	"github.com/docker/docker/libnetwork/ipams/defaultipam"
 	"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/ipams/windowsipam"
 	"github.com/docker/docker/libnetwork/ipamutils"
 	"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 {
 	if err := defaultipam.Register(r, addressPools); err != nil {
 		return err
 		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
 }
 }