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
a0787358
Commit
a0787358
authored
Jul 30, 2017
by
Harry Zhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cover get equivalence cache in core
Fix testing method
parent
2bd0b3dd
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
32 additions
and
58 deletions
+32
-58
utils.go
plugin/pkg/scheduler/algorithm/predicates/utils.go
+25
-0
defaults.go
plugin/pkg/scheduler/algorithmprovider/defaults/defaults.go
+1
-27
equivalence_cache.go
plugin/pkg/scheduler/core/equivalence_cache.go
+4
-29
equivalence_cache_test.go
plugin/pkg/scheduler/core/equivalence_cache_test.go
+0
-0
generic_scheduler.go
plugin/pkg/scheduler/core/generic_scheduler.go
+2
-2
No files found.
plugin/pkg/scheduler/algorithm/predicates/utils.go
View file @
a0787358
...
...
@@ -18,6 +18,7 @@ package predicates
import
(
"k8s.io/api/core/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
)
...
...
@@ -64,3 +65,27 @@ func CreateSelectorFromLabels(aL map[string]string) labels.Selector {
}
return
labels
.
Set
(
aL
)
.
AsSelector
()
}
// GetEquivalencePod returns a EquivalencePod which contains a group of pod attributes which can be reused.
func
GetEquivalencePod
(
pod
*
v1
.
Pod
)
interface
{}
{
// For now we only consider pods:
// 1. OwnerReferences is Controller
// 2. with same OwnerReferences
// to be equivalent
if
len
(
pod
.
OwnerReferences
)
!=
0
{
for
_
,
ref
:=
range
pod
.
OwnerReferences
{
if
*
ref
.
Controller
{
// a pod can only belongs to one controller
return
&
EquivalencePod
{
ControllerRef
:
ref
,
}
}
}
}
return
nil
}
// EquivalencePod is a group of pod attributes which can be reused as equivalence to schedule other pods.
type
EquivalencePod
struct
{
ControllerRef
metav1
.
OwnerReference
}
plugin/pkg/scheduler/algorithmprovider/defaults/defaults.go
View file @
a0787358
...
...
@@ -20,8 +20,6 @@ import (
"os"
"strconv"
"k8s.io/api/core/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/kubernetes/pkg/cloudprovider/providers/aws"
"k8s.io/kubernetes/plugin/pkg/scheduler/algorithm"
...
...
@@ -89,7 +87,7 @@ func init() {
factory
.
RegisterFitPredicate
(
"MatchNodeSelector"
,
predicates
.
PodMatchNodeSelector
)
// Use equivalence class to speed up predicates & priorities
factory
.
RegisterGetEquivalencePodFunction
(
GetEquivalencePod
)
factory
.
RegisterGetEquivalencePodFunction
(
predicates
.
GetEquivalencePod
)
// ServiceSpreadingPriority is a priority config factory that spreads pods by minimizing
// the number of pods (belonging to the same service) on the same node.
...
...
@@ -252,27 +250,3 @@ func copyAndReplace(set sets.String, replaceWhat, replaceWith string) sets.Strin
}
return
result
}
// GetEquivalencePod returns a EquivalencePod which contains a group of pod attributes which can be reused.
func
GetEquivalencePod
(
pod
*
v1
.
Pod
)
interface
{}
{
// For now we only consider pods:
// 1. OwnerReferences is Controller
// 2. with same OwnerReferences
// to be equivalent
if
len
(
pod
.
OwnerReferences
)
!=
0
{
for
_
,
ref
:=
range
pod
.
OwnerReferences
{
if
*
ref
.
Controller
{
// a pod can only belongs to one controller
return
&
EquivalencePod
{
ControllerRef
:
ref
,
}
}
}
}
return
nil
}
// EquivalencePod is a group of pod attributes which can be reused as equivalence to schedule other pods.
type
EquivalencePod
struct
{
ControllerRef
metav1
.
OwnerReference
}
plugin/pkg/scheduler/core/equivalence_cache.go
View file @
a0787358
...
...
@@ -66,7 +66,7 @@ func NewEquivalenceCache(getEquivalencePodFunc algorithm.GetEquivalencePodFunc)
}
// UpdateCachedPredicateItem updates pod predicate for equivalence class
func
(
ec
*
EquivalenceCache
)
UpdateCachedPredicateItem
(
pod
*
v1
.
Pod
,
nodeName
,
predicateKey
string
,
fit
bool
,
reasons
[]
algorithm
.
PredicateFailureReason
,
equivalenceHash
uint64
)
{
func
(
ec
*
EquivalenceCache
)
UpdateCachedPredicateItem
(
pod
Name
,
nodeName
,
predicateKey
string
,
fit
bool
,
reasons
[]
algorithm
.
PredicateFailureReason
,
equivalenceHash
uint64
)
{
ec
.
Lock
()
defer
ec
.
Unlock
()
if
_
,
exist
:=
ec
.
algorithmCache
[
nodeName
];
!
exist
{
...
...
@@ -87,7 +87,7 @@ func (ec *EquivalenceCache) UpdateCachedPredicateItem(pod *v1.Pod, nodeName, pre
equivalenceHash
:
predicateItem
,
})
}
glog
.
V
(
5
)
.
Infof
(
"Updated cached predicate: %v for pod: %v on node: %s, with item %v"
,
predicateKey
,
pod
.
GetName
()
,
nodeName
,
predicateItem
)
glog
.
V
(
5
)
.
Infof
(
"Updated cached predicate: %v for pod: %v on node: %s, with item %v"
,
predicateKey
,
pod
Name
,
nodeName
,
predicateItem
)
}
// PredicateWithECache returns:
...
...
@@ -95,10 +95,10 @@ func (ec *EquivalenceCache) UpdateCachedPredicateItem(pod *v1.Pod, nodeName, pre
// 2. reasons if not fit
// 3. if this cache is invalid
// based on cached predicate results
func
(
ec
*
EquivalenceCache
)
PredicateWithECache
(
pod
*
v1
.
Pod
,
nodeName
,
predicateKey
string
,
equivalenceHash
uint64
)
(
bool
,
[]
algorithm
.
PredicateFailureReason
,
bool
)
{
func
(
ec
*
EquivalenceCache
)
PredicateWithECache
(
pod
Name
,
nodeName
,
predicateKey
string
,
equivalenceHash
uint64
)
(
bool
,
[]
algorithm
.
PredicateFailureReason
,
bool
)
{
ec
.
RLock
()
defer
ec
.
RUnlock
()
glog
.
V
(
5
)
.
Infof
(
"Begin to calculate predicate: %v for pod: %s on node: %s based on equivalence cache"
,
predicateKey
,
pod
.
GetName
()
,
nodeName
)
glog
.
V
(
5
)
.
Infof
(
"Begin to calculate predicate: %v for pod: %s on node: %s based on equivalence cache"
,
predicateKey
,
pod
Name
,
nodeName
)
if
algorithmCache
,
exist
:=
ec
.
algorithmCache
[
nodeName
];
exist
{
if
cachePredicate
,
exist
:=
algorithmCache
.
predicatesCache
.
Get
(
predicateKey
);
exist
{
predicateMap
:=
cachePredicate
.
(
PredicateMap
)
...
...
@@ -158,31 +158,6 @@ func (ec *EquivalenceCache) InvalidateAllCachedPredicateItemOfNode(nodeName stri
glog
.
V
(
5
)
.
Infof
(
"Done invalidating all cached predicates on node: %s"
,
nodeName
)
}
// InvalidateCachedPredicateItemForPod marks item of given predicateKeys, of given pod (i.e. equivalenceHash),
// on the given node as invalid
func
(
ec
*
EquivalenceCache
)
InvalidateCachedPredicateItemForPod
(
nodeName
string
,
predicateKeys
sets
.
String
,
pod
*
v1
.
Pod
)
{
if
len
(
predicateKeys
)
==
0
{
return
}
equivalenceHash
:=
ec
.
getHashEquivalencePod
(
pod
)
if
equivalenceHash
==
0
{
// no equivalence pod found, just return
return
}
ec
.
Lock
()
defer
ec
.
Unlock
()
if
algorithmCache
,
exist
:=
ec
.
algorithmCache
[
nodeName
];
exist
{
for
predicateKey
:=
range
predicateKeys
{
if
cachePredicate
,
exist
:=
algorithmCache
.
predicatesCache
.
Get
(
predicateKey
);
exist
{
// got the cached item of by predicateKey & pod
predicateMap
:=
cachePredicate
.
(
PredicateMap
)
delete
(
predicateMap
,
equivalenceHash
)
}
}
}
glog
.
V
(
5
)
.
Infof
(
"Done invalidating cached predicates %v on node %s, for pod %v"
,
predicateKeys
,
nodeName
,
pod
.
GetName
())
}
// InvalidateCachedPredicateItemForPodAdd is a wrapper of InvalidateCachedPredicateItem for pod add case
func
(
ec
*
EquivalenceCache
)
InvalidateCachedPredicateItemForPodAdd
(
pod
*
v1
.
Pod
,
nodeName
string
)
{
// MatchInterPodAffinity: we assume scheduler can make sure newly binded pod
...
...
plugin/pkg/scheduler/core/equivalence_cache_test.go
View file @
a0787358
This diff is collapsed.
Click to expand it.
plugin/pkg/scheduler/core/generic_scheduler.go
View file @
a0787358
...
...
@@ -251,7 +251,7 @@ func podFitsOnNode(pod *v1.Pod, meta interface{}, info *schedulercache.NodeInfo,
// If equivalenceCache is available
if
eCacheAvailable
{
// PredicateWithECache will returns it's cached predicate results
fit
,
reasons
,
invalid
=
ecache
.
PredicateWithECache
(
pod
,
info
.
Node
()
.
GetName
(),
predicateKey
,
equivalenceHash
)
fit
,
reasons
,
invalid
=
ecache
.
PredicateWithECache
(
pod
.
GetName
()
,
info
.
Node
()
.
GetName
(),
predicateKey
,
equivalenceHash
)
}
if
!
eCacheAvailable
||
invalid
{
...
...
@@ -264,7 +264,7 @@ func podFitsOnNode(pod *v1.Pod, meta interface{}, info *schedulercache.NodeInfo,
if
eCacheAvailable
{
// update equivalence cache with newly computed fit & reasons
// TODO(resouer) should we do this in another thread? any race?
ecache
.
UpdateCachedPredicateItem
(
pod
,
info
.
Node
()
.
GetName
(),
predicateKey
,
fit
,
reasons
,
equivalenceHash
)
ecache
.
UpdateCachedPredicateItem
(
pod
.
GetName
()
,
info
.
Node
()
.
GetName
(),
predicateKey
,
fit
,
reasons
,
equivalenceHash
)
}
}
...
...
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