github.com/moby/docker@v26.1.3+incompatible/libnetwork/cnmallocator/drivers_ipam.go (about) 1 package cnmallocator 2 3 import ( 4 "context" 5 "strconv" 6 "strings" 7 8 "github.com/containerd/log" 9 "github.com/docker/docker/libnetwork/ipamapi" 10 builtinIpam "github.com/docker/docker/libnetwork/ipams/builtin" 11 nullIpam "github.com/docker/docker/libnetwork/ipams/null" 12 "github.com/docker/docker/libnetwork/ipamutils" 13 "github.com/moby/swarmkit/v2/manager/allocator/networkallocator" 14 ) 15 16 func initIPAMDrivers(r ipamapi.Registerer, netConfig *networkallocator.Config) error { 17 var addressPool []*ipamutils.NetworkToSplit 18 var str strings.Builder 19 str.WriteString("Subnetlist - ") 20 // Extract defaultAddrPool param info and construct ipamutils.NetworkToSplit 21 // from the info. We will be using it to call Libnetwork API 22 // We also need to log new address pool info whenever swarm init 23 // happens with default address pool option 24 if netConfig != nil { 25 for _, p := range netConfig.DefaultAddrPool { 26 addressPool = append(addressPool, &ipamutils.NetworkToSplit{ 27 Base: p, 28 Size: int(netConfig.SubnetSize), 29 }) 30 str.WriteString(p + ",") 31 } 32 str.WriteString(": Size ") 33 str.WriteString(strconv.Itoa(int(netConfig.SubnetSize))) 34 35 } 36 if err := ipamutils.ConfigGlobalScopeDefaultNetworks(addressPool); err != nil { 37 return err 38 } 39 if addressPool != nil { 40 log.G(context.TODO()).Infof("Swarm initialized global default address pool to: " + str.String()) 41 } 42 43 for _, fn := range [](func(ipamapi.Registerer) error){ 44 builtinIpam.Register, 45 nullIpam.Register, 46 } { 47 if err := fn(r); err != nil { 48 return err 49 } 50 } 51 52 return nil 53 }