vendor: github.com/moby/moby/api, client 0769fe708773 (master)
full diff: 4ca8aedf92...0769fe7087
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"net/netip"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/cli/cli"
|
||||
@ -34,9 +35,9 @@ type createOptions struct {
|
||||
|
||||
type ipamOptions struct {
|
||||
driver string
|
||||
subnets []string
|
||||
ipRanges []string
|
||||
gateways []string
|
||||
subnets []string // TODO(thaJeztah): change to []net.IPNet? This won't accept a bare address (without "/xxx"); we need a flag-type to handle []netip.Prefix directly
|
||||
ipRanges []net.IPNet // TODO(thaJeztah): we need a flag-type to handle []netip.Prefix directly
|
||||
gateways []net.IP // TODO(thaJeztah): we need a flag-type to handle []netip.Addr directly
|
||||
auxAddresses opts.MapOpts
|
||||
driverOpts opts.MapOpts
|
||||
}
|
||||
@ -92,8 +93,8 @@ func newCreateCommand(dockerCLI command.Cli) *cobra.Command {
|
||||
|
||||
flags.StringVar(&options.ipam.driver, "ipam-driver", "default", "IP Address Management Driver")
|
||||
flags.StringSliceVar(&options.ipam.subnets, "subnet", []string{}, "Subnet in CIDR format that represents a network segment")
|
||||
flags.StringSliceVar(&options.ipam.ipRanges, "ip-range", []string{}, "Allocate container ip from a sub-range")
|
||||
flags.StringSliceVar(&options.ipam.gateways, "gateway", []string{}, "IPv4 or IPv6 Gateway for the master subnet")
|
||||
flags.IPNetSliceVar(&options.ipam.ipRanges, "ip-range", nil, "Allocate container ip from a sub-range")
|
||||
flags.IPSliceVar(&options.ipam.gateways, "gateway", nil, "IPv4 or IPv6 Gateway for the master subnet")
|
||||
|
||||
flags.Var(&options.ipam.auxAddresses, "aux-address", "Auxiliary IPv4 or IPv6 addresses used by Network driver")
|
||||
flags.Var(&options.ipam.driverOpts, "ipam-opt", "Set IPAM driver specific options")
|
||||
@ -162,32 +163,36 @@ func createIPAMConfig(options ipamOptions) (*network.IPAM, error) {
|
||||
return nil, errors.New("multiple overlapping subnet configuration is not supported")
|
||||
}
|
||||
}
|
||||
iData[s] = &network.IPAMConfig{Subnet: s, AuxAddress: map[string]string{}}
|
||||
sn, err := netip.ParsePrefix(s)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
iData[s] = &network.IPAMConfig{Subnet: sn, AuxAddress: map[string]netip.Addr{}}
|
||||
}
|
||||
|
||||
// Validate and add valid ip ranges
|
||||
for _, r := range options.ipRanges {
|
||||
match := false
|
||||
for _, s := range options.subnets {
|
||||
if _, _, err := net.ParseCIDR(r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ok, err := subnetMatches(s, r)
|
||||
ok, err := subnetMatches(s, r.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
if iData[s].IPRange != "" {
|
||||
return nil, fmt.Errorf("cannot configure multiple ranges (%s, %s) on the same subnet (%s)", r, iData[s].IPRange, s)
|
||||
|
||||
// Using "IsValid" to check if a valid IPRange was already set.
|
||||
if iData[s].IPRange.IsValid() {
|
||||
return nil, fmt.Errorf("cannot configure multiple ranges (%s, %s) on the same subnet (%s)", r.String(), iData[s].IPRange.String(), s)
|
||||
}
|
||||
if ipRange, ok := toPrefix(r); ok {
|
||||
iData[s].IPRange = ipRange
|
||||
match = true
|
||||
}
|
||||
d := iData[s]
|
||||
d.IPRange = r
|
||||
match = true
|
||||
}
|
||||
if !match {
|
||||
return nil, fmt.Errorf("no matching subnet for range %s", r)
|
||||
return nil, fmt.Errorf("no matching subnet for range %s", r.String())
|
||||
}
|
||||
}
|
||||
|
||||
@ -195,18 +200,18 @@ func createIPAMConfig(options ipamOptions) (*network.IPAM, error) {
|
||||
for _, g := range options.gateways {
|
||||
match := false
|
||||
for _, s := range options.subnets {
|
||||
ok, err := subnetMatches(s, g)
|
||||
ok, err := subnetMatches(s, g.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
if iData[s].Gateway != "" {
|
||||
if iData[s].Gateway.IsValid() {
|
||||
return nil, fmt.Errorf("cannot configure multiple gateways (%s, %s) for the same subnet (%s)", g, iData[s].Gateway, s)
|
||||
}
|
||||
d := iData[s]
|
||||
d.Gateway = g
|
||||
d.Gateway = toNetipAddr(g)
|
||||
match = true
|
||||
}
|
||||
if !match {
|
||||
@ -215,17 +220,24 @@ func createIPAMConfig(options ipamOptions) (*network.IPAM, error) {
|
||||
}
|
||||
|
||||
// Validate and add aux-addresses
|
||||
for key, aa := range options.auxAddresses.GetAll() {
|
||||
for name, aa := range options.auxAddresses.GetAll() {
|
||||
if aa == "" {
|
||||
continue
|
||||
}
|
||||
auxAddr, err := netip.ParseAddr(aa)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
match := false
|
||||
for _, s := range options.subnets {
|
||||
ok, err := subnetMatches(s, aa)
|
||||
ok, err := subnetMatches(s, auxAddr.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
iData[s].AuxAddress[key] = aa
|
||||
iData[s].AuxAddress[name] = auxAddr
|
||||
match = true
|
||||
}
|
||||
if !match {
|
||||
|
||||
Reference in New Issue
Block a user