mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
libnet/ipams/defaultipam: move driver name to its pkg
Signed-off-by: Albin Kerouanton <albinker@gmail.com>
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"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/defaultipam"
|
||||
remoteipam "github.com/docker/docker/libnetwork/ipams/remote"
|
||||
"github.com/docker/docker/libnetwork/netlabel"
|
||||
"github.com/docker/docker/libnetwork/scope"
|
||||
@@ -803,7 +804,7 @@ func (na *cnmNetworkAllocator) loadDriver(name string) error {
|
||||
|
||||
// Resolve the IPAM driver
|
||||
func (na *cnmNetworkAllocator) resolveIPAM(n *api.Network) (ipamapi.Ipam, string, map[string]string, error) {
|
||||
dName := ipamapi.DefaultIPAM
|
||||
dName := defaultipam.DriverName
|
||||
if n.Spec.IPAM != nil && n.Spec.IPAM.Driver != nil && n.Spec.IPAM.Driver.Name != "" {
|
||||
dName = n.Spec.IPAM.Driver.Name
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/docker/docker/libnetwork/driverapi"
|
||||
"github.com/docker/docker/libnetwork/drivers/overlay/overlayutils"
|
||||
"github.com/docker/docker/libnetwork/ipamapi"
|
||||
"github.com/docker/docker/libnetwork/ipams/defaultipam"
|
||||
"github.com/docker/docker/pkg/plugingetter"
|
||||
"github.com/moby/swarmkit/v2/api"
|
||||
"github.com/moby/swarmkit/v2/manager/allocator/networkallocator"
|
||||
@@ -35,7 +36,7 @@ func (p *Provider) ValidateIPAMDriver(driver *api.Driver) error {
|
||||
if driver.Name == "" {
|
||||
return status.Errorf(codes.InvalidArgument, "driver name: if driver is specified name is required")
|
||||
}
|
||||
if strings.ToLower(driver.Name) == ipamapi.DefaultIPAM {
|
||||
if strings.ToLower(driver.Name) == defaultipam.DriverName {
|
||||
return nil
|
||||
}
|
||||
return p.validatePluginDriver(driver, ipamapi.PluginEndpointType)
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/internal/testutils/netnsutils"
|
||||
"github.com/docker/docker/libnetwork/ipamapi"
|
||||
"github.com/docker/docker/libnetwork/ipams/defaultipam"
|
||||
"github.com/docker/docker/libnetwork/osl"
|
||||
)
|
||||
|
||||
@@ -24,7 +24,7 @@ ff02::2 ip6-allrouters
|
||||
fe90::2 somehost.example.com somehost
|
||||
`
|
||||
|
||||
opts := []NetworkOption{NetworkOptionEnableIPv6(true), NetworkOptionIpam(ipamapi.DefaultIPAM, "",
|
||||
opts := []NetworkOption{NetworkOptionEnableIPv6(true), NetworkOptionIpam(defaultipam.DriverName, "",
|
||||
[]*IpamConf{{PreferredPool: "192.168.222.0/24", Gateway: "192.168.222.1"}},
|
||||
[]*IpamConf{{PreferredPool: "fe90::/64", Gateway: "fe90::1"}},
|
||||
nil)}
|
||||
|
||||
@@ -10,8 +10,6 @@ import (
|
||||
|
||||
// IPAM plugin types
|
||||
const (
|
||||
// DefaultIPAM is the name of the built-in default ipam driver
|
||||
DefaultIPAM = "default"
|
||||
// NullIPAM is the name of the built-in null ipam driver
|
||||
NullIPAM = "null"
|
||||
// PluginEndpointType represents the Endpoint Type used by Plugin system
|
||||
|
||||
@@ -16,6 +16,9 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
// DriverName is the name of the built-in default IPAM driver.
|
||||
DriverName = "default"
|
||||
|
||||
localAddressSpace = "LocalDefault"
|
||||
globalAddressSpace = "GlobalDefault"
|
||||
)
|
||||
@@ -49,7 +52,7 @@ func Register(ic ipamapi.Registerer, lAddrPools, gAddrPools []*ipamutils.Network
|
||||
|
||||
cps := &ipamapi.Capability{RequiresRequestReplay: true}
|
||||
|
||||
return ic.RegisterIpamDriverWithCapabilities(ipamapi.DefaultIPAM, a, cps)
|
||||
return ic.RegisterIpamDriverWithCapabilities(DriverName, a, cps)
|
||||
}
|
||||
|
||||
// Allocator provides per address space ipv4/ipv6 book keeping
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
|
||||
"github.com/docker/docker/internal/testutils/netnsutils"
|
||||
"github.com/docker/docker/libnetwork/driverapi"
|
||||
"github.com/docker/docker/libnetwork/ipamapi"
|
||||
"github.com/docker/docker/libnetwork/ipams/defaultipam"
|
||||
"github.com/docker/docker/libnetwork/netlabel"
|
||||
"github.com/docker/docker/libnetwork/netutils"
|
||||
"github.com/docker/docker/libnetwork/scope"
|
||||
@@ -320,7 +320,7 @@ func TestAuxAddresses(t *testing.T) {
|
||||
}
|
||||
defer c.Stop()
|
||||
|
||||
n := &Network{ipamType: ipamapi.DefaultIPAM, networkType: "bridge", ctrlr: c}
|
||||
n := &Network{ipamType: defaultipam.DriverName, networkType: "bridge", ctrlr: c}
|
||||
|
||||
input := []struct {
|
||||
masterPool string
|
||||
@@ -581,7 +581,7 @@ func TestIpamReleaseOnNetDriverFailures(t *testing.T) {
|
||||
|
||||
// Test whether ipam state release is invoked on network create failure from net driver
|
||||
// by checking whether subsequent network creation requesting same gateway IP succeeds
|
||||
ipamOpt := NetworkOptionIpam(ipamapi.DefaultIPAM, "", []*IpamConf{{PreferredPool: "10.34.0.0/16", Gateway: "10.34.255.254"}}, nil, nil)
|
||||
ipamOpt := NetworkOptionIpam(defaultipam.DriverName, "", []*IpamConf{{PreferredPool: "10.34.0.0/16", Gateway: "10.34.255.254"}}, nil, nil)
|
||||
if _, err := c.NewNetwork(badDriverName, "badnet1", "", ipamOpt); err == nil {
|
||||
t.Fatalf("bad network driver should have failed network creation")
|
||||
}
|
||||
@@ -611,7 +611,7 @@ func TestIpamReleaseOnNetDriverFailures(t *testing.T) {
|
||||
}
|
||||
|
||||
// Now create good bridge network with different gateway
|
||||
ipamOpt2 := NetworkOptionIpam(ipamapi.DefaultIPAM, "", []*IpamConf{{PreferredPool: "10.35.0.0/16", Gateway: "10.35.255.253"}}, nil, nil)
|
||||
ipamOpt2 := NetworkOptionIpam(defaultipam.DriverName, "", []*IpamConf{{PreferredPool: "10.35.0.0/16", Gateway: "10.35.255.253"}}, nil, nil)
|
||||
gnw, err = c.NewNetwork("bridge", "goodnet2", "", ipamOpt2)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
@@ -23,6 +23,7 @@ import (
|
||||
"github.com/docker/docker/libnetwork/datastore"
|
||||
"github.com/docker/docker/libnetwork/driverapi"
|
||||
"github.com/docker/docker/libnetwork/ipamapi"
|
||||
"github.com/docker/docker/libnetwork/ipams/defaultipam"
|
||||
"github.com/docker/docker/libnetwork/netlabel"
|
||||
"github.com/docker/docker/libnetwork/options"
|
||||
"github.com/docker/docker/libnetwork/osl"
|
||||
@@ -68,7 +69,7 @@ func newController(t *testing.T) *libnetwork.Controller {
|
||||
func createTestNetwork(c *libnetwork.Controller, networkType, networkName string, netOption options.Generic, ipamV4Configs, ipamV6Configs []*libnetwork.IpamConf) (*libnetwork.Network, error) {
|
||||
return c.NewNetwork(networkType, networkName, "",
|
||||
libnetwork.NetworkOptionGeneric(netOption),
|
||||
libnetwork.NetworkOptionIpam(ipamapi.DefaultIPAM, "", ipamV4Configs, ipamV6Configs, nil))
|
||||
libnetwork.NetworkOptionIpam(defaultipam.DriverName, "", ipamV4Configs, ipamV6Configs, nil))
|
||||
}
|
||||
|
||||
func getEmptyGenericOption() map[string]interface{} {
|
||||
@@ -1421,7 +1422,7 @@ func TestBridgeIpv6FromMac(t *testing.T) {
|
||||
network, err := controller.NewNetwork(bridgeNetType, "testipv6mac", "",
|
||||
libnetwork.NetworkOptionGeneric(netOption),
|
||||
libnetwork.NetworkOptionEnableIPv6(true),
|
||||
libnetwork.NetworkOptionIpam(ipamapi.DefaultIPAM, "", ipamV4ConfList, ipamV6ConfList, nil),
|
||||
libnetwork.NetworkOptionIpam(defaultipam.DriverName, "", ipamV4ConfList, ipamV6ConfList, nil),
|
||||
libnetwork.NetworkOptionDeferIPv6Alloc(true))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -1495,7 +1496,7 @@ func TestEndpointJoin(t *testing.T) {
|
||||
n1, err := controller.NewNetwork(bridgeNetType, "testnetwork1", "",
|
||||
libnetwork.NetworkOptionGeneric(netOption),
|
||||
libnetwork.NetworkOptionEnableIPv6(true),
|
||||
libnetwork.NetworkOptionIpam(ipamapi.DefaultIPAM, "", nil, ipamV6ConfList, nil),
|
||||
libnetwork.NetworkOptionIpam(defaultipam.DriverName, "", nil, ipamV6ConfList, nil),
|
||||
libnetwork.NetworkOptionDeferIPv6Alloc(true))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
"github.com/docker/docker/libnetwork/internal/netiputil"
|
||||
"github.com/docker/docker/libnetwork/internal/setmatrix"
|
||||
"github.com/docker/docker/libnetwork/ipamapi"
|
||||
"github.com/docker/docker/libnetwork/ipams/defaultipam"
|
||||
"github.com/docker/docker/libnetwork/netlabel"
|
||||
"github.com/docker/docker/libnetwork/netutils"
|
||||
"github.com/docker/docker/libnetwork/networkdb"
|
||||
@@ -643,7 +644,7 @@ func (n *Network) UnmarshalJSON(b []byte) (err error) {
|
||||
if v, ok := netMap["ipamType"]; ok {
|
||||
n.ipamType = v.(string)
|
||||
} else {
|
||||
n.ipamType = ipamapi.DefaultIPAM
|
||||
n.ipamType = defaultipam.DriverName
|
||||
}
|
||||
if v, ok := netMap["addrSpace"]; ok {
|
||||
n.addrSpace = v.(string)
|
||||
@@ -785,7 +786,7 @@ func NetworkOptionIpam(ipamDriver string, addrSpace string, ipV4 []*IpamConf, ip
|
||||
return func(n *Network) {
|
||||
if ipamDriver != "" {
|
||||
n.ipamType = ipamDriver
|
||||
if ipamDriver == ipamapi.DefaultIPAM {
|
||||
if ipamDriver == defaultipam.DriverName {
|
||||
n.ipamType = defaultIpamForNetworkType(n.Type())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ package libnetwork
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/docker/docker/libnetwork/ipamapi"
|
||||
"github.com/docker/docker/libnetwork/ipams/defaultipam"
|
||||
)
|
||||
|
||||
type platformNetwork struct{} //nolint:nolintlint,unused // only populated on windows
|
||||
@@ -30,5 +30,5 @@ func deleteEpFromResolver(epName string, epIface *EndpointInterface, resolvers [
|
||||
}
|
||||
|
||||
func defaultIpamForNetworkType(networkType string) string {
|
||||
return ipamapi.DefaultIPAM
|
||||
return defaultipam.DriverName
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
"github.com/Microsoft/hcsshim"
|
||||
"github.com/containerd/log"
|
||||
"github.com/docker/docker/libnetwork/drivers/windows"
|
||||
"github.com/docker/docker/libnetwork/ipamapi"
|
||||
"github.com/docker/docker/libnetwork/ipams/defaultipam"
|
||||
"github.com/docker/docker/libnetwork/ipams/windowsipam"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
@@ -247,5 +247,5 @@ func defaultIpamForNetworkType(networkType string) string {
|
||||
if windows.IsBuiltinLocalDriver(networkType) {
|
||||
return windowsipam.DefaultIPAM
|
||||
}
|
||||
return ipamapi.DefaultIPAM
|
||||
return defaultipam.DriverName
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/internal/testutils/netnsutils"
|
||||
"github.com/docker/docker/libnetwork/config"
|
||||
"github.com/docker/docker/libnetwork/ipamapi"
|
||||
"github.com/docker/docker/libnetwork/ipams/defaultipam"
|
||||
"github.com/docker/docker/libnetwork/netlabel"
|
||||
"github.com/docker/docker/libnetwork/options"
|
||||
"github.com/docker/docker/libnetwork/osl"
|
||||
@@ -114,7 +114,7 @@ func TestSandboxAddMultiPrio(t *testing.T) {
|
||||
defer netnsutils.SetupTestOSContext(t)()
|
||||
|
||||
opts := [][]NetworkOption{
|
||||
{NetworkOptionEnableIPv6(true), NetworkOptionIpam(ipamapi.DefaultIPAM, "", nil, []*IpamConf{{PreferredPool: "fe90::/64"}}, nil)},
|
||||
{NetworkOptionEnableIPv6(true), NetworkOptionIpam(defaultipam.DriverName, "", nil, []*IpamConf{{PreferredPool: "fe90::/64"}}, nil)},
|
||||
{NetworkOptionInternalNetwork()},
|
||||
{},
|
||||
}
|
||||
@@ -200,7 +200,7 @@ func TestSandboxAddSamePrio(t *testing.T) {
|
||||
opts := [][]NetworkOption{
|
||||
{},
|
||||
{},
|
||||
{NetworkOptionEnableIPv6(true), NetworkOptionIpam(ipamapi.DefaultIPAM, "", nil, []*IpamConf{{PreferredPool: "fe90::/64"}}, nil)},
|
||||
{NetworkOptionEnableIPv6(true), NetworkOptionIpam(defaultipam.DriverName, "", nil, []*IpamConf{{PreferredPool: "fe90::/64"}}, nil)},
|
||||
{NetworkOptionInternalNetwork()},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user