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
aa65a797
Commit
aa65a797
authored
May 25, 2016
by
Wojciech Tyczynski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Spread creating routes over time and retry on failures
parent
98766f45
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
7 deletions
+32
-7
routecontroller.go
pkg/controller/route/routecontroller.go
+32
-7
No files found.
pkg/controller/route/routecontroller.go
View file @
aa65a797
...
@@ -30,6 +30,14 @@ import (
...
@@ -30,6 +30,14 @@ import (
"k8s.io/kubernetes/pkg/util/wait"
"k8s.io/kubernetes/pkg/util/wait"
)
)
const
(
// Maximal number of concurrent CreateRoute API calls.
// TODO: This should be per-provider.
maxConcurrentRouteCreations
int
=
200
// Maximum number of retries of route creations.
maxRetries
int
=
5
)
type
RouteController
struct
{
type
RouteController
struct
{
routes
cloudprovider
.
Routes
routes
cloudprovider
.
Routes
kubeClient
clientset
.
Interface
kubeClient
clientset
.
Interface
...
@@ -50,6 +58,11 @@ func New(routes cloudprovider.Routes, kubeClient clientset.Interface, clusterNam
...
@@ -50,6 +58,11 @@ func New(routes cloudprovider.Routes, kubeClient clientset.Interface, clusterNam
}
}
func
(
rc
*
RouteController
)
Run
(
syncPeriod
time
.
Duration
)
{
func
(
rc
*
RouteController
)
Run
(
syncPeriod
time
.
Duration
)
{
// TODO: If we do just the full Resync every 5 minutes (default value)
// that means that we may wait up to 5 minutes before even starting
// creating a route for it. This is bad.
// We should have a watch on node and if we observe a new node (with CIDR?)
// trigger reconciliation for that node.
go
wait
.
NonSlidingUntil
(
func
()
{
go
wait
.
NonSlidingUntil
(
func
()
{
if
err
:=
rc
.
reconcileNodeRoutes
();
err
!=
nil
{
if
err
:=
rc
.
reconcileNodeRoutes
();
err
!=
nil
{
glog
.
Errorf
(
"Couldn't reconcile node routes: %v"
,
err
)
glog
.
Errorf
(
"Couldn't reconcile node routes: %v"
,
err
)
...
@@ -79,7 +92,10 @@ func (rc *RouteController) reconcile(nodes []api.Node, routes []*cloudprovider.R
...
@@ -79,7 +92,10 @@ func (rc *RouteController) reconcile(nodes []api.Node, routes []*cloudprovider.R
for
_
,
route
:=
range
routes
{
for
_
,
route
:=
range
routes
{
routeMap
[
route
.
TargetInstance
]
=
route
routeMap
[
route
.
TargetInstance
]
=
route
}
}
wg
:=
sync
.
WaitGroup
{}
wg
:=
sync
.
WaitGroup
{}
rateLimiter
:=
make
(
chan
struct
{},
maxConcurrentRouteCreations
)
for
_
,
node
:=
range
nodes
{
for
_
,
node
:=
range
nodes
{
// Skip if the node hasn't been assigned a CIDR yet.
// Skip if the node hasn't been assigned a CIDR yet.
if
node
.
Spec
.
PodCIDR
==
""
{
if
node
.
Spec
.
PodCIDR
==
""
{
...
@@ -96,14 +112,23 @@ func (rc *RouteController) reconcile(nodes []api.Node, routes []*cloudprovider.R
...
@@ -96,14 +112,23 @@ func (rc *RouteController) reconcile(nodes []api.Node, routes []*cloudprovider.R
nameHint
:=
string
(
node
.
UID
)
nameHint
:=
string
(
node
.
UID
)
wg
.
Add
(
1
)
wg
.
Add
(
1
)
glog
.
Infof
(
"Creating route for node %s %s with hint %s"
,
node
.
Name
,
route
.
DestinationCIDR
,
nameHint
)
glog
.
Infof
(
"Creating route for node %s %s with hint %s"
,
node
.
Name
,
route
.
DestinationCIDR
,
nameHint
)
go
func
(
nodeName
string
,
nameHint
string
,
route
*
cloudprovider
.
Route
,
startTime
time
.
Time
)
{
go
func
(
nodeName
string
,
nameHint
string
,
route
*
cloudprovider
.
Route
)
{
if
err
:=
rc
.
routes
.
CreateRoute
(
rc
.
clusterName
,
nameHint
,
route
);
err
!=
nil
{
defer
wg
.
Done
()
glog
.
Errorf
(
"Could not create route %s %s for node %s after %v: %v"
,
nameHint
,
route
.
DestinationCIDR
,
nodeName
,
time
.
Now
()
.
Sub
(
startTime
),
err
)
for
i
:=
0
;
i
<
maxRetries
;
i
++
{
}
else
{
startTime
:=
time
.
Now
()
glog
.
Infof
(
"Created route for node %s %s with hint %s after %v"
,
nodeName
,
route
.
DestinationCIDR
,
nameHint
,
time
.
Now
()
.
Sub
(
startTime
))
// Ensure that we don't have more than maxConcurrentRouteCreations
// CreateRoute calls in flight.
rateLimiter
<-
struct
{}{}
err
:=
rc
.
routes
.
CreateRoute
(
rc
.
clusterName
,
nameHint
,
route
)
<-
rateLimiter
if
err
!=
nil
{
glog
.
Errorf
(
"Could not create route %s %s for node %s after %v: %v"
,
nameHint
,
route
.
DestinationCIDR
,
nodeName
,
time
.
Now
()
.
Sub
(
startTime
),
err
)
}
else
{
glog
.
Infof
(
"Created route for node %s %s with hint %s after %v"
,
nodeName
,
route
.
DestinationCIDR
,
nameHint
,
time
.
Now
()
.
Sub
(
startTime
))
return
}
}
}
wg
.
Done
()
}(
node
.
Name
,
nameHint
,
route
)
}(
node
.
Name
,
nameHint
,
route
,
time
.
Now
())
}
}
nodeCIDRs
[
node
.
Name
]
=
node
.
Spec
.
PodCIDR
nodeCIDRs
[
node
.
Name
]
=
node
.
Spec
.
PodCIDR
}
}
...
...
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