Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
ef8936ce
Commit
ef8936ce
authored
May 14, 2017
by
Robert Pothier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updating NewCIDRSet return value
for IPv6, NewCIDRSet was updated to return an error if the subnet mask size is too big. In this case, NewCIDRSet will fail and return an error.
parent
fc8bfe2d
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
63 additions
and
24 deletions
+63
-24
cidr_set.go
pkg/controller/node/ipam/cidrset/cidr_set.go
+9
-6
cidr_set_test.go
pkg/controller/node/ipam/cidrset/cidr_set_test.go
+33
-12
controller.go
pkg/controller/node/ipam/controller.go
+6
-1
controller_test.go
pkg/controller/node/ipam/controller_test.go
+4
-1
range_allocator.go
pkg/controller/node/ipam/range_allocator.go
+5
-1
sync_test.go
pkg/controller/node/ipam/sync/sync_test.go
+6
-3
No files found.
pkg/controller/node/ipam/cidrset/cidr_set.go
View file @
ef8936ce
...
@@ -48,30 +48,33 @@ const (
...
@@ -48,30 +48,33 @@ const (
)
)
var
(
var
(
// ErrCIDRRangeNoCIDRsRemaining occurs when there
are
no more space
// ErrCIDRRangeNoCIDRsRemaining occurs when there
is
no more space
// to allocate CIDR ranges.
// to allocate CIDR ranges.
ErrCIDRRangeNoCIDRsRemaining
=
errors
.
New
(
ErrCIDRRangeNoCIDRsRemaining
=
errors
.
New
(
"CIDR allocation failed; there are no remaining CIDRs left to allocate in the accepted range"
)
"CIDR allocation failed; there are no remaining CIDRs left to allocate in the accepted range"
)
// ErrCIDRSetSubNetTooBig occurs when the subnet mask size is too
// big compared to the CIDR mask size.
ErrCIDRSetSubNetTooBig
=
errors
.
New
(
"New CIDR set failed; the node CIDR size is too big"
)
)
)
// NewCIDRSet creates a new CidrSet.
// NewCIDRSet creates a new CidrSet.
func
NewCIDRSet
(
clusterCIDR
*
net
.
IPNet
,
subNetMaskSize
int
)
*
CidrSet
{
func
NewCIDRSet
(
clusterCIDR
*
net
.
IPNet
,
subNetMaskSize
int
)
(
*
CidrSet
,
error
)
{
clusterMask
:=
clusterCIDR
.
Mask
clusterMask
:=
clusterCIDR
.
Mask
clusterMaskSize
,
_
:=
clusterMask
.
Size
()
clusterMaskSize
,
_
:=
clusterMask
.
Size
()
var
maxCIDRs
int
var
maxCIDRs
int
if
(
clusterCIDR
.
IP
.
To4
()
==
nil
)
&&
(
subNetMaskSize
-
clusterMaskSize
>
clusterSubnetMaxDiff
)
{
if
(
clusterCIDR
.
IP
.
To4
()
==
nil
)
&&
(
subNetMaskSize
-
clusterMaskSize
>
clusterSubnetMaxDiff
)
{
maxCIDRs
=
0
return
nil
,
ErrCIDRSetSubNetTooBig
}
else
{
maxCIDRs
=
1
<<
uint32
(
subNetMaskSize
-
clusterMaskSize
)
}
}
maxCIDRs
=
1
<<
uint32
(
subNetMaskSize
-
clusterMaskSize
)
return
&
CidrSet
{
return
&
CidrSet
{
clusterCIDR
:
clusterCIDR
,
clusterCIDR
:
clusterCIDR
,
clusterIP
:
clusterCIDR
.
IP
,
clusterIP
:
clusterCIDR
.
IP
,
clusterMaskSize
:
clusterMaskSize
,
clusterMaskSize
:
clusterMaskSize
,
maxCIDRs
:
maxCIDRs
,
maxCIDRs
:
maxCIDRs
,
subNetMaskSize
:
subNetMaskSize
,
subNetMaskSize
:
subNetMaskSize
,
}
}
,
nil
}
}
// TODO: Remove this function when upgrading to go 1.9
// TODO: Remove this function when upgrading to go 1.9
...
...
pkg/controller/node/ipam/cidrset/cidr_set_test.go
View file @
ef8936ce
...
@@ -47,8 +47,10 @@ func TestCIDRSetFullyAllocated(t *testing.T) {
...
@@ -47,8 +47,10 @@ func TestCIDRSetFullyAllocated(t *testing.T) {
}
}
for
_
,
tc
:=
range
cases
{
for
_
,
tc
:=
range
cases
{
_
,
clusterCIDR
,
_
:=
net
.
ParseCIDR
(
tc
.
clusterCIDRStr
)
_
,
clusterCIDR
,
_
:=
net
.
ParseCIDR
(
tc
.
clusterCIDRStr
)
a
:=
NewCIDRSet
(
clusterCIDR
,
tc
.
subNetMaskSize
)
a
,
err
:=
NewCIDRSet
(
clusterCIDR
,
tc
.
subNetMaskSize
)
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v for %v"
,
err
,
tc
.
description
)
}
p
,
err
:=
a
.
AllocateNext
()
p
,
err
:=
a
.
AllocateNext
()
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v for %v"
,
err
,
tc
.
description
)
t
.
Fatalf
(
"unexpected error: %v for %v"
,
err
,
tc
.
description
)
...
@@ -196,7 +198,10 @@ func TestIndexToCIDRBlock(t *testing.T) {
...
@@ -196,7 +198,10 @@ func TestIndexToCIDRBlock(t *testing.T) {
}
}
for
_
,
tc
:=
range
cases
{
for
_
,
tc
:=
range
cases
{
_
,
clusterCIDR
,
_
:=
net
.
ParseCIDR
(
tc
.
clusterCIDRStr
)
_
,
clusterCIDR
,
_
:=
net
.
ParseCIDR
(
tc
.
clusterCIDRStr
)
a
:=
NewCIDRSet
(
clusterCIDR
,
tc
.
subnetMaskSize
)
a
,
err
:=
NewCIDRSet
(
clusterCIDR
,
tc
.
subnetMaskSize
)
if
err
!=
nil
{
t
.
Fatalf
(
"error for %v "
,
tc
.
description
)
}
cidr
:=
a
.
indexToCIDRBlock
(
tc
.
index
)
cidr
:=
a
.
indexToCIDRBlock
(
tc
.
index
)
if
cidr
.
String
()
!=
tc
.
CIDRBlock
{
if
cidr
.
String
()
!=
tc
.
CIDRBlock
{
t
.
Fatalf
(
"error for %v index %d %s"
,
tc
.
description
,
tc
.
index
,
cidr
.
String
())
t
.
Fatalf
(
"error for %v index %d %s"
,
tc
.
description
,
tc
.
index
,
cidr
.
String
())
...
@@ -220,7 +225,10 @@ func TestCIDRSet_RandomishAllocation(t *testing.T) {
...
@@ -220,7 +225,10 @@ func TestCIDRSet_RandomishAllocation(t *testing.T) {
}
}
for
_
,
tc
:=
range
cases
{
for
_
,
tc
:=
range
cases
{
_
,
clusterCIDR
,
_
:=
net
.
ParseCIDR
(
tc
.
clusterCIDRStr
)
_
,
clusterCIDR
,
_
:=
net
.
ParseCIDR
(
tc
.
clusterCIDRStr
)
a
:=
NewCIDRSet
(
clusterCIDR
,
24
)
a
,
err
:=
NewCIDRSet
(
clusterCIDR
,
24
)
if
err
!=
nil
{
t
.
Fatalf
(
"Error allocating CIDRSet for %v"
,
tc
.
description
)
}
// allocate all the CIDRs
// allocate all the CIDRs
var
cidrs
[]
*
net
.
IPNet
var
cidrs
[]
*
net
.
IPNet
...
@@ -232,7 +240,7 @@ func TestCIDRSet_RandomishAllocation(t *testing.T) {
...
@@ -232,7 +240,7 @@ func TestCIDRSet_RandomishAllocation(t *testing.T) {
}
}
}
}
var
err
error
//
var err error
_
,
err
=
a
.
AllocateNext
()
_
,
err
=
a
.
AllocateNext
()
if
err
==
nil
{
if
err
==
nil
{
t
.
Fatalf
(
"expected error because of fully-allocated range for %v"
,
tc
.
description
)
t
.
Fatalf
(
"expected error because of fully-allocated range for %v"
,
tc
.
description
)
...
@@ -278,8 +286,10 @@ func TestCIDRSet_AllocationOccupied(t *testing.T) {
...
@@ -278,8 +286,10 @@ func TestCIDRSet_AllocationOccupied(t *testing.T) {
}
}
for
_
,
tc
:=
range
cases
{
for
_
,
tc
:=
range
cases
{
_
,
clusterCIDR
,
_
:=
net
.
ParseCIDR
(
tc
.
clusterCIDRStr
)
_
,
clusterCIDR
,
_
:=
net
.
ParseCIDR
(
tc
.
clusterCIDRStr
)
a
:=
NewCIDRSet
(
clusterCIDR
,
24
)
a
,
err
:=
NewCIDRSet
(
clusterCIDR
,
24
)
if
err
!=
nil
{
t
.
Fatalf
(
"Error allocating CIDRSet for %v"
,
tc
.
description
)
}
// allocate all the CIDRs
// allocate all the CIDRs
var
cidrs
[]
*
net
.
IPNet
var
cidrs
[]
*
net
.
IPNet
var
numCIDRs
=
256
var
numCIDRs
=
256
...
@@ -292,7 +302,7 @@ func TestCIDRSet_AllocationOccupied(t *testing.T) {
...
@@ -292,7 +302,7 @@ func TestCIDRSet_AllocationOccupied(t *testing.T) {
}
}
}
}
var
err
error
//
var err error
_
,
err
=
a
.
AllocateNext
()
_
,
err
=
a
.
AllocateNext
()
if
err
==
nil
{
if
err
==
nil
{
t
.
Fatalf
(
"expected error because of fully-allocated range for %v"
,
tc
.
description
)
t
.
Fatalf
(
"expected error because of fully-allocated range for %v"
,
tc
.
description
)
...
@@ -457,8 +467,10 @@ func TestGetBitforCIDR(t *testing.T) {
...
@@ -457,8 +467,10 @@ func TestGetBitforCIDR(t *testing.T) {
t
.
Fatalf
(
"unexpected error: %v for %v"
,
err
,
tc
.
description
)
t
.
Fatalf
(
"unexpected error: %v for %v"
,
err
,
tc
.
description
)
}
}
cs
:=
NewCIDRSet
(
clusterCIDR
,
tc
.
subNetMaskSize
)
cs
,
err
:=
NewCIDRSet
(
clusterCIDR
,
tc
.
subNetMaskSize
)
if
err
!=
nil
{
t
.
Fatalf
(
"Error allocating CIDRSet for %v"
,
tc
.
description
)
}
_
,
subnetCIDR
,
err
:=
net
.
ParseCIDR
(
tc
.
subNetCIDRStr
)
_
,
subnetCIDR
,
err
:=
net
.
ParseCIDR
(
tc
.
subNetCIDRStr
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v for %v"
,
err
,
tc
.
description
)
t
.
Fatalf
(
"unexpected error: %v for %v"
,
err
,
tc
.
description
)
...
@@ -625,7 +637,10 @@ func TestOccupy(t *testing.T) {
...
@@ -625,7 +637,10 @@ func TestOccupy(t *testing.T) {
t
.
Fatalf
(
"unexpected error: %v for %v"
,
err
,
tc
.
description
)
t
.
Fatalf
(
"unexpected error: %v for %v"
,
err
,
tc
.
description
)
}
}
cs
:=
NewCIDRSet
(
clusterCIDR
,
tc
.
subNetMaskSize
)
cs
,
err
:=
NewCIDRSet
(
clusterCIDR
,
tc
.
subNetMaskSize
)
if
err
!=
nil
{
t
.
Fatalf
(
"Error allocating CIDRSet for %v"
,
tc
.
description
)
}
_
,
subnetCIDR
,
err
:=
net
.
ParseCIDR
(
tc
.
subNetCIDRStr
)
_
,
subnetCIDR
,
err
:=
net
.
ParseCIDR
(
tc
.
subNetCIDRStr
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -686,7 +701,13 @@ func TestCIDRSetv6(t *testing.T) {
...
@@ -686,7 +701,13 @@ func TestCIDRSetv6(t *testing.T) {
}
}
for
_
,
tc
:=
range
cases
{
for
_
,
tc
:=
range
cases
{
_
,
clusterCIDR
,
_
:=
net
.
ParseCIDR
(
tc
.
clusterCIDRStr
)
_
,
clusterCIDR
,
_
:=
net
.
ParseCIDR
(
tc
.
clusterCIDRStr
)
a
:=
NewCIDRSet
(
clusterCIDR
,
tc
.
subNetMaskSize
)
a
,
err
:=
NewCIDRSet
(
clusterCIDR
,
tc
.
subNetMaskSize
)
if
err
!=
nil
{
if
tc
.
expectErr
{
continue
}
t
.
Fatalf
(
"Error allocating CIDRSet for %v"
,
tc
.
description
)
}
p
,
err
:=
a
.
AllocateNext
()
p
,
err
:=
a
.
AllocateNext
()
if
err
==
nil
&&
tc
.
expectErr
{
if
err
==
nil
&&
tc
.
expectErr
{
...
...
pkg/controller/node/ipam/controller.go
View file @
ef8936ce
...
@@ -76,11 +76,16 @@ func NewController(
...
@@ -76,11 +76,16 @@ func NewController(
return
nil
,
fmt
.
Errorf
(
"cloud IPAM controller does not support %q provider"
,
cloud
.
ProviderName
())
return
nil
,
fmt
.
Errorf
(
"cloud IPAM controller does not support %q provider"
,
cloud
.
ProviderName
())
}
}
set
,
err
:=
cidrset
.
NewCIDRSet
(
clusterCIDR
,
nodeCIDRMaskSize
)
if
err
!=
nil
{
return
nil
,
err
}
c
:=
&
Controller
{
c
:=
&
Controller
{
config
:
config
,
config
:
config
,
adapter
:
newAdapter
(
kubeClient
,
gceCloud
),
adapter
:
newAdapter
(
kubeClient
,
gceCloud
),
syncers
:
make
(
map
[
string
]
*
nodesync
.
NodeSync
),
syncers
:
make
(
map
[
string
]
*
nodesync
.
NodeSync
),
set
:
cidrset
.
NewCIDRSet
(
clusterCIDR
,
nodeCIDRMaskSize
)
,
set
:
set
,
}
}
if
err
:=
occupyServiceCIDR
(
c
.
set
,
clusterCIDR
,
serviceCIDR
);
err
!=
nil
{
if
err
:=
occupyServiceCIDR
(
c
.
set
,
clusterCIDR
,
serviceCIDR
);
err
!=
nil
{
...
...
pkg/controller/node/ipam/controller_test.go
View file @
ef8936ce
...
@@ -37,7 +37,10 @@ TestCase:
...
@@ -37,7 +37,10 @@ TestCase:
{
"10.2.0.0/24"
},
{
"10.2.0.0/24"
},
}
{
}
{
serviceCIDR
:=
test
.
MustParseCIDR
(
tc
.
serviceCIDR
)
serviceCIDR
:=
test
.
MustParseCIDR
(
tc
.
serviceCIDR
)
set
:=
cidrset
.
NewCIDRSet
(
test
.
MustParseCIDR
(
clusterCIDR
),
24
)
set
,
err
:=
cidrset
.
NewCIDRSet
(
test
.
MustParseCIDR
(
clusterCIDR
),
24
)
if
err
!=
nil
{
t
.
Errorf
(
"test case %+v: NewCIDRSet() = %v, want nil"
,
tc
,
err
)
}
if
err
:=
occupyServiceCIDR
(
set
,
test
.
MustParseCIDR
(
clusterCIDR
),
serviceCIDR
);
err
!=
nil
{
if
err
:=
occupyServiceCIDR
(
set
,
test
.
MustParseCIDR
(
clusterCIDR
),
serviceCIDR
);
err
!=
nil
{
t
.
Errorf
(
"test case %+v: occupyServiceCIDR() = %v, want nil"
,
tc
,
err
)
t
.
Errorf
(
"test case %+v: occupyServiceCIDR() = %v, want nil"
,
tc
,
err
)
}
}
...
...
pkg/controller/node/ipam/range_allocator.go
View file @
ef8936ce
...
@@ -70,9 +70,13 @@ func NewCIDRRangeAllocator(client clientset.Interface, clusterCIDR *net.IPNet, s
...
@@ -70,9 +70,13 @@ func NewCIDRRangeAllocator(client clientset.Interface, clusterCIDR *net.IPNet, s
glog
.
V
(
0
)
.
Infof
(
"Sending events to api server."
)
glog
.
V
(
0
)
.
Infof
(
"Sending events to api server."
)
eventBroadcaster
.
StartRecordingToSink
(
&
v1core
.
EventSinkImpl
{
Interface
:
v1core
.
New
(
client
.
CoreV1
()
.
RESTClient
())
.
Events
(
""
)})
eventBroadcaster
.
StartRecordingToSink
(
&
v1core
.
EventSinkImpl
{
Interface
:
v1core
.
New
(
client
.
CoreV1
()
.
RESTClient
())
.
Events
(
""
)})
set
,
err
:=
cidrset
.
NewCIDRSet
(
clusterCIDR
,
subNetMaskSize
)
if
err
!=
nil
{
return
nil
,
err
}
ra
:=
&
rangeAllocator
{
ra
:=
&
rangeAllocator
{
client
:
client
,
client
:
client
,
cidrs
:
cidrset
.
NewCIDRSet
(
clusterCIDR
,
subNetMaskSize
)
,
cidrs
:
set
,
clusterCIDR
:
clusterCIDR
,
clusterCIDR
:
clusterCIDR
,
nodeCIDRUpdateChannel
:
make
(
chan
nodeAndCIDR
,
cidrUpdateQueueSize
),
nodeCIDRUpdateChannel
:
make
(
chan
nodeAndCIDR
,
cidrUpdateQueueSize
),
recorder
:
recorder
,
recorder
:
recorder
,
...
...
pkg/controller/node/ipam/sync/sync_test.go
View file @
ef8936ce
...
@@ -194,7 +194,8 @@ func TestNodeSyncUpdate(t *testing.T) {
...
@@ -194,7 +194,8 @@ func TestNodeSyncUpdate(t *testing.T) {
wantError
:
false
,
wantError
:
false
,
},
},
}
{
}
{
sync
:=
New
(
&
tc
.
fake
,
&
tc
.
fake
,
&
tc
.
fake
,
tc
.
mode
,
"node1"
,
cidrset
.
NewCIDRSet
(
clusterCIDRRange
,
24
))
cidr
,
_
:=
cidrset
.
NewCIDRSet
(
clusterCIDRRange
,
24
)
sync
:=
New
(
&
tc
.
fake
,
&
tc
.
fake
,
&
tc
.
fake
,
tc
.
mode
,
"node1"
,
cidr
)
doneChan
:=
make
(
chan
struct
{})
doneChan
:=
make
(
chan
struct
{})
// Do a single step of the loop.
// Do a single step of the loop.
...
@@ -225,7 +226,8 @@ func TestNodeSyncResync(t *testing.T) {
...
@@ -225,7 +226,8 @@ func TestNodeSyncResync(t *testing.T) {
resyncTimeout
:
time
.
Millisecond
,
resyncTimeout
:
time
.
Millisecond
,
reportChan
:
make
(
chan
struct
{}),
reportChan
:
make
(
chan
struct
{}),
}
}
sync
:=
New
(
fake
,
fake
,
fake
,
SyncFromCluster
,
"node1"
,
cidrset
.
NewCIDRSet
(
clusterCIDRRange
,
24
))
cidr
,
_
:=
cidrset
.
NewCIDRSet
(
clusterCIDRRange
,
24
)
sync
:=
New
(
fake
,
fake
,
fake
,
SyncFromCluster
,
"node1"
,
cidr
)
doneChan
:=
make
(
chan
struct
{})
doneChan
:=
make
(
chan
struct
{})
go
sync
.
Loop
(
doneChan
)
go
sync
.
Loop
(
doneChan
)
...
@@ -267,7 +269,8 @@ func TestNodeSyncDelete(t *testing.T) {
...
@@ -267,7 +269,8 @@ func TestNodeSyncDelete(t *testing.T) {
},
},
},
},
}
{
}
{
sync
:=
New
(
&
tc
.
fake
,
&
tc
.
fake
,
&
tc
.
fake
,
tc
.
mode
,
"node1"
,
cidrset
.
NewCIDRSet
(
clusterCIDRRange
,
24
))
cidr
,
_
:=
cidrset
.
NewCIDRSet
(
clusterCIDRRange
,
24
)
sync
:=
New
(
&
tc
.
fake
,
&
tc
.
fake
,
&
tc
.
fake
,
tc
.
mode
,
"node1"
,
cidr
)
doneChan
:=
make
(
chan
struct
{})
doneChan
:=
make
(
chan
struct
{})
// Do a single step of the loop.
// Do a single step of the loop.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment