host-local: fix allocation of last address in a /30
This commit is contained in:
parent
56032390fe
commit
52e4358cbd
@ -173,7 +173,7 @@ func (a *IPAllocator) Get(id string) (*types.IPConfig, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
startIP, endIP := a.getSearchRange()
|
startIP, endIP := a.getSearchRange()
|
||||||
for cur := startIP; !cur.Equal(endIP); cur = a.nextIP(cur) {
|
for cur := startIP; ; cur = a.nextIP(cur) {
|
||||||
// don't allocate gateway IP
|
// don't allocate gateway IP
|
||||||
if gw != nil && cur.Equal(gw) {
|
if gw != nil && cur.Equal(gw) {
|
||||||
continue
|
continue
|
||||||
@ -190,6 +190,10 @@ func (a *IPAllocator) Get(id string) (*types.IPConfig, error) {
|
|||||||
Routes: a.conf.Routes,
|
Routes: a.conf.Routes,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
// break here to complete the loop
|
||||||
|
if cur.Equal(endIP) {
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("no IP addresses available in network: %s", a.conf.Name)
|
return nil, fmt.Errorf("no IP addresses available in network: %s", a.conf.Name)
|
||||||
}
|
}
|
||||||
|
@ -65,6 +65,12 @@ var _ = Describe("host-local ip allocator", func() {
|
|||||||
expectResult: "10.0.0.2",
|
expectResult: "10.0.0.2",
|
||||||
lastIP: "",
|
lastIP: "",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
subnet: "10.0.0.0/30",
|
||||||
|
ipmap: map[string]string{},
|
||||||
|
expectResult: "10.0.0.2",
|
||||||
|
lastIP: "",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
subnet: "10.0.0.0/29",
|
subnet: "10.0.0.0/29",
|
||||||
ipmap: map[string]string{
|
ipmap: map[string]string{
|
||||||
@ -107,6 +113,18 @@ var _ = Describe("host-local ip allocator", func() {
|
|||||||
expectResult: "10.0.0.3",
|
expectResult: "10.0.0.3",
|
||||||
lastIP: "10.0.0.128",
|
lastIP: "10.0.0.128",
|
||||||
},
|
},
|
||||||
|
// wrap around and reserve lastIP
|
||||||
|
{
|
||||||
|
subnet: "10.0.0.0/29",
|
||||||
|
ipmap: map[string]string{
|
||||||
|
"10.0.0.2": "id",
|
||||||
|
"10.0.0.4": "id",
|
||||||
|
"10.0.0.5": "id",
|
||||||
|
"10.0.0.6": "id",
|
||||||
|
},
|
||||||
|
expectResult: "10.0.0.3",
|
||||||
|
lastIP: "10.0.0.3",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user