Merge pull request #44571 from rpothier/cidr_set_indices

Automatic merge from submit-queue

Fixes an issue in cide_set.go

Function getBeginingAndEndIndices may return
end index too big



**What this PR does / why we need it**:
Fixes getBeginingAndEndIndices() in cidr_set.go
End index is off by one when s.clusterMaskSize >= maskSize

**Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #44558


**Special notes for your reviewer**:

**Release note**:

```release-note
```
This commit is contained in:
Kubernetes Submit Queue 2017-04-19 02:36:52 -07:00 committed by GitHub
commit 9c17779924
2 changed files with 3 additions and 3 deletions

View File

@ -79,7 +79,7 @@ func (s *cidrSet) allocateNext() (*net.IPNet, error) {
} }
func (s *cidrSet) getBeginingAndEndIndices(cidr *net.IPNet) (begin, end int, err error) { func (s *cidrSet) getBeginingAndEndIndices(cidr *net.IPNet) (begin, end int, err error) {
begin, end = 0, s.maxCIDRs begin, end = 0, s.maxCIDRs-1
cidrMask := cidr.Mask cidrMask := cidr.Mask
maskSize, _ := cidrMask.Size() maskSize, _ := cidrMask.Size()

View File

@ -249,7 +249,7 @@ func TestOccupy(t *testing.T) {
subNetMaskSize: 16, subNetMaskSize: 16,
subNetCIDRStr: "127.0.0.0/8", subNetCIDRStr: "127.0.0.0/8",
expectedUsedBegin: 0, expectedUsedBegin: 0,
expectedUsedEnd: 256, expectedUsedEnd: 255,
expectErr: false, expectErr: false,
}, },
{ {
@ -257,7 +257,7 @@ func TestOccupy(t *testing.T) {
subNetMaskSize: 16, subNetMaskSize: 16,
subNetCIDRStr: "127.0.0.0/2", subNetCIDRStr: "127.0.0.0/2",
expectedUsedBegin: 0, expectedUsedBegin: 0,
expectedUsedEnd: 256, expectedUsedEnd: 255,
expectErr: false, expectErr: false,
}, },
{ {