From bafc66d7dfa6a8d32e9fc9447ff4bae69343191d Mon Sep 17 00:00:00 2001 From: Divya Vavili Date: Tue, 1 Mar 2016 22:34:54 -0800 Subject: [PATCH 1/3] Add DNS options to RequestAddress API Signed-off-by: Divya Vavili --- endpoint.go | 22 +++++++++++++++++----- endpoint_info.go | 39 +++++++++++++++++++++++++++++++-------- ipam/allocator.go | 18 +++++++++--------- ipamapi/contract.go | 2 +- ipams/remote/api/api.go | 6 ++++-- ipams/remote/remote.go | 6 +++--- network.go | 4 ++-- 7 files changed, 67 insertions(+), 30 deletions(-) diff --git a/endpoint.go b/endpoint.go index f0af1e7538..ebf6f3fe2f 100644 --- a/endpoint.go +++ b/endpoint.go @@ -391,6 +391,12 @@ func (ep *endpoint) sbJoin(sb *sandbox, options ...EndpointOption) error { } }() + sb.config.dnsList = append(sb.config.dnsList, ep.iface.dnsServers...) + sb.config.dnsSearchList = append(sb.config.dnsSearchList, ep.iface.dnsSearchDomains...) + if err = sb.setupResolutionFiles(); err != nil { + log.Errorf("Error in setting up resolution files: err %+v", err) + } + nid := n.ID() ep.processOptions(options...) @@ -887,13 +893,17 @@ func (ep *endpoint) assignAddress(ipam ipamapi.Ipam, assignIPv4, assignIPv6 bool func (ep *endpoint) assignAddressVersion(ipVer int, ipam ipamapi.Ipam) error { var ( - poolID *string - address **net.IPNet - prefAdd net.IP - progAdd net.IP + poolID *string + address **net.IPNet + dnsServers *[]string + dnsSearchDomains *[]string + prefAdd net.IP + progAdd net.IP ) n := ep.getNetwork() + dnsServers = &ep.iface.dnsServers + dnsSearchDomains = &ep.iface.dnsSearchDomains switch ipVer { case 4: poolID = &ep.iface.v4PoolID @@ -926,10 +936,12 @@ func (ep *endpoint) assignAddressVersion(ipVer int, ipam ipamapi.Ipam) error { if progAdd != nil && !d.Pool.Contains(progAdd) { continue } - addr, _, err := ipam.RequestAddress(d.PoolID, progAdd, ep.ipamOptions) + addr, dnsServerList, dnsSearchList, _, err := ipam.RequestAddress(d.PoolID, progAdd, ep.ipamOptions) if err == nil { ep.Lock() *address = addr + *dnsServers = dnsServerList + *dnsSearchDomains = dnsSearchList *poolID = d.PoolID ep.Unlock() return nil diff --git a/endpoint_info.go b/endpoint_info.go index 4ba8e3d548..64c6beee3d 100644 --- a/endpoint_info.go +++ b/endpoint_info.go @@ -46,14 +46,16 @@ type InterfaceInfo interface { } type endpointInterface struct { - mac net.HardwareAddr - addr *net.IPNet - addrv6 *net.IPNet - srcName string - dstPrefix string - routes []*net.IPNet - v4PoolID string - v6PoolID string + mac net.HardwareAddr + addr *net.IPNet + addrv6 *net.IPNet + dnsServers []string + dnsSearchDomains []string + srcName string + dstPrefix string + routes []*net.IPNet + v4PoolID string + v6PoolID string } func (epi *endpointInterface) MarshalJSON() ([]byte, error) { @@ -67,6 +69,8 @@ func (epi *endpointInterface) MarshalJSON() ([]byte, error) { if epi.addrv6 != nil { epMap["addrv6"] = epi.addrv6.String() } + epMap["dnsServers"] = epi.dnsServers + epMap["dnsSearchDomains"] = epi.dnsSearchDomains epMap["srcName"] = epi.srcName epMap["dstPrefix"] = epi.dstPrefix var routes []string @@ -103,6 +107,16 @@ func (epi *endpointInterface) UnmarshalJSON(b []byte) error { } } + ds, _ := json.Marshal(epMap["dnsServers"]) + var dnsServers []string + json.Unmarshal(ds, &dnsServers) + epi.dnsServers = dnsServers + + dsl, _ := json.Marshal(epMap["dnsSearchDomains"]) + var dnsSearchDomains []string + json.Unmarshal(dsl, &dnsSearchDomains) + epi.dnsSearchDomains = dnsSearchDomains + epi.srcName = epMap["srcName"].(string) epi.dstPrefix = epMap["dstPrefix"].(string) @@ -127,6 +141,15 @@ func (epi *endpointInterface) CopyTo(dstEpi *endpointInterface) error { dstEpi.mac = types.GetMacCopy(epi.mac) dstEpi.addr = types.GetIPNetCopy(epi.addr) dstEpi.addrv6 = types.GetIPNetCopy(epi.addrv6) + + dstEpi.dnsServers = make([]string, len(epi.dnsServers)) + copy(dstEpi.dnsServers, epi.dnsServers) + dstEpi.dnsServers = epi.dnsServers + + dstEpi.dnsSearchDomains = make([]string, len(epi.dnsSearchDomains)) + copy(dstEpi.dnsSearchDomains, epi.dnsSearchDomains) + dstEpi.dnsSearchDomains = epi.dnsSearchDomains + dstEpi.srcName = epi.srcName dstEpi.dstPrefix = epi.dstPrefix dstEpi.v4PoolID = epi.v4PoolID diff --git a/ipam/allocator.go b/ipam/allocator.go index 70fe06eba7..0f610fadfb 100644 --- a/ipam/allocator.go +++ b/ipam/allocator.go @@ -416,32 +416,32 @@ func (a *Allocator) getPredefinedPool(as string, ipV6 bool) (*net.IPNet, error) } // RequestAddress returns an address from the specified pool ID -func (a *Allocator) RequestAddress(poolID string, prefAddress net.IP, opts map[string]string) (*net.IPNet, map[string]string, error) { +func (a *Allocator) RequestAddress(poolID string, prefAddress net.IP, opts map[string]string) (*net.IPNet, []string, []string, map[string]string, error) { log.Debugf("RequestAddress(%s, %v, %v)", poolID, prefAddress, opts) k := SubnetKey{} if err := k.FromString(poolID); err != nil { - return nil, nil, types.BadRequestErrorf("invalid pool id: %s", poolID) + return nil, nil, nil, nil, types.BadRequestErrorf("invalid pool id: %s", poolID) } if err := a.refresh(k.AddressSpace); err != nil { - return nil, nil, err + return nil, nil, nil, nil, err } aSpace, err := a.getAddrSpace(k.AddressSpace) if err != nil { - return nil, nil, err + return nil, nil, nil, nil, err } aSpace.Lock() p, ok := aSpace.subnets[k] if !ok { aSpace.Unlock() - return nil, nil, types.NotFoundErrorf("cannot find address pool for poolID:%s", poolID) + return nil, nil, nil, nil, types.NotFoundErrorf("cannot find address pool for poolID:%s", poolID) } if prefAddress != nil && !p.Pool.Contains(prefAddress) { aSpace.Unlock() - return nil, nil, ipamapi.ErrIPOutOfRange + return nil, nil, nil, nil, ipamapi.ErrIPOutOfRange } c := p @@ -453,15 +453,15 @@ func (a *Allocator) RequestAddress(poolID string, prefAddress net.IP, opts map[s bm, err := a.retrieveBitmask(k, c.Pool) if err != nil { - return nil, nil, types.InternalErrorf("could not find bitmask in datastore for %s on address %v request from pool %s: %v", + return nil, nil, nil, nil, types.InternalErrorf("could not find bitmask in datastore for %s on address %v request from pool %s: %v", k.String(), prefAddress, poolID, err) } ip, err := a.getAddress(p.Pool, bm, prefAddress, p.Range) if err != nil { - return nil, nil, err + return nil, nil, nil, nil, err } - return &net.IPNet{IP: ip, Mask: p.Pool.Mask}, nil, nil + return &net.IPNet{IP: ip, Mask: p.Pool.Mask}, nil, nil, nil, nil } // ReleaseAddress releases the address from the specified pool ID diff --git a/ipamapi/contract.go b/ipamapi/contract.go index 513e482349..4f4fd84648 100644 --- a/ipamapi/contract.go +++ b/ipamapi/contract.go @@ -73,7 +73,7 @@ type Ipam interface { // ReleasePool releases the address pool identified by the passed id ReleasePool(poolID string) error // Request address from the specified pool ID. Input options or required IP can be passed. - RequestAddress(string, net.IP, map[string]string) (*net.IPNet, map[string]string, error) + RequestAddress(string, net.IP, map[string]string) (*net.IPNet, []string, []string, map[string]string, error) // Release the address from the specified pool ID ReleaseAddress(string, net.IP) error } diff --git a/ipams/remote/api/api.go b/ipams/remote/api/api.go index e357630cbb..c93611c28b 100644 --- a/ipams/remote/api/api.go +++ b/ipams/remote/api/api.go @@ -74,8 +74,10 @@ type RequestAddressRequest struct { // RequestAddressResponse represents the expected data in the response message to a ``request address`` request type RequestAddressResponse struct { Response - Address string // in CIDR format - Data map[string]string + Address string // in CIDR format + DNSServers []string + DNSSearchDomains []string + Data map[string]string } // ReleaseAddressRequest represents the expected data in a ``release address`` request message diff --git a/ipams/remote/remote.go b/ipams/remote/remote.go index 799a2e77f4..357f1170a0 100644 --- a/ipams/remote/remote.go +++ b/ipams/remote/remote.go @@ -95,7 +95,7 @@ func (a *allocator) ReleasePool(poolID string) error { } // RequestAddress requests an address from the address pool -func (a *allocator) RequestAddress(poolID string, address net.IP, options map[string]string) (*net.IPNet, map[string]string, error) { +func (a *allocator) RequestAddress(poolID string, address net.IP, options map[string]string) (*net.IPNet, []string, []string, map[string]string, error) { var ( prefAddress string retAddress *net.IPNet @@ -107,12 +107,12 @@ func (a *allocator) RequestAddress(poolID string, address net.IP, options map[st req := &api.RequestAddressRequest{PoolID: poolID, Address: prefAddress, Options: options} res := &api.RequestAddressResponse{} if err := a.call("RequestAddress", req, res); err != nil { - return nil, nil, err + return nil, nil, nil, nil, err } if res.Address != "" { retAddress, err = types.ParseCIDR(res.Address) } - return retAddress, res.Data, err + return retAddress, res.DNSServers, res.DNSSearchDomains, res.Data, err } // ReleaseAddress releases the address from the specified address pool diff --git a/network.go b/network.go index 25dc39c3f5..4d1a9fc23f 100644 --- a/network.go +++ b/network.go @@ -1055,7 +1055,7 @@ func (n *network) ipamAllocateVersion(ipVer int, ipam ipamapi.Ipam) error { var gatewayOpts = map[string]string{ ipamapi.RequestAddressType: netlabel.Gateway, } - if d.Gateway, _, err = ipam.RequestAddress(d.PoolID, net.ParseIP(cfg.Gateway), gatewayOpts); err != nil { + 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) } } @@ -1073,7 +1073,7 @@ func (n *network) ipamAllocateVersion(ipVer int, ipam ipamapi.Ipam) error { return types.ForbiddenErrorf("auxilairy address: (%s:%s) must belong to the master pool: %s", k, v, d.Pool) } // Attempt reservation in the container addressable pool, silent the error if address does not belong to that pool - if d.IPAMData.AuxAddresses[k], _, err = ipam.RequestAddress(d.PoolID, ip, nil); err != nil && err != ipamapi.ErrIPOutOfRange { + if d.IPAMData.AuxAddresses[k], _, _, _, err = ipam.RequestAddress(d.PoolID, ip, nil); err != nil && err != ipamapi.ErrIPOutOfRange { return types.InternalErrorf("failed to allocate secondary ip address (%s:%s): %v", k, v, err) } } From 3d80368b9907c949609ab37dbf4b3d2f927549f2 Mon Sep 17 00:00:00 2001 From: Divya Vavili Date: Tue, 1 Mar 2016 10:34:58 -0800 Subject: [PATCH 2/3] Adding test cases to test DNS options in RequestAddress Signed-off-by: Divya Vavili --- ipam/allocator_test.go | 56 +++++++++++++-------------- ipams/remote/remote_test.go | 30 ++++++++++++-- ipams/windowsipam/windowsipam.go | 8 ++-- ipams/windowsipam/windowsipam_test.go | 4 +- 4 files changed, 61 insertions(+), 37 deletions(-) diff --git a/ipam/allocator_test.go b/ipam/allocator_test.go index 74c8199630..0bcf722b60 100644 --- a/ipam/allocator_test.go +++ b/ipam/allocator_test.go @@ -176,7 +176,7 @@ func TestSubnetsMarshal(t *testing.T) { if err != nil { t.Fatal(err) } - _, _, err = a.RequestAddress(pid0, nil, nil) + _, _, _, _, err = a.RequestAddress(pid0, nil, nil) if err != nil { t.Fatal(err) } @@ -192,7 +192,7 @@ func TestSubnetsMarshal(t *testing.T) { } expIP := &net.IPNet{IP: net.IP{192, 168, 0, 2}, Mask: net.IPMask{255, 255, 0, 0}} - ip, _, err := a.RequestAddress(pid0, nil, nil) + ip, _, _, _, err := a.RequestAddress(pid0, nil, nil) if err != nil { t.Fatal(err) } @@ -201,7 +201,7 @@ func TestSubnetsMarshal(t *testing.T) { } expIP = &net.IPNet{IP: net.IP{192, 169, 0, 1}, Mask: net.IPMask{255, 255, 0, 0}} - ip, _, err = a.RequestAddress(pid1, nil, nil) + ip, _, _, _, err = a.RequestAddress(pid1, nil, nil) if err != nil { t.Fatal(err) } @@ -556,12 +556,12 @@ func TestGetSameAddress(t *testing.T) { } ip := net.ParseIP("192.168.100.250") - _, _, err = a.RequestAddress(pid, ip, nil) + _, _, _, _, err = a.RequestAddress(pid, ip, nil) if err != nil { t.Fatal(err) } - _, _, err = a.RequestAddress(pid, ip, nil) + _, _, _, _, err = a.RequestAddress(pid, ip, nil) if err == nil { t.Fatal(err) } @@ -578,7 +578,7 @@ func TestGetAddressSubPoolEqualPool(t *testing.T) { t.Fatal(err) } - _, _, err = a.RequestAddress(pid, nil, nil) + _, _, _, _, err = a.RequestAddress(pid, nil, nil) if err != nil { t.Fatal(err) } @@ -606,7 +606,7 @@ func TestRequestReleaseAddressFromSubPool(t *testing.T) { expected := &net.IPNet{IP: net.IP{172, 28, 30, 255}, Mask: net.IPMask{255, 255, 0, 0}} for err == nil { var c *net.IPNet - if c, _, err = a.RequestAddress(poolID, nil, nil); err == nil { + if c, _, _, _, err = a.RequestAddress(poolID, nil, nil); err == nil { ip = c } } @@ -620,7 +620,7 @@ func TestRequestReleaseAddressFromSubPool(t *testing.T) { if err = a.ReleaseAddress(poolID, rp.IP); err != nil { t.Fatal(err) } - if ip, _, err = a.RequestAddress(poolID, nil, nil); err != nil { + if ip, _, _, _, err = a.RequestAddress(poolID, nil, nil); err != nil { t.Fatal(err) } if !types.CompareIPNet(rp, ip) { @@ -638,7 +638,7 @@ func TestRequestReleaseAddressFromSubPool(t *testing.T) { expected = &net.IPNet{IP: net.IP{10, 0, 0, 255}, Mask: net.IPMask{255, 255, 0, 0}} for err == nil { var c *net.IPNet - if c, _, err = a.RequestAddress(poolID, nil, nil); err == nil { + if c, _, _, _, err = a.RequestAddress(poolID, nil, nil); err == nil { ip = c } } @@ -652,7 +652,7 @@ func TestRequestReleaseAddressFromSubPool(t *testing.T) { if err = a.ReleaseAddress(poolID, rp.IP); err != nil { t.Fatal(err) } - if ip, _, err = a.RequestAddress(poolID, nil, nil); err != nil { + if ip, _, _, _, err = a.RequestAddress(poolID, nil, nil); err != nil { t.Fatal(err) } if !types.CompareIPNet(rp, ip) { @@ -666,7 +666,7 @@ func TestRequestReleaseAddressFromSubPool(t *testing.T) { if poolID, _, _, err = a.RequestPool("rosso", "10.2.0.0/16", "10.2.2.0/24", nil, false); err != nil { t.Fatal(err) } - tre, _, err := a.RequestAddress(poolID, treExp.IP, nil) + tre, _, _, _, err := a.RequestAddress(poolID, treExp.IP, nil) if err != nil { t.Fatal(err) } @@ -674,7 +674,7 @@ func TestRequestReleaseAddressFromSubPool(t *testing.T) { t.Fatalf("Unexpected address: %v", tre) } - uno, _, err := a.RequestAddress(poolID, nil, nil) + uno, _, _, _, err := a.RequestAddress(poolID, nil, nil) if err != nil { t.Fatal(err) } @@ -682,7 +682,7 @@ func TestRequestReleaseAddressFromSubPool(t *testing.T) { t.Fatalf("Unexpected address: %v", uno) } - due, _, err := a.RequestAddress(poolID, nil, nil) + due, _, _, _, err := a.RequestAddress(poolID, nil, nil) if err != nil { t.Fatal(err) } @@ -693,7 +693,7 @@ func TestRequestReleaseAddressFromSubPool(t *testing.T) { if err = a.ReleaseAddress(poolID, uno.IP); err != nil { t.Fatal(err) } - uno, _, err = a.RequestAddress(poolID, nil, nil) + uno, _, _, _, err = a.RequestAddress(poolID, nil, nil) if err != nil { t.Fatal(err) } @@ -704,7 +704,7 @@ func TestRequestReleaseAddressFromSubPool(t *testing.T) { if err = a.ReleaseAddress(poolID, tre.IP); err != nil { t.Fatal(err) } - tre, _, err = a.RequestAddress(poolID, nil, nil) + tre, _, _, _, err = a.RequestAddress(poolID, nil, nil) if err != nil { t.Fatal(err) } @@ -765,19 +765,19 @@ func TestRequestSyntaxCheck(t *testing.T) { t.Fatalf("Unexpected failure: %v", err) } - _, _, err = a.RequestAddress("", nil, nil) + _, _, _, _, err = a.RequestAddress("", nil, nil) if err == nil { t.Fatalf("Failed to detect wrong request: no pool id specified") } ip := net.ParseIP("172.17.0.23") - _, _, err = a.RequestAddress(pid, ip, nil) + _, _, _, _, err = a.RequestAddress(pid, ip, nil) if err == nil { t.Fatalf("Failed to detect wrong request: requested IP from different subnet") } ip = net.ParseIP("192.168.0.50") - _, _, err = a.RequestAddress(pid, ip, nil) + _, _, _, _, err = a.RequestAddress(pid, ip, nil) if err != nil { t.Fatalf("Unexpected failure: %v", err) } @@ -848,7 +848,7 @@ func TestRelease(t *testing.T) { // Allocate all addresses for err != ipamapi.ErrNoAvailableIPs { - _, _, err = a.RequestAddress(pid, nil, nil) + _, _, _, _, err = a.RequestAddress(pid, nil, nil) } toRelease := []struct { @@ -887,7 +887,7 @@ func TestRelease(t *testing.T) { t.Fatalf("Failed to update free address count after release. Expected %d, Found: %d", i+1, bm.Unselected()) } - nw, _, err := a.RequestAddress(pid, nil, nil) + nw, _, _, _, err := a.RequestAddress(pid, nil, nil) if err != nil { t.Fatalf("Failed to obtain the address: %s", err.Error()) } @@ -954,7 +954,7 @@ func assertNRequests(t *testing.T, subnet string, numReq int, lastExpectedIP str i := 0 start := time.Now() for ; i < numReq; i++ { - nw, _, err = a.RequestAddress(pid, nil, nil) + nw, _, _, _, err = a.RequestAddress(pid, nil, nil) } if printTime { fmt.Printf("\nTaken %v, to allocate %d addresses on %s\n", time.Since(start), numReq, subnet) @@ -968,7 +968,7 @@ func assertNRequests(t *testing.T, subnet string, numReq int, lastExpectedIP str func benchmarkRequest(b *testing.B, a *Allocator, subnet string) { pid, _, _, err := a.RequestPool(localAddressSpace, subnet, "", nil, false) for err != ipamapi.ErrNoAvailableIPs { - _, _, err = a.RequestAddress(pid, nil, nil) + _, _, _, _, err = a.RequestAddress(pid, nil, nil) } } @@ -1019,7 +1019,7 @@ func testAllocateRandomDeallocate(t *testing.T, pool, subPool string, num int) { indices := make(map[int]*net.IPNet, num) allocated := make(map[string]bool, num) for i := 0; i < num; i++ { - ip, _, err := a.RequestAddress(pid, nil, nil) + ip, _, _, _, err := a.RequestAddress(pid, nil, nil) if err != nil { t.Fatal(err) } @@ -1052,7 +1052,7 @@ func testAllocateRandomDeallocate(t *testing.T, pool, subPool string, num int) { // Request a quarter of addresses for i := 0; i < num/2; i++ { - ip, _, err := a.RequestAddress(pid, nil, nil) + ip, _, _, _, err := a.RequestAddress(pid, nil, nil) if err != nil { t.Fatal(err) } @@ -1082,7 +1082,7 @@ func TestRetrieveFromStore(t *testing.T) { t.Fatal(err) } for i := 0; i < num; i++ { - if _, _, err := a.RequestAddress(pid, nil, nil); err != nil { + if _, _, _, _, err := a.RequestAddress(pid, nil, nil); err != nil { t.Fatal(err) } } @@ -1104,7 +1104,7 @@ func TestRetrieveFromStore(t *testing.T) { t.Fatal(err) } for i := 0; i < num/2; i++ { - if _, _, err := a1.RequestAddress(pid, nil, nil); err != nil { + if _, _, _, _, err := a1.RequestAddress(pid, nil, nil); err != nil { t.Fatal(err) } } @@ -1121,7 +1121,7 @@ func TestRetrieveFromStore(t *testing.T) { t.Fatal(err) } for i := 0; i < num/2; i++ { - if _, _, err := a2.RequestAddress(pid, nil, nil); err != nil { + if _, _, _, _, err := a2.RequestAddress(pid, nil, nil); err != nil { t.Fatal(err) } } @@ -1138,7 +1138,7 @@ func TestRetrieveFromStore(t *testing.T) { t.Fatal(err) } for i := 0; i < num/2; i++ { - if _, _, err := a3.RequestAddress(pid, nil, nil); err != nil { + if _, _, _, _, err := a3.RequestAddress(pid, nil, nil); err != nil { t.Fatal(err) } } diff --git a/ipams/remote/remote_test.go b/ipams/remote/remote_test.go index 3c6cc4bfa9..c75391825b 100644 --- a/ipams/remote/remote_test.go +++ b/ipams/remote/remote_test.go @@ -197,8 +197,12 @@ func TestRemoteDriver(t *testing.T) { ip = "172.20.0.34" } ip = fmt.Sprintf("%s/16", ip) + dnsList := []string{"172.20.0.1", "172.20.0.2"} + dnsSearchList := []string{"domain1", "domain2"} return map[string]interface{}{ - "Address": ip, + "Address": ip, + "DNSServers": dnsList, + "DNSSearchDomains": dnsSearchList, } }) @@ -267,7 +271,7 @@ func TestRemoteDriver(t *testing.T) { } // Request any address - addr, _, err := d.RequestAddress(poolID2, nil, nil) + addr, dnsList, dnsSearchDomains, _, err := d.RequestAddress(poolID2, nil, nil) if err != nil { t.Fatal(err) } @@ -275,8 +279,28 @@ func TestRemoteDriver(t *testing.T) { t.Fatalf("Unexpected address: %s", addr) } + expectedDNSList := []string{"172.20.0.1", "172.20.0.2"} + if dnsList == nil || len(dnsList) != len(expectedDNSList) { + t.Fatalf("Unexpected DNS list: %+v", dnsList) + } + for i, exp := range expectedDNSList { + if dnsList[i] != exp { + t.Fatalf("Expected DNS IP: %s, got %s", exp, dnsList[i]) + } + } + + expectedDNSSearchDomains := []string{"domain1", "domain2"} + if dnsSearchDomains == nil || len(dnsSearchDomains) != len(expectedDNSSearchDomains) { + t.Fatalf("Unexpected DNS Search Domains: %+v", dnsSearchDomains) + } + for i, exp := range expectedDNSSearchDomains { + if dnsSearchDomains[i] != exp { + t.Fatalf("Expected DNS Search domain: %s, got %s", exp, dnsSearchDomains[i]) + } + } + // Request specific address - addr2, _, err := d.RequestAddress(poolID2, net.ParseIP("172.20.1.45"), nil) + addr2, _, _, _, err := d.RequestAddress(poolID2, net.ParseIP("172.20.1.45"), nil) if err != nil { t.Fatal(err) } diff --git a/ipams/windowsipam/windowsipam.go b/ipams/windowsipam/windowsipam.go index a92d5ccd77..a1723bd6d3 100644 --- a/ipams/windowsipam/windowsipam.go +++ b/ipams/windowsipam/windowsipam.go @@ -69,17 +69,17 @@ func (a *allocator) RequestAddress(poolID string, prefAddress net.IP, opts map[s _, ipNet, err := net.ParseCIDR(poolID) if err != nil { - return nil, nil, err + return nil, nil, nil, nil, err } // TODO Windows: Remove this once the bug in docker daemon is fixed // that causes it to throw an exception on nil gateway if opts[ipamapi.RequestAddressType] == netlabel.Gateway { - return ipNet, nil, nil + return ipNet, nil, nil, nil, nil } else if prefAddress == nil { - return nil, nil, nil + return nil, nil, nil, nil, nil } - return &net.IPNet{IP: prefAddress, Mask: ipNet.Mask}, nil, nil + return &net.IPNet{IP: prefAddress, Mask: ipNet.Mask}, nil, nil, nil, nil } // ReleaseAddress releases the address - always succeeds diff --git a/ipams/windowsipam/windowsipam_test.go b/ipams/windowsipam/windowsipam_test.go index 3fee5e690c..20edb009cb 100644 --- a/ipams/windowsipam/windowsipam_test.go +++ b/ipams/windowsipam/windowsipam_test.go @@ -46,7 +46,7 @@ func TestWindowsIPAM(t *testing.T) { t.Fatal(err) } - ip, _, err := a.RequestAddress(requestPool.String(), nil, map[string]string{}) + ip, _, _, _, err := a.RequestAddress(requestPool.String(), nil, map[string]string{}) if err != nil { t.Fatal(err) } @@ -55,7 +55,7 @@ func TestWindowsIPAM(t *testing.T) { t.Fatalf("Unexpected data returned. Expected %v . Got: %v ", requestPool, ip) } - ip, _, err = a.RequestAddress(requestPool.String(), requestAddress, map[string]string{}) + ip, _, _, _, err = a.RequestAddress(requestPool.String(), requestAddress, map[string]string{}) if err != nil { t.Fatal(err) } From a1452ed9c5f6ca0d9e63b32d4dfd8c866c9e47f0 Mon Sep 17 00:00:00 2001 From: Divya Vavili Date: Tue, 8 Mar 2016 15:44:06 -0800 Subject: [PATCH 3/3] Moving DNS options to IPAM data Signed-off-by: Divya Vavili --- endpoint.go | 32 +++++++++++---- ipam/allocator.go | 18 ++++----- ipam/allocator_test.go | 56 +++++++++++++-------------- ipamapi/contract.go | 2 +- ipams/remote/api/api.go | 6 +-- ipams/remote/remote.go | 6 +-- ipams/remote/remote_test.go | 15 ++++--- ipams/windowsipam/windowsipam.go | 8 ++-- ipams/windowsipam/windowsipam_test.go | 4 +- network.go | 4 +- 10 files changed, 86 insertions(+), 65 deletions(-) diff --git a/endpoint.go b/endpoint.go index ebf6f3fe2f..2456a46abf 100644 --- a/endpoint.go +++ b/endpoint.go @@ -391,10 +391,12 @@ func (ep *endpoint) sbJoin(sb *sandbox, options ...EndpointOption) error { } }() - sb.config.dnsList = append(sb.config.dnsList, ep.iface.dnsServers...) - sb.config.dnsSearchList = append(sb.config.dnsSearchList, ep.iface.dnsSearchDomains...) - if err = sb.setupResolutionFiles(); err != nil { - log.Errorf("Error in setting up resolution files: err %+v", err) + if len(ep.iface.dnsServers) > 0 || len(ep.iface.dnsSearchDomains) > 0 { + sb.config.dnsList = appendUnique(sb.config.dnsList, ep.iface.dnsServers) + sb.config.dnsSearchList = appendUnique(sb.config.dnsSearchList, ep.iface.dnsSearchDomains) + if err = sb.setupResolutionFiles(); err != nil { + log.Errorf("Error in setting up resolution files: err %+v", err) + } } nid := n.ID() @@ -478,6 +480,18 @@ func (ep *endpoint) sbJoin(sb *sandbox, options ...EndpointOption) error { return sb.clearDefaultGW() } +func appendUnique(list1, list2 []string) []string { + encountered := map[string]bool{} + var result []string + for _, el := range append(list1, list2...) { + if !encountered[el] { + encountered[el] = true + result = append(result, el) + } + } + return result +} + func (ep *endpoint) rename(name string) error { var err error n := ep.getNetwork() @@ -936,12 +950,16 @@ func (ep *endpoint) assignAddressVersion(ipVer int, ipam ipamapi.Ipam) error { if progAdd != nil && !d.Pool.Contains(progAdd) { continue } - addr, dnsServerList, dnsSearchList, _, err := ipam.RequestAddress(d.PoolID, progAdd, ep.ipamOptions) + addr, ipamData, err := ipam.RequestAddress(d.PoolID, progAdd, ep.ipamOptions) if err == nil { ep.Lock() *address = addr - *dnsServers = dnsServerList - *dnsSearchDomains = dnsSearchList + if len(ipamData["DNSServers"]) > 0 { + *dnsServers = strings.Split(ipamData["DNSServers"], " ") + } + if len(ipamData["DNSSearchDomains"]) > 0 { + *dnsSearchDomains = strings.Split(ipamData["DNSSearchDomains"], " ") + } *poolID = d.PoolID ep.Unlock() return nil diff --git a/ipam/allocator.go b/ipam/allocator.go index 0f610fadfb..70fe06eba7 100644 --- a/ipam/allocator.go +++ b/ipam/allocator.go @@ -416,32 +416,32 @@ func (a *Allocator) getPredefinedPool(as string, ipV6 bool) (*net.IPNet, error) } // RequestAddress returns an address from the specified pool ID -func (a *Allocator) RequestAddress(poolID string, prefAddress net.IP, opts map[string]string) (*net.IPNet, []string, []string, map[string]string, error) { +func (a *Allocator) RequestAddress(poolID string, prefAddress net.IP, opts map[string]string) (*net.IPNet, map[string]string, error) { log.Debugf("RequestAddress(%s, %v, %v)", poolID, prefAddress, opts) k := SubnetKey{} if err := k.FromString(poolID); err != nil { - return nil, nil, nil, nil, types.BadRequestErrorf("invalid pool id: %s", poolID) + return nil, nil, types.BadRequestErrorf("invalid pool id: %s", poolID) } if err := a.refresh(k.AddressSpace); err != nil { - return nil, nil, nil, nil, err + return nil, nil, err } aSpace, err := a.getAddrSpace(k.AddressSpace) if err != nil { - return nil, nil, nil, nil, err + return nil, nil, err } aSpace.Lock() p, ok := aSpace.subnets[k] if !ok { aSpace.Unlock() - return nil, nil, nil, nil, types.NotFoundErrorf("cannot find address pool for poolID:%s", poolID) + return nil, nil, types.NotFoundErrorf("cannot find address pool for poolID:%s", poolID) } if prefAddress != nil && !p.Pool.Contains(prefAddress) { aSpace.Unlock() - return nil, nil, nil, nil, ipamapi.ErrIPOutOfRange + return nil, nil, ipamapi.ErrIPOutOfRange } c := p @@ -453,15 +453,15 @@ func (a *Allocator) RequestAddress(poolID string, prefAddress net.IP, opts map[s bm, err := a.retrieveBitmask(k, c.Pool) if err != nil { - return nil, nil, nil, nil, types.InternalErrorf("could not find bitmask in datastore for %s on address %v request from pool %s: %v", + return nil, nil, types.InternalErrorf("could not find bitmask in datastore for %s on address %v request from pool %s: %v", k.String(), prefAddress, poolID, err) } ip, err := a.getAddress(p.Pool, bm, prefAddress, p.Range) if err != nil { - return nil, nil, nil, nil, err + return nil, nil, err } - return &net.IPNet{IP: ip, Mask: p.Pool.Mask}, nil, nil, nil, nil + return &net.IPNet{IP: ip, Mask: p.Pool.Mask}, nil, nil } // ReleaseAddress releases the address from the specified pool ID diff --git a/ipam/allocator_test.go b/ipam/allocator_test.go index 0bcf722b60..74c8199630 100644 --- a/ipam/allocator_test.go +++ b/ipam/allocator_test.go @@ -176,7 +176,7 @@ func TestSubnetsMarshal(t *testing.T) { if err != nil { t.Fatal(err) } - _, _, _, _, err = a.RequestAddress(pid0, nil, nil) + _, _, err = a.RequestAddress(pid0, nil, nil) if err != nil { t.Fatal(err) } @@ -192,7 +192,7 @@ func TestSubnetsMarshal(t *testing.T) { } expIP := &net.IPNet{IP: net.IP{192, 168, 0, 2}, Mask: net.IPMask{255, 255, 0, 0}} - ip, _, _, _, err := a.RequestAddress(pid0, nil, nil) + ip, _, err := a.RequestAddress(pid0, nil, nil) if err != nil { t.Fatal(err) } @@ -201,7 +201,7 @@ func TestSubnetsMarshal(t *testing.T) { } expIP = &net.IPNet{IP: net.IP{192, 169, 0, 1}, Mask: net.IPMask{255, 255, 0, 0}} - ip, _, _, _, err = a.RequestAddress(pid1, nil, nil) + ip, _, err = a.RequestAddress(pid1, nil, nil) if err != nil { t.Fatal(err) } @@ -556,12 +556,12 @@ func TestGetSameAddress(t *testing.T) { } ip := net.ParseIP("192.168.100.250") - _, _, _, _, err = a.RequestAddress(pid, ip, nil) + _, _, err = a.RequestAddress(pid, ip, nil) if err != nil { t.Fatal(err) } - _, _, _, _, err = a.RequestAddress(pid, ip, nil) + _, _, err = a.RequestAddress(pid, ip, nil) if err == nil { t.Fatal(err) } @@ -578,7 +578,7 @@ func TestGetAddressSubPoolEqualPool(t *testing.T) { t.Fatal(err) } - _, _, _, _, err = a.RequestAddress(pid, nil, nil) + _, _, err = a.RequestAddress(pid, nil, nil) if err != nil { t.Fatal(err) } @@ -606,7 +606,7 @@ func TestRequestReleaseAddressFromSubPool(t *testing.T) { expected := &net.IPNet{IP: net.IP{172, 28, 30, 255}, Mask: net.IPMask{255, 255, 0, 0}} for err == nil { var c *net.IPNet - if c, _, _, _, err = a.RequestAddress(poolID, nil, nil); err == nil { + if c, _, err = a.RequestAddress(poolID, nil, nil); err == nil { ip = c } } @@ -620,7 +620,7 @@ func TestRequestReleaseAddressFromSubPool(t *testing.T) { if err = a.ReleaseAddress(poolID, rp.IP); err != nil { t.Fatal(err) } - if ip, _, _, _, err = a.RequestAddress(poolID, nil, nil); err != nil { + if ip, _, err = a.RequestAddress(poolID, nil, nil); err != nil { t.Fatal(err) } if !types.CompareIPNet(rp, ip) { @@ -638,7 +638,7 @@ func TestRequestReleaseAddressFromSubPool(t *testing.T) { expected = &net.IPNet{IP: net.IP{10, 0, 0, 255}, Mask: net.IPMask{255, 255, 0, 0}} for err == nil { var c *net.IPNet - if c, _, _, _, err = a.RequestAddress(poolID, nil, nil); err == nil { + if c, _, err = a.RequestAddress(poolID, nil, nil); err == nil { ip = c } } @@ -652,7 +652,7 @@ func TestRequestReleaseAddressFromSubPool(t *testing.T) { if err = a.ReleaseAddress(poolID, rp.IP); err != nil { t.Fatal(err) } - if ip, _, _, _, err = a.RequestAddress(poolID, nil, nil); err != nil { + if ip, _, err = a.RequestAddress(poolID, nil, nil); err != nil { t.Fatal(err) } if !types.CompareIPNet(rp, ip) { @@ -666,7 +666,7 @@ func TestRequestReleaseAddressFromSubPool(t *testing.T) { if poolID, _, _, err = a.RequestPool("rosso", "10.2.0.0/16", "10.2.2.0/24", nil, false); err != nil { t.Fatal(err) } - tre, _, _, _, err := a.RequestAddress(poolID, treExp.IP, nil) + tre, _, err := a.RequestAddress(poolID, treExp.IP, nil) if err != nil { t.Fatal(err) } @@ -674,7 +674,7 @@ func TestRequestReleaseAddressFromSubPool(t *testing.T) { t.Fatalf("Unexpected address: %v", tre) } - uno, _, _, _, err := a.RequestAddress(poolID, nil, nil) + uno, _, err := a.RequestAddress(poolID, nil, nil) if err != nil { t.Fatal(err) } @@ -682,7 +682,7 @@ func TestRequestReleaseAddressFromSubPool(t *testing.T) { t.Fatalf("Unexpected address: %v", uno) } - due, _, _, _, err := a.RequestAddress(poolID, nil, nil) + due, _, err := a.RequestAddress(poolID, nil, nil) if err != nil { t.Fatal(err) } @@ -693,7 +693,7 @@ func TestRequestReleaseAddressFromSubPool(t *testing.T) { if err = a.ReleaseAddress(poolID, uno.IP); err != nil { t.Fatal(err) } - uno, _, _, _, err = a.RequestAddress(poolID, nil, nil) + uno, _, err = a.RequestAddress(poolID, nil, nil) if err != nil { t.Fatal(err) } @@ -704,7 +704,7 @@ func TestRequestReleaseAddressFromSubPool(t *testing.T) { if err = a.ReleaseAddress(poolID, tre.IP); err != nil { t.Fatal(err) } - tre, _, _, _, err = a.RequestAddress(poolID, nil, nil) + tre, _, err = a.RequestAddress(poolID, nil, nil) if err != nil { t.Fatal(err) } @@ -765,19 +765,19 @@ func TestRequestSyntaxCheck(t *testing.T) { t.Fatalf("Unexpected failure: %v", err) } - _, _, _, _, err = a.RequestAddress("", nil, nil) + _, _, err = a.RequestAddress("", nil, nil) if err == nil { t.Fatalf("Failed to detect wrong request: no pool id specified") } ip := net.ParseIP("172.17.0.23") - _, _, _, _, err = a.RequestAddress(pid, ip, nil) + _, _, err = a.RequestAddress(pid, ip, nil) if err == nil { t.Fatalf("Failed to detect wrong request: requested IP from different subnet") } ip = net.ParseIP("192.168.0.50") - _, _, _, _, err = a.RequestAddress(pid, ip, nil) + _, _, err = a.RequestAddress(pid, ip, nil) if err != nil { t.Fatalf("Unexpected failure: %v", err) } @@ -848,7 +848,7 @@ func TestRelease(t *testing.T) { // Allocate all addresses for err != ipamapi.ErrNoAvailableIPs { - _, _, _, _, err = a.RequestAddress(pid, nil, nil) + _, _, err = a.RequestAddress(pid, nil, nil) } toRelease := []struct { @@ -887,7 +887,7 @@ func TestRelease(t *testing.T) { t.Fatalf("Failed to update free address count after release. Expected %d, Found: %d", i+1, bm.Unselected()) } - nw, _, _, _, err := a.RequestAddress(pid, nil, nil) + nw, _, err := a.RequestAddress(pid, nil, nil) if err != nil { t.Fatalf("Failed to obtain the address: %s", err.Error()) } @@ -954,7 +954,7 @@ func assertNRequests(t *testing.T, subnet string, numReq int, lastExpectedIP str i := 0 start := time.Now() for ; i < numReq; i++ { - nw, _, _, _, err = a.RequestAddress(pid, nil, nil) + nw, _, err = a.RequestAddress(pid, nil, nil) } if printTime { fmt.Printf("\nTaken %v, to allocate %d addresses on %s\n", time.Since(start), numReq, subnet) @@ -968,7 +968,7 @@ func assertNRequests(t *testing.T, subnet string, numReq int, lastExpectedIP str func benchmarkRequest(b *testing.B, a *Allocator, subnet string) { pid, _, _, err := a.RequestPool(localAddressSpace, subnet, "", nil, false) for err != ipamapi.ErrNoAvailableIPs { - _, _, _, _, err = a.RequestAddress(pid, nil, nil) + _, _, err = a.RequestAddress(pid, nil, nil) } } @@ -1019,7 +1019,7 @@ func testAllocateRandomDeallocate(t *testing.T, pool, subPool string, num int) { indices := make(map[int]*net.IPNet, num) allocated := make(map[string]bool, num) for i := 0; i < num; i++ { - ip, _, _, _, err := a.RequestAddress(pid, nil, nil) + ip, _, err := a.RequestAddress(pid, nil, nil) if err != nil { t.Fatal(err) } @@ -1052,7 +1052,7 @@ func testAllocateRandomDeallocate(t *testing.T, pool, subPool string, num int) { // Request a quarter of addresses for i := 0; i < num/2; i++ { - ip, _, _, _, err := a.RequestAddress(pid, nil, nil) + ip, _, err := a.RequestAddress(pid, nil, nil) if err != nil { t.Fatal(err) } @@ -1082,7 +1082,7 @@ func TestRetrieveFromStore(t *testing.T) { t.Fatal(err) } for i := 0; i < num; i++ { - if _, _, _, _, err := a.RequestAddress(pid, nil, nil); err != nil { + if _, _, err := a.RequestAddress(pid, nil, nil); err != nil { t.Fatal(err) } } @@ -1104,7 +1104,7 @@ func TestRetrieveFromStore(t *testing.T) { t.Fatal(err) } for i := 0; i < num/2; i++ { - if _, _, _, _, err := a1.RequestAddress(pid, nil, nil); err != nil { + if _, _, err := a1.RequestAddress(pid, nil, nil); err != nil { t.Fatal(err) } } @@ -1121,7 +1121,7 @@ func TestRetrieveFromStore(t *testing.T) { t.Fatal(err) } for i := 0; i < num/2; i++ { - if _, _, _, _, err := a2.RequestAddress(pid, nil, nil); err != nil { + if _, _, err := a2.RequestAddress(pid, nil, nil); err != nil { t.Fatal(err) } } @@ -1138,7 +1138,7 @@ func TestRetrieveFromStore(t *testing.T) { t.Fatal(err) } for i := 0; i < num/2; i++ { - if _, _, _, _, err := a3.RequestAddress(pid, nil, nil); err != nil { + if _, _, err := a3.RequestAddress(pid, nil, nil); err != nil { t.Fatal(err) } } diff --git a/ipamapi/contract.go b/ipamapi/contract.go index 4f4fd84648..513e482349 100644 --- a/ipamapi/contract.go +++ b/ipamapi/contract.go @@ -73,7 +73,7 @@ type Ipam interface { // ReleasePool releases the address pool identified by the passed id ReleasePool(poolID string) error // Request address from the specified pool ID. Input options or required IP can be passed. - RequestAddress(string, net.IP, map[string]string) (*net.IPNet, []string, []string, map[string]string, error) + RequestAddress(string, net.IP, map[string]string) (*net.IPNet, map[string]string, error) // Release the address from the specified pool ID ReleaseAddress(string, net.IP) error } diff --git a/ipams/remote/api/api.go b/ipams/remote/api/api.go index c93611c28b..e357630cbb 100644 --- a/ipams/remote/api/api.go +++ b/ipams/remote/api/api.go @@ -74,10 +74,8 @@ type RequestAddressRequest struct { // RequestAddressResponse represents the expected data in the response message to a ``request address`` request type RequestAddressResponse struct { Response - Address string // in CIDR format - DNSServers []string - DNSSearchDomains []string - Data map[string]string + Address string // in CIDR format + Data map[string]string } // ReleaseAddressRequest represents the expected data in a ``release address`` request message diff --git a/ipams/remote/remote.go b/ipams/remote/remote.go index 357f1170a0..799a2e77f4 100644 --- a/ipams/remote/remote.go +++ b/ipams/remote/remote.go @@ -95,7 +95,7 @@ func (a *allocator) ReleasePool(poolID string) error { } // RequestAddress requests an address from the address pool -func (a *allocator) RequestAddress(poolID string, address net.IP, options map[string]string) (*net.IPNet, []string, []string, map[string]string, error) { +func (a *allocator) RequestAddress(poolID string, address net.IP, options map[string]string) (*net.IPNet, map[string]string, error) { var ( prefAddress string retAddress *net.IPNet @@ -107,12 +107,12 @@ func (a *allocator) RequestAddress(poolID string, address net.IP, options map[st req := &api.RequestAddressRequest{PoolID: poolID, Address: prefAddress, Options: options} res := &api.RequestAddressResponse{} if err := a.call("RequestAddress", req, res); err != nil { - return nil, nil, nil, nil, err + return nil, nil, err } if res.Address != "" { retAddress, err = types.ParseCIDR(res.Address) } - return retAddress, res.DNSServers, res.DNSSearchDomains, res.Data, err + return retAddress, res.Data, err } // ReleaseAddress releases the address from the specified address pool diff --git a/ipams/remote/remote_test.go b/ipams/remote/remote_test.go index c75391825b..f4b0790138 100644 --- a/ipams/remote/remote_test.go +++ b/ipams/remote/remote_test.go @@ -9,6 +9,7 @@ import ( "net/http" "net/http/httptest" "os" + "strings" "testing" "github.com/docker/docker/pkg/plugins" @@ -199,10 +200,11 @@ func TestRemoteDriver(t *testing.T) { ip = fmt.Sprintf("%s/16", ip) dnsList := []string{"172.20.0.1", "172.20.0.2"} dnsSearchList := []string{"domain1", "domain2"} + ipamData := map[string]string{"DNSServers": strings.Join(dnsList, " "), + "DNSSearchDomains": strings.Join(dnsSearchList, " ")} return map[string]interface{}{ - "Address": ip, - "DNSServers": dnsList, - "DNSSearchDomains": dnsSearchList, + "Address": ip, + "Data": ipamData, } }) @@ -271,7 +273,7 @@ func TestRemoteDriver(t *testing.T) { } // Request any address - addr, dnsList, dnsSearchDomains, _, err := d.RequestAddress(poolID2, nil, nil) + addr, ipamData, err := d.RequestAddress(poolID2, nil, nil) if err != nil { t.Fatal(err) } @@ -279,6 +281,9 @@ func TestRemoteDriver(t *testing.T) { t.Fatalf("Unexpected address: %s", addr) } + dnsList := strings.Split(ipamData["DNSServers"], " ") + dnsSearchDomains := strings.Split(ipamData["DNSSearchDomains"], " ") + expectedDNSList := []string{"172.20.0.1", "172.20.0.2"} if dnsList == nil || len(dnsList) != len(expectedDNSList) { t.Fatalf("Unexpected DNS list: %+v", dnsList) @@ -300,7 +305,7 @@ func TestRemoteDriver(t *testing.T) { } // Request specific address - addr2, _, _, _, err := d.RequestAddress(poolID2, net.ParseIP("172.20.1.45"), nil) + addr2, _, err := d.RequestAddress(poolID2, net.ParseIP("172.20.1.45"), nil) if err != nil { t.Fatal(err) } diff --git a/ipams/windowsipam/windowsipam.go b/ipams/windowsipam/windowsipam.go index a1723bd6d3..a92d5ccd77 100644 --- a/ipams/windowsipam/windowsipam.go +++ b/ipams/windowsipam/windowsipam.go @@ -69,17 +69,17 @@ func (a *allocator) RequestAddress(poolID string, prefAddress net.IP, opts map[s _, ipNet, err := net.ParseCIDR(poolID) if err != nil { - return nil, nil, nil, nil, err + return nil, nil, err } // TODO Windows: Remove this once the bug in docker daemon is fixed // that causes it to throw an exception on nil gateway if opts[ipamapi.RequestAddressType] == netlabel.Gateway { - return ipNet, nil, nil, nil, nil + return ipNet, nil, nil } else if prefAddress == nil { - return nil, nil, nil, nil, nil + return nil, nil, nil } - return &net.IPNet{IP: prefAddress, Mask: ipNet.Mask}, nil, nil, nil, nil + return &net.IPNet{IP: prefAddress, Mask: ipNet.Mask}, nil, nil } // ReleaseAddress releases the address - always succeeds diff --git a/ipams/windowsipam/windowsipam_test.go b/ipams/windowsipam/windowsipam_test.go index 20edb009cb..3fee5e690c 100644 --- a/ipams/windowsipam/windowsipam_test.go +++ b/ipams/windowsipam/windowsipam_test.go @@ -46,7 +46,7 @@ func TestWindowsIPAM(t *testing.T) { t.Fatal(err) } - ip, _, _, _, err := a.RequestAddress(requestPool.String(), nil, map[string]string{}) + ip, _, err := a.RequestAddress(requestPool.String(), nil, map[string]string{}) if err != nil { t.Fatal(err) } @@ -55,7 +55,7 @@ func TestWindowsIPAM(t *testing.T) { t.Fatalf("Unexpected data returned. Expected %v . Got: %v ", requestPool, ip) } - ip, _, _, _, err = a.RequestAddress(requestPool.String(), requestAddress, map[string]string{}) + ip, _, err = a.RequestAddress(requestPool.String(), requestAddress, map[string]string{}) if err != nil { t.Fatal(err) } diff --git a/network.go b/network.go index 4d1a9fc23f..25dc39c3f5 100644 --- a/network.go +++ b/network.go @@ -1055,7 +1055,7 @@ func (n *network) ipamAllocateVersion(ipVer int, ipam ipamapi.Ipam) error { var gatewayOpts = map[string]string{ ipamapi.RequestAddressType: netlabel.Gateway, } - if d.Gateway, _, _, _, err = ipam.RequestAddress(d.PoolID, net.ParseIP(cfg.Gateway), gatewayOpts); err != nil { + 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) } } @@ -1073,7 +1073,7 @@ func (n *network) ipamAllocateVersion(ipVer int, ipam ipamapi.Ipam) error { return types.ForbiddenErrorf("auxilairy address: (%s:%s) must belong to the master pool: %s", k, v, d.Pool) } // Attempt reservation in the container addressable pool, silent the error if address does not belong to that pool - if d.IPAMData.AuxAddresses[k], _, _, _, err = ipam.RequestAddress(d.PoolID, ip, nil); err != nil && err != ipamapi.ErrIPOutOfRange { + if d.IPAMData.AuxAddresses[k], _, err = ipam.RequestAddress(d.PoolID, ip, nil); err != nil && err != ipamapi.ErrIPOutOfRange { return types.InternalErrorf("failed to allocate secondary ip address (%s:%s): %v", k, v, err) } }