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
527d1c34
Unverified
Commit
527d1c34
authored
Nov 29, 2018
by
k8s-ci-robot
Committed by
GitHub
Nov 29, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #70947 from Adirio/nodetree-thread-safety
Scheduler internal NodeTree thread-safe NumNodes
parents
b4be9512
c7cba737
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
16 additions
and
9 deletions
+16
-9
generic_scheduler.go
pkg/scheduler/core/generic_scheduler.go
+1
-1
cache_test.go
pkg/scheduler/internal/cache/cache_test.go
+3
-3
node_tree.go
pkg/scheduler/internal/cache/node_tree.go
+10
-3
node_tree_test.go
pkg/scheduler/internal/cache/node_tree_test.go
+2
-2
No files found.
pkg/scheduler/core/generic_scheduler.go
View file @
527d1c34
...
@@ -390,7 +390,7 @@ func (g *genericScheduler) findNodesThatFit(pod *v1.Pod, nodes []*v1.Node) ([]*v
...
@@ -390,7 +390,7 @@ func (g *genericScheduler) findNodesThatFit(pod *v1.Pod, nodes []*v1.Node) ([]*v
if
len
(
g
.
predicates
)
==
0
{
if
len
(
g
.
predicates
)
==
0
{
filtered
=
nodes
filtered
=
nodes
}
else
{
}
else
{
allNodes
:=
int32
(
g
.
cache
.
NodeTree
()
.
NumNodes
)
allNodes
:=
int32
(
g
.
cache
.
NodeTree
()
.
NumNodes
()
)
numNodesToFind
:=
g
.
numFeasibleNodesToFind
(
allNodes
)
numNodesToFind
:=
g
.
numFeasibleNodesToFind
(
allNodes
)
// Create filtered list with enough space to avoid growing it
// Create filtered list with enough space to avoid growing it
...
...
pkg/scheduler/internal/cache/cache_test.go
View file @
527d1c34
...
@@ -1057,7 +1057,7 @@ func TestNodeOperators(t *testing.T) {
...
@@ -1057,7 +1057,7 @@ func TestNodeOperators(t *testing.T) {
if
!
found
{
if
!
found
{
t
.
Errorf
(
"Failed to find node %v in schedulerinternalcache."
,
node
.
Name
)
t
.
Errorf
(
"Failed to find node %v in schedulerinternalcache."
,
node
.
Name
)
}
}
if
cache
.
nodeTree
.
NumNodes
!=
1
||
cache
.
nodeTree
.
Next
()
!=
node
.
Name
{
if
cache
.
nodeTree
.
NumNodes
()
!=
1
||
cache
.
nodeTree
.
Next
()
!=
node
.
Name
{
t
.
Errorf
(
"cache.nodeTree is not updated correctly after adding node: %v"
,
node
.
Name
)
t
.
Errorf
(
"cache.nodeTree is not updated correctly after adding node: %v"
,
node
.
Name
)
}
}
...
@@ -1100,7 +1100,7 @@ func TestNodeOperators(t *testing.T) {
...
@@ -1100,7 +1100,7 @@ func TestNodeOperators(t *testing.T) {
t
.
Errorf
(
"Failed to update node in schedulercache:
\n
got: %+v
\n
expected: %+v"
,
got
,
expected
)
t
.
Errorf
(
"Failed to update node in schedulercache:
\n
got: %+v
\n
expected: %+v"
,
got
,
expected
)
}
}
// Check nodeTree after update
// Check nodeTree after update
if
cache
.
nodeTree
.
NumNodes
!=
1
||
cache
.
nodeTree
.
Next
()
!=
node
.
Name
{
if
cache
.
nodeTree
.
NumNodes
()
!=
1
||
cache
.
nodeTree
.
Next
()
!=
node
.
Name
{
t
.
Errorf
(
"unexpected cache.nodeTree after updating node: %v"
,
node
.
Name
)
t
.
Errorf
(
"unexpected cache.nodeTree after updating node: %v"
,
node
.
Name
)
}
}
...
@@ -1111,7 +1111,7 @@ func TestNodeOperators(t *testing.T) {
...
@@ -1111,7 +1111,7 @@ func TestNodeOperators(t *testing.T) {
}
}
// Check nodeTree after remove. The node should be removed from the nodeTree even if there are
// Check nodeTree after remove. The node should be removed from the nodeTree even if there are
// still pods on it.
// still pods on it.
if
cache
.
nodeTree
.
NumNodes
!=
0
||
cache
.
nodeTree
.
Next
()
!=
""
{
if
cache
.
nodeTree
.
NumNodes
()
!=
0
||
cache
.
nodeTree
.
Next
()
!=
""
{
t
.
Errorf
(
"unexpected cache.nodeTree after removing node: %v"
,
node
.
Name
)
t
.
Errorf
(
"unexpected cache.nodeTree after removing node: %v"
,
node
.
Name
)
}
}
}
}
...
...
pkg/scheduler/internal/cache/node_tree.go
View file @
527d1c34
...
@@ -32,7 +32,7 @@ type NodeTree struct {
...
@@ -32,7 +32,7 @@ type NodeTree struct {
tree
map
[
string
]
*
nodeArray
// a map from zone (region-zone) to an array of nodes in the zone.
tree
map
[
string
]
*
nodeArray
// a map from zone (region-zone) to an array of nodes in the zone.
zones
[]
string
// a list of all the zones in the tree (keys)
zones
[]
string
// a list of all the zones in the tree (keys)
zoneIndex
int
zoneIndex
int
N
umNodes
int
n
umNodes
int
mu
sync
.
RWMutex
mu
sync
.
RWMutex
}
}
...
@@ -91,7 +91,7 @@ func (nt *NodeTree) addNode(n *v1.Node) {
...
@@ -91,7 +91,7 @@ func (nt *NodeTree) addNode(n *v1.Node) {
nt
.
tree
[
zone
]
=
&
nodeArray
{
nodes
:
[]
string
{
n
.
Name
},
lastIndex
:
0
}
nt
.
tree
[
zone
]
=
&
nodeArray
{
nodes
:
[]
string
{
n
.
Name
},
lastIndex
:
0
}
}
}
klog
.
V
(
5
)
.
Infof
(
"Added node %v in group %v to NodeTree"
,
n
.
Name
,
zone
)
klog
.
V
(
5
)
.
Infof
(
"Added node %v in group %v to NodeTree"
,
n
.
Name
,
zone
)
nt
.
N
umNodes
++
nt
.
n
umNodes
++
}
}
// RemoveNode removes a node from the NodeTree.
// RemoveNode removes a node from the NodeTree.
...
@@ -111,7 +111,7 @@ func (nt *NodeTree) removeNode(n *v1.Node) error {
...
@@ -111,7 +111,7 @@ func (nt *NodeTree) removeNode(n *v1.Node) error {
nt
.
removeZone
(
zone
)
nt
.
removeZone
(
zone
)
}
}
klog
.
V
(
5
)
.
Infof
(
"Removed node %v in group %v from NodeTree"
,
n
.
Name
,
zone
)
klog
.
V
(
5
)
.
Infof
(
"Removed node %v in group %v from NodeTree"
,
n
.
Name
,
zone
)
nt
.
N
umNodes
--
nt
.
n
umNodes
--
return
nil
return
nil
}
}
}
}
...
@@ -184,3 +184,10 @@ func (nt *NodeTree) Next() string {
...
@@ -184,3 +184,10 @@ func (nt *NodeTree) Next() string {
}
}
}
}
}
}
// NumNodes returns the number of nodes.
func
(
nt
*
NodeTree
)
NumNodes
()
int
{
nt
.
mu
.
RLock
()
defer
nt
.
mu
.
RUnlock
()
return
nt
.
numNodes
}
pkg/scheduler/internal/cache/node_tree_test.go
View file @
527d1c34
...
@@ -116,8 +116,8 @@ func verifyNodeTree(t *testing.T, nt *NodeTree, expectedTree map[string]*nodeArr
...
@@ -116,8 +116,8 @@ func verifyNodeTree(t *testing.T, nt *NodeTree, expectedTree map[string]*nodeArr
for
_
,
na
:=
range
expectedTree
{
for
_
,
na
:=
range
expectedTree
{
expectedNumNodes
+=
len
(
na
.
nodes
)
expectedNumNodes
+=
len
(
na
.
nodes
)
}
}
if
n
t
.
N
umNodes
!=
expectedNumNodes
{
if
n
umNodes
:=
nt
.
NumNodes
();
n
umNodes
!=
expectedNumNodes
{
t
.
Errorf
(
"unexpected NodeTree.numNodes. Expected: %v, Got: %v"
,
expectedNumNodes
,
n
t
.
N
umNodes
)
t
.
Errorf
(
"unexpected NodeTree.numNodes. Expected: %v, Got: %v"
,
expectedNumNodes
,
numNodes
)
}
}
if
!
reflect
.
DeepEqual
(
nt
.
tree
,
expectedTree
)
{
if
!
reflect
.
DeepEqual
(
nt
.
tree
,
expectedTree
)
{
t
.
Errorf
(
"The node tree is not the same as expected. Expected: %v, Got: %v"
,
expectedTree
,
nt
.
tree
)
t
.
Errorf
(
"The node tree is not the same as expected. Expected: %v, Got: %v"
,
expectedTree
,
nt
.
tree
)
...
...
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