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
47f756bf
Commit
47f756bf
authored
Nov 22, 2017
by
Wojciech Tyczynski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix long even handler in cloud cidr allocator
parent
9f09c55e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
30 deletions
+29
-30
cloud_cidr_allocator.go
pkg/controller/node/ipam/cloud_cidr_allocator.go
+29
-30
No files found.
pkg/controller/node/ipam/cloud_cidr_allocator.go
View file @
47f756bf
...
@@ -49,10 +49,12 @@ type cloudCIDRAllocator struct {
...
@@ -49,10 +49,12 @@ type cloudCIDRAllocator struct {
client
clientset
.
Interface
client
clientset
.
Interface
cloud
*
gce
.
GCECloud
cloud
*
gce
.
GCECloud
// Channel that is used to pass updating Nodes with assigned CIDRs to the background
// Channel that is used to pass updating Nodes to the background.
// This increases a throughput of CIDR assignment by not blocking on long operations.
// This increases the throughput of CIDR assignment by parallelization
nodeCIDRUpdateChannel
chan
nodeAndCIDR
// and not blocking on long operations (which shouldn't be done from
recorder
record
.
EventRecorder
// event handlers anyway).
nodeUpdateChannel
chan
string
recorder
record
.
EventRecorder
// Keep a set of nodes that are currectly being processed to avoid races in CIDR allocation
// Keep a set of nodes that are currectly being processed to avoid races in CIDR allocation
lock
sync
.
Mutex
lock
sync
.
Mutex
...
@@ -80,11 +82,11 @@ func NewCloudCIDRAllocator(client clientset.Interface, cloud cloudprovider.Inter
...
@@ -80,11 +82,11 @@ func NewCloudCIDRAllocator(client clientset.Interface, cloud cloudprovider.Inter
}
}
ca
:=
&
cloudCIDRAllocator
{
ca
:=
&
cloudCIDRAllocator
{
client
:
client
,
client
:
client
,
cloud
:
gceCloud
,
cloud
:
gceCloud
,
node
CIDRUpdateChannel
:
make
(
chan
nodeAndCIDR
,
cidrUpdateQueueSize
),
node
UpdateChannel
:
make
(
chan
string
,
cidrUpdateQueueSize
),
recorder
:
recorder
,
recorder
:
recorder
,
nodesInProcessing
:
sets
.
NewString
(),
nodesInProcessing
:
sets
.
NewString
(),
}
}
for
i
:=
0
;
i
<
cidrUpdateWorkers
;
i
++
{
for
i
:=
0
;
i
<
cidrUpdateWorkers
;
i
++
{
...
@@ -99,7 +101,7 @@ func NewCloudCIDRAllocator(client clientset.Interface, cloud cloudprovider.Inter
...
@@ -99,7 +101,7 @@ func NewCloudCIDRAllocator(client clientset.Interface, cloud cloudprovider.Inter
func
(
ca
*
cloudCIDRAllocator
)
worker
(
stopChan
<-
chan
struct
{})
{
func
(
ca
*
cloudCIDRAllocator
)
worker
(
stopChan
<-
chan
struct
{})
{
for
{
for
{
select
{
select
{
case
workItem
,
ok
:=
<-
ca
.
node
CIDR
UpdateChannel
:
case
workItem
,
ok
:=
<-
ca
.
nodeUpdateChannel
:
if
!
ok
{
if
!
ok
{
glog
.
Warning
(
"Channel nodeCIDRUpdateChannel was unexpectedly closed"
)
glog
.
Warning
(
"Channel nodeCIDRUpdateChannel was unexpectedly closed"
)
return
return
...
@@ -138,14 +140,24 @@ func (ca *cloudCIDRAllocator) AllocateOrOccupyCIDR(node *v1.Node) error {
...
@@ -138,14 +140,24 @@ func (ca *cloudCIDRAllocator) AllocateOrOccupyCIDR(node *v1.Node) error {
glog
.
V
(
2
)
.
Infof
(
"Node %v is already in a process of CIDR assignment."
,
node
.
Name
)
glog
.
V
(
2
)
.
Infof
(
"Node %v is already in a process of CIDR assignment."
,
node
.
Name
)
return
nil
return
nil
}
}
cidrs
,
err
:=
ca
.
cloud
.
AliasRanges
(
types
.
NodeName
(
node
.
Name
))
glog
.
V
(
4
)
.
Infof
(
"Putting node %s into the work queue"
,
node
.
Name
)
ca
.
nodeUpdateChannel
<-
node
.
Name
return
nil
}
// updateCIDRAllocation assigns CIDR to Node and sends an update to the API server.
func
(
ca
*
cloudCIDRAllocator
)
updateCIDRAllocation
(
nodeName
string
)
error
{
var
err
error
var
node
*
v1
.
Node
defer
ca
.
removeNodeFromProcessing
(
nodeName
)
cidrs
,
err
:=
ca
.
cloud
.
AliasRanges
(
types
.
NodeName
(
nodeName
))
if
err
!=
nil
{
if
err
!=
nil
{
ca
.
removeNodeFromProcessing
(
node
.
Name
)
util
.
RecordNodeStatusChange
(
ca
.
recorder
,
node
,
"CIDRNotAvailable"
)
util
.
RecordNodeStatusChange
(
ca
.
recorder
,
node
,
"CIDRNotAvailable"
)
return
fmt
.
Errorf
(
"failed to allocate cidr: %v"
,
err
)
return
fmt
.
Errorf
(
"failed to allocate cidr: %v"
,
err
)
}
}
if
len
(
cidrs
)
==
0
{
if
len
(
cidrs
)
==
0
{
ca
.
removeNodeFromProcessing
(
node
.
Name
)
util
.
RecordNodeStatusChange
(
ca
.
recorder
,
node
,
"CIDRNotAvailable"
)
util
.
RecordNodeStatusChange
(
ca
.
recorder
,
node
,
"CIDRNotAvailable"
)
return
fmt
.
Errorf
(
"failed to allocate cidr: Node %v has no CIDRs"
,
node
.
Name
)
return
fmt
.
Errorf
(
"failed to allocate cidr: Node %v has no CIDRs"
,
node
.
Name
)
}
}
...
@@ -153,26 +165,13 @@ func (ca *cloudCIDRAllocator) AllocateOrOccupyCIDR(node *v1.Node) error {
...
@@ -153,26 +165,13 @@ func (ca *cloudCIDRAllocator) AllocateOrOccupyCIDR(node *v1.Node) error {
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to parse string '%s' as a CIDR: %v"
,
cidrs
[
0
],
err
)
return
fmt
.
Errorf
(
"failed to parse string '%s' as a CIDR: %v"
,
cidrs
[
0
],
err
)
}
}
podCIDR
:=
cidr
.
String
()
glog
.
V
(
4
)
.
Infof
(
"Putting node %s with CIDR %s into the work queue"
,
node
.
Name
,
cidrs
[
0
])
ca
.
nodeCIDRUpdateChannel
<-
nodeAndCIDR
{
nodeName
:
node
.
Name
,
cidr
:
cidr
,
}
return
nil
}
// updateCIDRAllocation assigns CIDR to Node and sends an update to the API server.
func
(
ca
*
cloudCIDRAllocator
)
updateCIDRAllocation
(
data
nodeAndCIDR
)
error
{
var
err
error
var
node
*
v1
.
Node
defer
ca
.
removeNodeFromProcessing
(
data
.
nodeName
)
podCIDR
:=
data
.
cidr
.
String
()
for
rep
:=
0
;
rep
<
cidrUpdateRetries
;
rep
++
{
for
rep
:=
0
;
rep
<
cidrUpdateRetries
;
rep
++
{
// TODO: change it to using PATCH instead of full Node updates.
// TODO: change it to using PATCH instead of full Node updates.
node
,
err
=
ca
.
client
.
CoreV1
()
.
Nodes
()
.
Get
(
data
.
nodeName
,
metav1
.
GetOptions
{})
node
,
err
=
ca
.
client
.
CoreV1
()
.
Nodes
()
.
Get
(
nodeName
,
metav1
.
GetOptions
{})
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Errorf
(
"Failed while getting node %v to retry updating Node.Spec.PodCIDR: %v"
,
data
.
nodeName
,
err
)
glog
.
Errorf
(
"Failed while getting node %v to retry updating Node.Spec.PodCIDR: %v"
,
nodeName
,
err
)
continue
continue
}
}
if
node
.
Spec
.
PodCIDR
!=
""
{
if
node
.
Spec
.
PodCIDR
!=
""
{
...
@@ -197,7 +196,7 @@ func (ca *cloudCIDRAllocator) updateCIDRAllocation(data nodeAndCIDR) error {
...
@@ -197,7 +196,7 @@ func (ca *cloudCIDRAllocator) updateCIDRAllocation(data nodeAndCIDR) error {
}
}
if
err
!=
nil
{
if
err
!=
nil
{
util
.
RecordNodeStatusChange
(
ca
.
recorder
,
node
,
"CIDRAssignmentFailed"
)
util
.
RecordNodeStatusChange
(
ca
.
recorder
,
node
,
"CIDRAssignmentFailed"
)
glog
.
Errorf
(
"CIDR assignment for node %v failed: %v."
,
data
.
nodeName
,
err
)
glog
.
Errorf
(
"CIDR assignment for node %v failed: %v."
,
nodeName
,
err
)
return
err
return
err
}
}
...
...
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