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
e6da5b96
Commit
e6da5b96
authored
May 20, 2015
by
CJ Cullen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make routecontroller_test less hacky.
Rename reconcilePodCIDRs to reconcileNodeCIDRs. Add comments and TODOs about using controller framework.
parent
0d12a159
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
36 additions
and
10 deletions
+36
-10
util.sh
cluster/gce/util.sh
+2
-0
cloud.go
pkg/cloudprovider/cloud.go
+10
-3
nodecontroller.go
pkg/cloudprovider/nodecontroller/nodecontroller.go
+6
-4
routecontroller.go
pkg/cloudprovider/routecontroller/routecontroller.go
+2
-0
routecontroller_test.go
pkg/cloudprovider/routecontroller/routecontroller_test.go
+16
-3
No files found.
cluster/gce/util.sh
View file @
e6da5b96
...
@@ -771,6 +771,8 @@ function kube-down {
...
@@ -771,6 +771,8 @@ function kube-down {
# Delete routes.
# Delete routes.
local
-a
routes
local
-a
routes
# Clean up all routes w/ names like "<cluster-name>-<node-GUID>"
# e.g. "kubernetes-12345678-90ab-cdef-1234-567890abcdef"
routes
=(
$(
gcloud compute routes list
--project
"
${
PROJECT
}
"
\
routes
=(
$(
gcloud compute routes list
--project
"
${
PROJECT
}
"
\
--regexp
"
${
INSTANCE_PREFIX
}
-.{8}-.{4}-.{4}-.{4}-.{12}"
|
awk
'NR >= 2 { print $1 }'
)
)
--regexp
"
${
INSTANCE_PREFIX
}
-.{8}-.{4}-.{4}-.{4}-.{12}"
|
awk
'NR >= 2 { print $1 }'
)
)
routes+
=(
"
${
MASTER_NAME
}
"
)
routes+
=(
"
${
MASTER_NAME
}
"
)
...
...
pkg/cloudprovider/cloud.go
View file @
e6da5b96
...
@@ -87,14 +87,21 @@ type Instances interface {
...
@@ -87,14 +87,21 @@ type Instances interface {
// Route is a representation of an advanced routing rule.
// Route is a representation of an advanced routing rule.
type
Route
struct
{
type
Route
struct
{
Name
string
// Name is the name of the routing rule in the cloud-provider.
TargetInstance
string
Name
string
// TargetInstance is the name of the instance as specified in routing rules
// for the cloud-provider (in gce: the Instance Name).
TargetInstance
string
// Destination CIDR is the CIDR format IP range that this routing rule
// applies to.
DestinationCIDR
string
DestinationCIDR
string
Description
string
// Description is a free-form string. It can be useful for tagging Routes.
Description
string
}
}
// Routes is an abstract, pluggable interface for advanced routing rules.
// Routes is an abstract, pluggable interface for advanced routing rules.
type
Routes
interface
{
type
Routes
interface
{
// List all routes that match the filter
ListRoutes
(
filter
string
)
([]
*
Route
,
error
)
ListRoutes
(
filter
string
)
([]
*
Route
,
error
)
// Create the described route
// Create the described route
CreateRoute
(
route
*
Route
)
error
CreateRoute
(
route
*
Route
)
error
...
...
pkg/cloudprovider/nodecontroller/nodecontroller.go
View file @
e6da5b96
...
@@ -148,10 +148,10 @@ func generateCIDRs(clusterCIDR *net.IPNet, num int) util.StringSet {
...
@@ -148,10 +148,10 @@ func generateCIDRs(clusterCIDR *net.IPNet, num int) util.StringSet {
return
res
return
res
}
}
// reconcile
Pod
CIDRs looks at each node and assigns it a valid CIDR
// reconcile
Node
CIDRs looks at each node and assigns it a valid CIDR
// if it doesn't currently have one.
// if it doesn't currently have one.
func
(
nc
*
NodeController
)
reconcile
Pod
CIDRs
(
nodes
*
api
.
NodeList
)
{
func
(
nc
*
NodeController
)
reconcile
Node
CIDRs
(
nodes
*
api
.
NodeList
)
{
glog
.
V
(
4
)
.
Infof
(
"Reconciling
pods
cidrs for %d nodes"
,
len
(
nodes
.
Items
))
glog
.
V
(
4
)
.
Infof
(
"Reconciling cidrs for %d nodes"
,
len
(
nodes
.
Items
))
// TODO(roberthbailey): This seems inefficient. Why re-calculate CIDRs
// TODO(roberthbailey): This seems inefficient. Why re-calculate CIDRs
// on each sync period?
// on each sync period?
availableCIDRs
:=
generateCIDRs
(
nc
.
clusterCIDR
,
len
(
nodes
.
Items
))
availableCIDRs
:=
generateCIDRs
(
nc
.
clusterCIDR
,
len
(
nodes
.
Items
))
...
@@ -341,7 +341,9 @@ func (nc *NodeController) monitorNodeStatus() error {
...
@@ -341,7 +341,9 @@ func (nc *NodeController) monitorNodeStatus() error {
return
err
return
err
}
}
if
nc
.
allocateNodeCIDRs
{
if
nc
.
allocateNodeCIDRs
{
nc
.
reconcilePodCIDRs
(
nodes
)
// TODO (cjcullen): Use pkg/controller/framework to watch nodes and
// reduce lists/decouple this from monitoring status.
nc
.
reconcileNodeCIDRs
(
nodes
)
}
}
for
i
:=
range
nodes
.
Items
{
for
i
:=
range
nodes
.
Items
{
var
gracePeriod
time
.
Duration
var
gracePeriod
time
.
Duration
...
...
pkg/cloudprovider/routecontroller/routecontroller.go
View file @
e6da5b96
...
@@ -62,6 +62,8 @@ func (rc *RouteController) reconcileNodeRoutes() error {
...
@@ -62,6 +62,8 @@ func (rc *RouteController) reconcileNodeRoutes() error {
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"error listing routes: %v"
,
err
)
return
fmt
.
Errorf
(
"error listing routes: %v"
,
err
)
}
}
// TODO (cjcullen): use pkg/controller/framework.NewInformer to watch this
// and reduce the number of lists needed.
nodeList
,
err
:=
rc
.
kubeClient
.
Nodes
()
.
List
(
labels
.
Everything
(),
fields
.
Everything
())
nodeList
,
err
:=
rc
.
kubeClient
.
Nodes
()
.
List
(
labels
.
Everything
(),
fields
.
Everything
())
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"error listing nodes: %v"
,
err
)
return
fmt
.
Errorf
(
"error listing nodes: %v"
,
err
)
...
...
pkg/cloudprovider/routecontroller/routecontroller_test.go
View file @
e6da5b96
...
@@ -168,9 +168,22 @@ func TestReconcile(t *testing.T) {
...
@@ -168,9 +168,22 @@ func TestReconcile(t *testing.T) {
if
err
:=
rc
.
reconcile
(
testCase
.
nodes
,
testCase
.
initialRoutes
);
err
!=
nil
{
if
err
:=
rc
.
reconcile
(
testCase
.
nodes
,
testCase
.
initialRoutes
);
err
!=
nil
{
t
.
Errorf
(
"%d. Error from rc.reconcile(): %v"
,
i
,
err
)
t
.
Errorf
(
"%d. Error from rc.reconcile(): %v"
,
i
,
err
)
}
}
time
.
Sleep
(
10
*
time
.
Millisecond
)
var
finalRoutes
[]
*
cloudprovider
.
Route
if
finalRoutes
,
err
:=
routes
.
ListRoutes
(
""
);
err
!=
nil
||
!
routeListEqual
(
finalRoutes
,
testCase
.
expectedRoutes
)
{
var
err
error
t
.
Errorf
(
"%d. rc.reconcile() = %v, routes:
\n
%v
\n
expected: nil, routes:
\n
%v
\n
"
,
i
,
err
,
flatten
(
finalRoutes
),
flatten
(
testCase
.
expectedRoutes
))
timeoutChan
:=
time
.
After
(
50
*
time
.
Millisecond
)
tick
:=
time
.
NewTicker
(
10
*
time
.
Millisecond
)
defer
tick
.
Stop
()
poll
:
for
{
select
{
case
<-
tick
.
C
:
if
finalRoutes
,
err
=
routes
.
ListRoutes
(
""
);
err
==
nil
&&
routeListEqual
(
finalRoutes
,
testCase
.
expectedRoutes
)
{
break
poll
}
case
<-
timeoutChan
:
t
.
Errorf
(
"%d. rc.reconcile() = %v, routes:
\n
%v
\n
expected: nil, routes:
\n
%v
\n
"
,
i
,
err
,
flatten
(
finalRoutes
),
flatten
(
testCase
.
expectedRoutes
))
break
poll
}
}
}
}
}
}
}
...
...
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