Browse code

libnet/ipams/defaultipam: move driver name to its pkg

Signed-off-by: Albin Kerouanton <albinker@gmail.com>

Albin Kerouanton authored on 2024/04/27 00:17:38
Showing 11 changed files
... ...
@@ -11,6 +11,7 @@ import (
11 11
 	"github.com/docker/docker/libnetwork/drivers/remote"
12 12
 	"github.com/docker/docker/libnetwork/drvregistry"
13 13
 	"github.com/docker/docker/libnetwork/ipamapi"
14
+	"github.com/docker/docker/libnetwork/ipams/defaultipam"
14 15
 	remoteipam "github.com/docker/docker/libnetwork/ipams/remote"
15 16
 	"github.com/docker/docker/libnetwork/netlabel"
16 17
 	"github.com/docker/docker/libnetwork/scope"
... ...
@@ -803,7 +804,7 @@ func (na *cnmNetworkAllocator) loadDriver(name string) error {
803 803
 
804 804
 // Resolve the IPAM driver
805 805
 func (na *cnmNetworkAllocator) resolveIPAM(n *api.Network) (ipamapi.Ipam, string, map[string]string, error) {
806
-	dName := ipamapi.DefaultIPAM
806
+	dName := defaultipam.DriverName
807 807
 	if n.Spec.IPAM != nil && n.Spec.IPAM.Driver != nil && n.Spec.IPAM.Driver.Name != "" {
808 808
 		dName = n.Spec.IPAM.Driver.Name
809 809
 	}
... ...
@@ -6,6 +6,7 @@ import (
6 6
 	"github.com/docker/docker/libnetwork/driverapi"
7 7
 	"github.com/docker/docker/libnetwork/drivers/overlay/overlayutils"
8 8
 	"github.com/docker/docker/libnetwork/ipamapi"
9
+	"github.com/docker/docker/libnetwork/ipams/defaultipam"
9 10
 	"github.com/docker/docker/pkg/plugingetter"
10 11
 	"github.com/moby/swarmkit/v2/api"
11 12
 	"github.com/moby/swarmkit/v2/manager/allocator/networkallocator"
... ...
@@ -35,7 +36,7 @@ func (p *Provider) ValidateIPAMDriver(driver *api.Driver) error {
35 35
 	if driver.Name == "" {
36 36
 		return status.Errorf(codes.InvalidArgument, "driver name: if driver is specified name is required")
37 37
 	}
38
-	if strings.ToLower(driver.Name) == ipamapi.DefaultIPAM {
38
+	if strings.ToLower(driver.Name) == defaultipam.DriverName {
39 39
 		return nil
40 40
 	}
41 41
 	return p.validatePluginDriver(driver, ipamapi.PluginEndpointType)
... ...
@@ -7,7 +7,7 @@ import (
7 7
 	"testing"
8 8
 
9 9
 	"github.com/docker/docker/internal/testutils/netnsutils"
10
-	"github.com/docker/docker/libnetwork/ipamapi"
10
+	"github.com/docker/docker/libnetwork/ipams/defaultipam"
11 11
 	"github.com/docker/docker/libnetwork/osl"
12 12
 )
13 13
 
... ...
@@ -24,7 +24,7 @@ ff02::2	ip6-allrouters
24 24
 fe90::2	somehost.example.com somehost
25 25
 `
26 26
 
27
-	opts := []NetworkOption{NetworkOptionEnableIPv6(true), NetworkOptionIpam(ipamapi.DefaultIPAM, "",
27
+	opts := []NetworkOption{NetworkOptionEnableIPv6(true), NetworkOptionIpam(defaultipam.DriverName, "",
28 28
 		[]*IpamConf{{PreferredPool: "192.168.222.0/24", Gateway: "192.168.222.1"}},
29 29
 		[]*IpamConf{{PreferredPool: "fe90::/64", Gateway: "fe90::1"}},
30 30
 		nil)}
... ...
@@ -10,8 +10,6 @@ import (
10 10
 
11 11
 // IPAM plugin types
12 12
 const (
13
-	// DefaultIPAM is the name of the built-in default ipam driver
14
-	DefaultIPAM = "default"
15 13
 	// NullIPAM is the name of the built-in null ipam driver
16 14
 	NullIPAM = "null"
17 15
 	// PluginEndpointType represents the Endpoint Type used by Plugin system
... ...
@@ -16,6 +16,9 @@ import (
16 16
 )
17 17
 
18 18
 const (
19
+	// DriverName is the name of the built-in default IPAM driver.
20
+	DriverName = "default"
21
+
19 22
 	localAddressSpace  = "LocalDefault"
20 23
 	globalAddressSpace = "GlobalDefault"
21 24
 )
... ...
@@ -49,7 +52,7 @@ func Register(ic ipamapi.Registerer, lAddrPools, gAddrPools []*ipamutils.Network
49 49
 
50 50
 	cps := &ipamapi.Capability{RequiresRequestReplay: true}
51 51
 
52
-	return ic.RegisterIpamDriverWithCapabilities(ipamapi.DefaultIPAM, a, cps)
52
+	return ic.RegisterIpamDriverWithCapabilities(DriverName, a, cps)
53 53
 }
54 54
 
55 55
 // Allocator provides per address space ipv4/ipv6 book keeping
... ...
@@ -12,7 +12,7 @@ import (
12 12
 
13 13
 	"github.com/docker/docker/internal/testutils/netnsutils"
14 14
 	"github.com/docker/docker/libnetwork/driverapi"
15
-	"github.com/docker/docker/libnetwork/ipamapi"
15
+	"github.com/docker/docker/libnetwork/ipams/defaultipam"
16 16
 	"github.com/docker/docker/libnetwork/netlabel"
17 17
 	"github.com/docker/docker/libnetwork/netutils"
18 18
 	"github.com/docker/docker/libnetwork/scope"
... ...
@@ -320,7 +320,7 @@ func TestAuxAddresses(t *testing.T) {
320 320
 	}
321 321
 	defer c.Stop()
322 322
 
323
-	n := &Network{ipamType: ipamapi.DefaultIPAM, networkType: "bridge", ctrlr: c}
323
+	n := &Network{ipamType: defaultipam.DriverName, networkType: "bridge", ctrlr: c}
324 324
 
325 325
 	input := []struct {
326 326
 		masterPool   string
... ...
@@ -581,7 +581,7 @@ func TestIpamReleaseOnNetDriverFailures(t *testing.T) {
581 581
 
582 582
 	// Test whether ipam state release is invoked  on network create failure from net driver
583 583
 	// by checking whether subsequent network creation requesting same gateway IP succeeds
584
-	ipamOpt := NetworkOptionIpam(ipamapi.DefaultIPAM, "", []*IpamConf{{PreferredPool: "10.34.0.0/16", Gateway: "10.34.255.254"}}, nil, nil)
584
+	ipamOpt := NetworkOptionIpam(defaultipam.DriverName, "", []*IpamConf{{PreferredPool: "10.34.0.0/16", Gateway: "10.34.255.254"}}, nil, nil)
585 585
 	if _, err := c.NewNetwork(badDriverName, "badnet1", "", ipamOpt); err == nil {
586 586
 		t.Fatalf("bad network driver should have failed network creation")
587 587
 	}
... ...
@@ -611,7 +611,7 @@ func TestIpamReleaseOnNetDriverFailures(t *testing.T) {
611 611
 	}
612 612
 
613 613
 	// Now create good bridge network with different gateway
614
-	ipamOpt2 := NetworkOptionIpam(ipamapi.DefaultIPAM, "", []*IpamConf{{PreferredPool: "10.35.0.0/16", Gateway: "10.35.255.253"}}, nil, nil)
614
+	ipamOpt2 := NetworkOptionIpam(defaultipam.DriverName, "", []*IpamConf{{PreferredPool: "10.35.0.0/16", Gateway: "10.35.255.253"}}, nil, nil)
615 615
 	gnw, err = c.NewNetwork("bridge", "goodnet2", "", ipamOpt2)
616 616
 	if err != nil {
617 617
 		t.Fatal(err)
... ...
@@ -23,6 +23,7 @@ import (
23 23
 	"github.com/docker/docker/libnetwork/datastore"
24 24
 	"github.com/docker/docker/libnetwork/driverapi"
25 25
 	"github.com/docker/docker/libnetwork/ipamapi"
26
+	"github.com/docker/docker/libnetwork/ipams/defaultipam"
26 27
 	"github.com/docker/docker/libnetwork/netlabel"
27 28
 	"github.com/docker/docker/libnetwork/options"
28 29
 	"github.com/docker/docker/libnetwork/osl"
... ...
@@ -68,7 +69,7 @@ func newController(t *testing.T) *libnetwork.Controller {
68 68
 func createTestNetwork(c *libnetwork.Controller, networkType, networkName string, netOption options.Generic, ipamV4Configs, ipamV6Configs []*libnetwork.IpamConf) (*libnetwork.Network, error) {
69 69
 	return c.NewNetwork(networkType, networkName, "",
70 70
 		libnetwork.NetworkOptionGeneric(netOption),
71
-		libnetwork.NetworkOptionIpam(ipamapi.DefaultIPAM, "", ipamV4Configs, ipamV6Configs, nil))
71
+		libnetwork.NetworkOptionIpam(defaultipam.DriverName, "", ipamV4Configs, ipamV6Configs, nil))
72 72
 }
73 73
 
74 74
 func getEmptyGenericOption() map[string]interface{} {
... ...
@@ -1421,7 +1422,7 @@ func TestBridgeIpv6FromMac(t *testing.T) {
1421 1421
 	network, err := controller.NewNetwork(bridgeNetType, "testipv6mac", "",
1422 1422
 		libnetwork.NetworkOptionGeneric(netOption),
1423 1423
 		libnetwork.NetworkOptionEnableIPv6(true),
1424
-		libnetwork.NetworkOptionIpam(ipamapi.DefaultIPAM, "", ipamV4ConfList, ipamV6ConfList, nil),
1424
+		libnetwork.NetworkOptionIpam(defaultipam.DriverName, "", ipamV4ConfList, ipamV6ConfList, nil),
1425 1425
 		libnetwork.NetworkOptionDeferIPv6Alloc(true))
1426 1426
 	if err != nil {
1427 1427
 		t.Fatal(err)
... ...
@@ -1495,7 +1496,7 @@ func TestEndpointJoin(t *testing.T) {
1495 1495
 	n1, err := controller.NewNetwork(bridgeNetType, "testnetwork1", "",
1496 1496
 		libnetwork.NetworkOptionGeneric(netOption),
1497 1497
 		libnetwork.NetworkOptionEnableIPv6(true),
1498
-		libnetwork.NetworkOptionIpam(ipamapi.DefaultIPAM, "", nil, ipamV6ConfList, nil),
1498
+		libnetwork.NetworkOptionIpam(defaultipam.DriverName, "", nil, ipamV6ConfList, nil),
1499 1499
 		libnetwork.NetworkOptionDeferIPv6Alloc(true))
1500 1500
 	if err != nil {
1501 1501
 		t.Fatal(err)
... ...
@@ -20,6 +20,7 @@ import (
20 20
 	"github.com/docker/docker/libnetwork/internal/netiputil"
21 21
 	"github.com/docker/docker/libnetwork/internal/setmatrix"
22 22
 	"github.com/docker/docker/libnetwork/ipamapi"
23
+	"github.com/docker/docker/libnetwork/ipams/defaultipam"
23 24
 	"github.com/docker/docker/libnetwork/netlabel"
24 25
 	"github.com/docker/docker/libnetwork/netutils"
25 26
 	"github.com/docker/docker/libnetwork/networkdb"
... ...
@@ -643,7 +644,7 @@ func (n *Network) UnmarshalJSON(b []byte) (err error) {
643 643
 	if v, ok := netMap["ipamType"]; ok {
644 644
 		n.ipamType = v.(string)
645 645
 	} else {
646
-		n.ipamType = ipamapi.DefaultIPAM
646
+		n.ipamType = defaultipam.DriverName
647 647
 	}
648 648
 	if v, ok := netMap["addrSpace"]; ok {
649 649
 		n.addrSpace = v.(string)
... ...
@@ -785,7 +786,7 @@ func NetworkOptionIpam(ipamDriver string, addrSpace string, ipV4 []*IpamConf, ip
785 785
 	return func(n *Network) {
786 786
 		if ipamDriver != "" {
787 787
 			n.ipamType = ipamDriver
788
-			if ipamDriver == ipamapi.DefaultIPAM {
788
+			if ipamDriver == defaultipam.DriverName {
789 789
 				n.ipamType = defaultIpamForNetworkType(n.Type())
790 790
 			}
791 791
 		}
... ...
@@ -5,7 +5,7 @@ package libnetwork
5 5
 import (
6 6
 	"context"
7 7
 
8
-	"github.com/docker/docker/libnetwork/ipamapi"
8
+	"github.com/docker/docker/libnetwork/ipams/defaultipam"
9 9
 )
10 10
 
11 11
 type platformNetwork struct{} //nolint:nolintlint,unused // only populated on windows
... ...
@@ -30,5 +30,5 @@ func deleteEpFromResolver(epName string, epIface *EndpointInterface, resolvers [
30 30
 }
31 31
 
32 32
 func defaultIpamForNetworkType(networkType string) string {
33
-	return ipamapi.DefaultIPAM
33
+	return defaultipam.DriverName
34 34
 }
... ...
@@ -15,7 +15,7 @@ import (
15 15
 	"github.com/Microsoft/hcsshim"
16 16
 	"github.com/containerd/log"
17 17
 	"github.com/docker/docker/libnetwork/drivers/windows"
18
-	"github.com/docker/docker/libnetwork/ipamapi"
18
+	"github.com/docker/docker/libnetwork/ipams/defaultipam"
19 19
 	"github.com/docker/docker/libnetwork/ipams/windowsipam"
20 20
 	"github.com/pkg/errors"
21 21
 )
... ...
@@ -247,5 +247,5 @@ func defaultIpamForNetworkType(networkType string) string {
247 247
 	if windows.IsBuiltinLocalDriver(networkType) {
248 248
 		return windowsipam.DefaultIPAM
249 249
 	}
250
-	return ipamapi.DefaultIPAM
250
+	return defaultipam.DriverName
251 251
 }
... ...
@@ -9,7 +9,7 @@ import (
9 9
 	"github.com/docker/docker/errdefs"
10 10
 	"github.com/docker/docker/internal/testutils/netnsutils"
11 11
 	"github.com/docker/docker/libnetwork/config"
12
-	"github.com/docker/docker/libnetwork/ipamapi"
12
+	"github.com/docker/docker/libnetwork/ipams/defaultipam"
13 13
 	"github.com/docker/docker/libnetwork/netlabel"
14 14
 	"github.com/docker/docker/libnetwork/options"
15 15
 	"github.com/docker/docker/libnetwork/osl"
... ...
@@ -114,7 +114,7 @@ func TestSandboxAddMultiPrio(t *testing.T) {
114 114
 	defer netnsutils.SetupTestOSContext(t)()
115 115
 
116 116
 	opts := [][]NetworkOption{
117
-		{NetworkOptionEnableIPv6(true), NetworkOptionIpam(ipamapi.DefaultIPAM, "", nil, []*IpamConf{{PreferredPool: "fe90::/64"}}, nil)},
117
+		{NetworkOptionEnableIPv6(true), NetworkOptionIpam(defaultipam.DriverName, "", nil, []*IpamConf{{PreferredPool: "fe90::/64"}}, nil)},
118 118
 		{NetworkOptionInternalNetwork()},
119 119
 		{},
120 120
 	}
... ...
@@ -200,7 +200,7 @@ func TestSandboxAddSamePrio(t *testing.T) {
200 200
 	opts := [][]NetworkOption{
201 201
 		{},
202 202
 		{},
203
-		{NetworkOptionEnableIPv6(true), NetworkOptionIpam(ipamapi.DefaultIPAM, "", nil, []*IpamConf{{PreferredPool: "fe90::/64"}}, nil)},
203
+		{NetworkOptionEnableIPv6(true), NetworkOptionIpam(defaultipam.DriverName, "", nil, []*IpamConf{{PreferredPool: "fe90::/64"}}, nil)},
204 204
 		{NetworkOptionInternalNetwork()},
205 205
 	}
206 206