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
ba08b05e
Commit
ba08b05e
authored
May 23, 2018
by
Jonathan Basseri
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename equiv. class invalidation functions.
Change the invalidation functions to have cleaner and more consistent names.
parent
5d13798e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
37 deletions
+36
-37
equivalence_cache.go
pkg/scheduler/core/equivalence_cache.go
+17
-18
equivalence_cache_test.go
pkg/scheduler/core/equivalence_cache_test.go
+4
-4
factory.go
pkg/scheduler/factory/factory.go
+14
-14
scheduler.go
pkg/scheduler/scheduler.go
+1
-1
No files found.
pkg/scheduler/core/equivalence_cache.go
View file @
ba08b05e
...
...
@@ -153,39 +153,37 @@ func (ec *EquivalenceCache) lookupResult(
return
value
,
ok
}
// Invalidate
CachedPredicateItem marks all items of given predicateKeys, of all pods, on the given node as invalid
func
(
ec
*
EquivalenceCache
)
Invalidate
CachedPredicateItem
(
nodeName
string
,
predicateKeys
sets
.
String
)
{
// Invalidate
Predicates clears all cached results for the given predicates.
func
(
ec
*
EquivalenceCache
)
Invalidate
Predicates
(
predicateKeys
sets
.
String
)
{
if
len
(
predicateKeys
)
==
0
{
return
}
ec
.
mu
.
Lock
()
defer
ec
.
mu
.
Unlock
()
for
predicateKey
:=
range
predicateKeys
{
delete
(
ec
.
cache
[
nodeName
],
predicateKey
)
// ec.cache uses nodeName as key, so we just iterate it and invalid given predicates
for
_
,
predicates
:=
range
ec
.
cache
{
for
predicateKey
:=
range
predicateKeys
{
delete
(
predicates
,
predicateKey
)
}
}
glog
.
V
(
5
)
.
Infof
(
"Done invalidating cached predicates: %v on
node: %s"
,
predicateKeys
,
nodeName
)
glog
.
V
(
5
)
.
Infof
(
"Done invalidating cached predicates: %v on
all node"
,
predicateKeys
)
}
// InvalidateCachedPredicateItemOfAllNodes marks all items of given
// predicateKeys, of all pods, on all node as invalid
func
(
ec
*
EquivalenceCache
)
InvalidateCachedPredicateItemOfAllNodes
(
predicateKeys
sets
.
String
)
{
// InvalidatePredicatesOnNode clears cached results for the given predicates on one node.
func
(
ec
*
EquivalenceCache
)
InvalidatePredicatesOnNode
(
nodeName
string
,
predicateKeys
sets
.
String
)
{
if
len
(
predicateKeys
)
==
0
{
return
}
ec
.
mu
.
Lock
()
defer
ec
.
mu
.
Unlock
()
// ec.cache uses nodeName as key, so we just iterate it and invalid given predicates
for
_
,
predicates
:=
range
ec
.
cache
{
for
predicateKey
:=
range
predicateKeys
{
delete
(
predicates
,
predicateKey
)
}
for
predicateKey
:=
range
predicateKeys
{
delete
(
ec
.
cache
[
nodeName
],
predicateKey
)
}
glog
.
V
(
5
)
.
Infof
(
"Done invalidating cached predicates: %v on
all node"
,
predicateKeys
)
glog
.
V
(
5
)
.
Infof
(
"Done invalidating cached predicates: %v on
node: %s"
,
predicateKeys
,
nodeName
)
}
// InvalidateAllCachedPredicateItemOfNode marks all cached items on given node
// as invalid
func
(
ec
*
EquivalenceCache
)
InvalidateAllCachedPredicateItemOfNode
(
nodeName
string
)
{
// InvalidateAllPredicatesOnNode clears all cached results for one node.
func
(
ec
*
EquivalenceCache
)
InvalidateAllPredicatesOnNode
(
nodeName
string
)
{
ec
.
mu
.
Lock
()
defer
ec
.
mu
.
Unlock
()
delete
(
ec
.
cache
,
nodeName
)
...
...
@@ -194,6 +192,7 @@ func (ec *EquivalenceCache) InvalidateAllCachedPredicateItemOfNode(nodeName stri
// InvalidateCachedPredicateItemForPodAdd is a wrapper of
// InvalidateCachedPredicateItem for pod add case
// TODO: This logic does not belong with the equivalence cache implementation.
func
(
ec
*
EquivalenceCache
)
InvalidateCachedPredicateItemForPodAdd
(
pod
*
v1
.
Pod
,
nodeName
string
)
{
// MatchInterPodAffinity: we assume scheduler can make sure newly bound pod
// will not break the existing inter pod affinity. So we does not need to
...
...
@@ -227,7 +226,7 @@ func (ec *EquivalenceCache) InvalidateCachedPredicateItemForPodAdd(pod *v1.Pod,
}
}
}
ec
.
Invalidate
CachedPredicateItem
(
nodeName
,
invalidPredicates
)
ec
.
Invalidate
PredicatesOnNode
(
nodeName
,
invalidPredicates
)
}
// EquivalenceClassInfo holds equivalence hash which is used for checking
...
...
pkg/scheduler/core/equivalence_cache_test.go
View file @
ba08b05e
...
...
@@ -493,7 +493,7 @@ func TestLookupResult(t *testing.T) {
if
test
.
expectedPredicateKeyMiss
{
predicateKeys
:=
sets
.
NewString
()
predicateKeys
.
Insert
(
test
.
predicateKey
)
ecache
.
Invalidate
CachedPredicateItem
(
test
.
nodeName
,
predicateKeys
)
ecache
.
Invalidate
PredicatesOnNode
(
test
.
nodeName
,
predicateKeys
)
}
// calculate predicate with equivalence cache
result
,
ok
:=
ecache
.
lookupResult
(
test
.
podName
,
...
...
@@ -709,7 +709,7 @@ func TestInvalidateCachedPredicateItemOfAllNodes(t *testing.T) {
}
// invalidate cached predicate for all nodes
ecache
.
Invalidate
CachedPredicateItemOfAllNod
es
(
sets
.
NewString
(
testPredicate
))
ecache
.
Invalidate
Predicat
es
(
sets
.
NewString
(
testPredicate
))
// there should be no cached predicate any more
for
_
,
test
:=
range
tests
{
...
...
@@ -782,7 +782,7 @@ func TestInvalidateAllCachedPredicateItemOfNode(t *testing.T) {
for
_
,
test
:=
range
tests
{
// invalidate cached predicate for all nodes
ecache
.
InvalidateAll
CachedPredicateItemOf
Node
(
test
.
nodeName
)
ecache
.
InvalidateAll
PredicatesOn
Node
(
test
.
nodeName
)
if
_
,
exist
:=
ecache
.
cache
[
test
.
nodeName
];
exist
{
t
.
Errorf
(
"Failed: cached item for node: %v should be invalidated"
,
test
.
nodeName
)
break
...
...
@@ -857,7 +857,7 @@ func TestEquivalenceCacheInvalidationRace(t *testing.T) {
if
err
:=
cache
.
AddPod
(
pod
);
err
!=
nil
{
t
.
Errorf
(
"Could not add pod to cache: %v"
,
err
)
}
eCache
.
InvalidateAll
CachedPredicateItemOf
Node
(
"machine1"
)
eCache
.
InvalidateAll
PredicatesOn
Node
(
"machine1"
)
mockCache
.
cacheInvalidated
<-
struct
{}{}
}()
...
...
pkg/scheduler/factory/factory.go
View file @
ba08b05e
...
...
@@ -410,7 +410,7 @@ func (c *configFactory) invalidatePredicatesForPvUpdate(oldPV, newPV *v1.Persist
break
}
}
c
.
equivalencePodCache
.
Invalidate
CachedPredicateItemOfAllNod
es
(
invalidPredicates
)
c
.
equivalencePodCache
.
Invalidate
Predicat
es
(
invalidPredicates
)
}
// isZoneRegionLabel check if given key of label is zone or region label.
...
...
@@ -468,7 +468,7 @@ func (c *configFactory) invalidatePredicatesForPv(pv *v1.PersistentVolume) {
invalidPredicates
.
Insert
(
predicates
.
CheckVolumeBindingPred
)
}
c
.
equivalencePodCache
.
Invalidate
CachedPredicateItemOfAllNod
es
(
invalidPredicates
)
c
.
equivalencePodCache
.
Invalidate
Predicat
es
(
invalidPredicates
)
}
func
(
c
*
configFactory
)
onPvcAdd
(
obj
interface
{})
{
...
...
@@ -538,7 +538,7 @@ func (c *configFactory) invalidatePredicatesForPvc(pvc *v1.PersistentVolumeClaim
// Add/delete impacts the available PVs to choose from
invalidPredicates
.
Insert
(
predicates
.
CheckVolumeBindingPred
)
}
c
.
equivalencePodCache
.
Invalidate
CachedPredicateItemOfAllNod
es
(
invalidPredicates
)
c
.
equivalencePodCache
.
Invalidate
Predicat
es
(
invalidPredicates
)
}
func
(
c
*
configFactory
)
invalidatePredicatesForPvcUpdate
(
old
,
new
*
v1
.
PersistentVolumeClaim
)
{
...
...
@@ -553,12 +553,12 @@ func (c *configFactory) invalidatePredicatesForPvcUpdate(old, new *v1.Persistent
invalidPredicates
.
Insert
(
maxPDVolumeCountPredicateKeys
...
)
}
c
.
equivalencePodCache
.
Invalidate
CachedPredicateItemOfAllNod
es
(
invalidPredicates
)
c
.
equivalencePodCache
.
Invalidate
Predicat
es
(
invalidPredicates
)
}
func
(
c
*
configFactory
)
onServiceAdd
(
obj
interface
{})
{
if
c
.
enableEquivalenceClassCache
{
c
.
equivalencePodCache
.
Invalidate
CachedPredicateItemOfAllNod
es
(
serviceAffinitySet
)
c
.
equivalencePodCache
.
Invalidate
Predicat
es
(
serviceAffinitySet
)
}
c
.
podQueue
.
MoveAllToActiveQueue
()
}
...
...
@@ -569,7 +569,7 @@ func (c *configFactory) onServiceUpdate(oldObj interface{}, newObj interface{})
oldService
:=
oldObj
.
(
*
v1
.
Service
)
newService
:=
newObj
.
(
*
v1
.
Service
)
if
!
reflect
.
DeepEqual
(
oldService
.
Spec
.
Selector
,
newService
.
Spec
.
Selector
)
{
c
.
equivalencePodCache
.
Invalidate
CachedPredicateItemOfAllNod
es
(
serviceAffinitySet
)
c
.
equivalencePodCache
.
Invalidate
Predicat
es
(
serviceAffinitySet
)
}
}
c
.
podQueue
.
MoveAllToActiveQueue
()
...
...
@@ -577,7 +577,7 @@ func (c *configFactory) onServiceUpdate(oldObj interface{}, newObj interface{})
func
(
c
*
configFactory
)
onServiceDelete
(
obj
interface
{})
{
if
c
.
enableEquivalenceClassCache
{
c
.
equivalencePodCache
.
Invalidate
CachedPredicateItemOfAllNod
es
(
serviceAffinitySet
)
c
.
equivalencePodCache
.
Invalidate
Predicat
es
(
serviceAffinitySet
)
}
c
.
podQueue
.
MoveAllToActiveQueue
()
}
...
...
@@ -694,13 +694,13 @@ func (c *configFactory) invalidateCachedPredicatesOnUpdatePod(newPod *v1.Pod, ol
if
!
reflect
.
DeepEqual
(
oldPod
.
GetLabels
(),
newPod
.
GetLabels
())
{
// MatchInterPodAffinity need to be reconsidered for this node,
// as well as all nodes in its same failure domain.
c
.
equivalencePodCache
.
Invalidate
CachedPredicateItemOfAllNod
es
(
c
.
equivalencePodCache
.
Invalidate
Predicat
es
(
matchInterPodAffinitySet
)
}
// if requested container resource changed, invalidate GeneralPredicates of this node
if
!
reflect
.
DeepEqual
(
predicates
.
GetResourceRequest
(
newPod
),
predicates
.
GetResourceRequest
(
oldPod
))
{
c
.
equivalencePodCache
.
Invalidate
CachedPredicateItem
(
c
.
equivalencePodCache
.
Invalidate
PredicatesOnNode
(
newPod
.
Spec
.
NodeName
,
generalPredicatesSets
)
}
}
...
...
@@ -741,14 +741,14 @@ func (c *configFactory) invalidateCachedPredicatesOnDeletePod(pod *v1.Pod) {
// MatchInterPodAffinity need to be reconsidered for this node,
// as well as all nodes in its same failure domain.
// TODO(resouer) can we just do this for nodes in the same failure domain
c
.
equivalencePodCache
.
Invalidate
CachedPredicateItemOfAllNod
es
(
c
.
equivalencePodCache
.
Invalidate
Predicat
es
(
matchInterPodAffinitySet
)
// if this pod have these PV, cached result of disk conflict will become invalid.
for
_
,
volume
:=
range
pod
.
Spec
.
Volumes
{
if
volume
.
GCEPersistentDisk
!=
nil
||
volume
.
AWSElasticBlockStore
!=
nil
||
volume
.
RBD
!=
nil
||
volume
.
ISCSI
!=
nil
{
c
.
equivalencePodCache
.
Invalidate
CachedPredicateItem
(
c
.
equivalencePodCache
.
Invalidate
PredicatesOnNode
(
pod
.
Spec
.
NodeName
,
noDiskConflictSet
)
}
}
...
...
@@ -858,7 +858,7 @@ func (c *configFactory) invalidateCachedPredicatesOnNodeUpdate(newNode *v1.Node,
if
newNode
.
Spec
.
Unschedulable
!=
oldNode
.
Spec
.
Unschedulable
{
invalidPredicates
.
Insert
(
predicates
.
CheckNodeConditionPred
)
}
c
.
equivalencePodCache
.
Invalidate
CachedPredicateItem
(
newNode
.
GetName
(),
invalidPredicates
)
c
.
equivalencePodCache
.
Invalidate
PredicatesOnNode
(
newNode
.
GetName
(),
invalidPredicates
)
}
}
...
...
@@ -885,7 +885,7 @@ func (c *configFactory) deleteNodeFromCache(obj interface{}) {
glog
.
Errorf
(
"scheduler cache RemoveNode failed: %v"
,
err
)
}
if
c
.
enableEquivalenceClassCache
{
c
.
equivalencePodCache
.
InvalidateAll
CachedPredicateItemOf
Node
(
node
.
GetName
())
c
.
equivalencePodCache
.
InvalidateAll
PredicatesOn
Node
(
node
.
GetName
())
}
}
...
...
@@ -1315,7 +1315,7 @@ func (c *configFactory) MakeDefaultErrorFunc(backoff *util.PodBackoff, podQueue
c
.
schedulerCache
.
RemoveNode
(
&
node
)
// invalidate cached predicate for the node
if
c
.
enableEquivalenceClassCache
{
c
.
equivalencePodCache
.
InvalidateAll
CachedPredicateItemOf
Node
(
nodeName
)
c
.
equivalencePodCache
.
InvalidateAll
PredicatesOn
Node
(
nodeName
)
}
}
}
...
...
pkg/scheduler/scheduler.go
View file @
ba08b05e
...
...
@@ -284,7 +284,7 @@ func (sched *Scheduler) assumeAndBindVolumes(assumed *v1.Pod, host string) error
if
bindingRequired
{
if
sched
.
config
.
Ecache
!=
nil
{
invalidPredicates
:=
sets
.
NewString
(
predicates
.
CheckVolumeBindingPred
)
sched
.
config
.
Ecache
.
Invalidate
CachedPredicateItemOfAllNod
es
(
invalidPredicates
)
sched
.
config
.
Ecache
.
Invalidate
Predicat
es
(
invalidPredicates
)
}
// bindVolumesWorker() will update the Pod object to put it back in the scheduler queue
...
...
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