mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
When assigning an address for an endpoint set preferred address and
options. When requesting a gateway address send a gateway label in the options. Signed-off-by: Ryan Belgrave <rmb1993@gmail.com>
This commit is contained in:
parent
405a737a48
commit
44f532f16e
3 changed files with 17 additions and 2 deletions
|
@ -60,6 +60,8 @@ type endpoint struct {
|
|||
anonymous bool
|
||||
generic map[string]interface{}
|
||||
joinLeaveDone chan struct{}
|
||||
prefAddress net.IP
|
||||
ipamOptions map[string]string
|
||||
dbIndex uint64
|
||||
dbExists bool
|
||||
sync.Mutex
|
||||
|
@ -685,6 +687,14 @@ func EndpointOptionGeneric(generic map[string]interface{}) EndpointOption {
|
|||
}
|
||||
}
|
||||
|
||||
// CreateOptionIpam function returns an option setter for the ipam configuration for this endpoint
|
||||
func CreateOptionIpam(prefAddress net.IP, ipamOptions map[string]string) EndpointOption {
|
||||
return func(ep *endpoint) {
|
||||
ep.prefAddress = prefAddress
|
||||
ep.ipamOptions = ipamOptions
|
||||
}
|
||||
}
|
||||
|
||||
// CreateOptionExposedPorts function returns an option setter for the container exposed
|
||||
// ports option to be passed to network.CreateEndpoint() method.
|
||||
func CreateOptionExposedPorts(exposedPorts []types.TransportPort) EndpointOption {
|
||||
|
@ -799,7 +809,7 @@ func (ep *endpoint) assignAddressVersion(ipVer int, ipam ipamapi.Ipam) error {
|
|||
if *address != nil {
|
||||
prefIP = (*address).IP
|
||||
}
|
||||
addr, _, err := ipam.RequestAddress(d.PoolID, prefIP, nil)
|
||||
addr, _, err := ipam.RequestAddress(d.PoolID, prefIP, ep.ipamOptions)
|
||||
if err == nil {
|
||||
ep.Lock()
|
||||
*address = addr
|
||||
|
|
|
@ -16,6 +16,8 @@ const (
|
|||
DefaultIPAM = "default"
|
||||
// PluginEndpointType represents the Endpoint Type used by Plugin system
|
||||
PluginEndpointType = "IpamDriver"
|
||||
// RequestAddressType represents the Address Type used when requesting an address
|
||||
RequestAddressType = "RequestAddressType"
|
||||
)
|
||||
|
||||
// Callback provides a Callback interface for registering an IPAM instance into LibNetwork
|
||||
|
|
|
@ -971,7 +971,10 @@ func (n *network) ipamAllocateVersion(ipVer int, ipam ipamapi.Ipam) error {
|
|||
// irrespective of whether ipam driver returned a gateway already.
|
||||
// If none of the above is true, libnetwork will allocate one.
|
||||
if cfg.Gateway != "" || d.Gateway == nil {
|
||||
if d.Gateway, _, err = ipam.RequestAddress(d.PoolID, net.ParseIP(cfg.Gateway), nil); err != nil {
|
||||
var gatewayOpts = map[string]string{
|
||||
ipamapi.RequestAddressType: netlabel.Gateway,
|
||||
}
|
||||
if d.Gateway, _, err = ipam.RequestAddress(d.PoolID, net.ParseIP(cfg.Gateway), gatewayOpts); err != nil {
|
||||
return types.InternalErrorf("failed to allocate gateway (%v): %v", cfg.Gateway, err)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue