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
9e75a05d
Commit
9e75a05d
authored
Jan 05, 2015
by
Abhishek Gupta
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implementing PR feedback
parent
3f722a3d
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
86 additions
and
98 deletions
+86
-98
listers.go
pkg/scheduler/listers.go
+10
-8
predicates.go
pkg/scheduler/predicates.go
+20
-7
predicates_test.go
pkg/scheduler/predicates_test.go
+2
-2
priorities.go
pkg/scheduler/priorities.go
+3
-4
spreading.go
pkg/scheduler/spreading.go
+23
-23
affinity.go
plugin/pkg/scheduler/algorithmprovider/affinity/affinity.go
+17
-7
labelchecker.go
.../scheduler/algorithmprovider/labelchecker/labelchecker.go
+0
-44
plugins.go
plugin/pkg/scheduler/algorithmprovider/plugins.go
+1
-0
plugins_test.go
plugin/pkg/scheduler/algorithmprovider/plugins_test.go
+2
-0
factory.go
plugin/pkg/scheduler/factory/factory.go
+8
-3
No files found.
pkg/scheduler/listers.go
View file @
9e75a05d
...
@@ -59,8 +59,8 @@ func (f FakePodLister) List(s labels.Selector) (selected []api.Pod, err error) {
...
@@ -59,8 +59,8 @@ func (f FakePodLister) List(s labels.Selector) (selected []api.Pod, err error) {
type
ServiceLister
interface
{
type
ServiceLister
interface
{
// Lists all the services
// Lists all the services
ListServices
()
(
api
.
ServiceList
,
error
)
ListServices
()
(
api
.
ServiceList
,
error
)
// Gets the service for the given pod
// Gets the service
s
for the given pod
GetPodService
(
api
.
Pod
)
(
api
.
Service
,
error
)
GetPodService
s
(
api
.
Pod
)
([]
api
.
Service
,
error
)
}
}
// FakeServiceLister implements ServiceLister on []api.Service for test purposes.
// FakeServiceLister implements ServiceLister on []api.Service for test purposes.
...
@@ -71,10 +71,8 @@ func (f FakeServiceLister) ListServices() (api.ServiceList, error) {
...
@@ -71,10 +71,8 @@ func (f FakeServiceLister) ListServices() (api.ServiceList, error) {
return
api
.
ServiceList
{
Items
:
f
},
nil
return
api
.
ServiceList
{
Items
:
f
},
nil
}
}
// GetPodService gets the service that has the selector that can match the labels on the given pod
// GetPodServices gets the services that have the selector that match the labels on the given pod
// We are assuming a single service per pod.
func
(
f
FakeServiceLister
)
GetPodServices
(
pod
api
.
Pod
)
(
services
[]
api
.
Service
,
err
error
)
{
// In case of multiple services per pod, the first service found is returned
func
(
f
FakeServiceLister
)
GetPodService
(
pod
api
.
Pod
)
(
service
api
.
Service
,
err
error
)
{
var
selector
labels
.
Selector
var
selector
labels
.
Selector
for
_
,
service
:=
range
f
{
for
_
,
service
:=
range
f
{
...
@@ -84,8 +82,12 @@ func (f FakeServiceLister) GetPodService(pod api.Pod) (service api.Service, err
...
@@ -84,8 +82,12 @@ func (f FakeServiceLister) GetPodService(pod api.Pod) (service api.Service, err
}
}
selector
=
labels
.
Set
(
service
.
Spec
.
Selector
)
.
AsSelector
()
selector
=
labels
.
Set
(
service
.
Spec
.
Selector
)
.
AsSelector
()
if
selector
.
Matches
(
labels
.
Set
(
pod
.
Labels
))
{
if
selector
.
Matches
(
labels
.
Set
(
pod
.
Labels
))
{
return
service
,
nil
services
=
append
(
services
,
service
)
}
}
}
}
return
service
,
fmt
.
Errorf
(
"Could not find service for pod %s in namespace %s with labels: %v"
,
pod
.
Name
,
pod
.
Namespace
,
pod
.
Labels
)
if
len
(
services
)
==
0
{
err
=
fmt
.
Errorf
(
"Could not find service for pod %s in namespace %s with labels: %v"
,
pod
.
Name
,
pod
.
Namespace
,
pod
.
Labels
)
}
return
}
}
pkg/scheduler/predicates.go
View file @
9e75a05d
...
@@ -182,7 +182,12 @@ func NewNodeLabelPredicate(info NodeInfo, labels []string, presence bool) FitPre
...
@@ -182,7 +182,12 @@ func NewNodeLabelPredicate(info NodeInfo, labels []string, presence bool) FitPre
return
labelChecker
.
CheckNodeLabelPresence
return
labelChecker
.
CheckNodeLabelPresence
}
}
// CheckNodeLabelPresence checks whether a particular label exists on a minion or not, regardless of its value
// CheckNodeLabelPresence checks whether all of the specified labels exists on a minion or not, regardless of their value
// If "presence" is false, then returns false if any of the requested labels matches any of the minion's labels,
// otherwise returns true.
// If "presence" is true, then returns false if any of the requested labels does not match any of the minion's labels,
// otherwise returns true.
//
// Consider the cases where the minions are placed in regions/zones/racks and these are identified by labels
// Consider the cases where the minions are placed in regions/zones/racks and these are identified by labels
// In some cases, it is required that only minions that are part of ANY of the defined regions/zones/racks be selected
// In some cases, it is required that only minions that are part of ANY of the defined regions/zones/racks be selected
//
//
...
@@ -195,8 +200,9 @@ func (n *NodeLabelChecker) CheckNodeLabelPresence(pod api.Pod, existingPods []ap
...
@@ -195,8 +200,9 @@ func (n *NodeLabelChecker) CheckNodeLabelPresence(pod api.Pod, existingPods []ap
if
err
!=
nil
{
if
err
!=
nil
{
return
false
,
err
return
false
,
err
}
}
minionLabels
:=
labels
.
Set
(
minion
.
Labels
)
for
_
,
label
:=
range
n
.
labels
{
for
_
,
label
:=
range
n
.
labels
{
exists
=
labels
.
Set
(
minion
.
Labels
)
.
Has
(
label
)
exists
=
minionLabels
.
Has
(
label
)
if
(
exists
&&
!
n
.
presence
)
||
(
!
exists
&&
n
.
presence
)
{
if
(
exists
&&
!
n
.
presence
)
||
(
!
exists
&&
n
.
presence
)
{
return
false
,
nil
return
false
,
nil
}
}
...
@@ -221,15 +227,20 @@ func NewServiceAffinityPredicate(podLister PodLister, serviceLister ServiceListe
...
@@ -221,15 +227,20 @@ func NewServiceAffinityPredicate(podLister PodLister, serviceLister ServiceListe
return
affinity
.
CheckServiceAffinity
return
affinity
.
CheckServiceAffinity
}
}
// CheckServiceAffinity ensures that only the minions that match the specified labels are considered for scheduling.
// The set of labels to be considered are provided to the struct (ServiceAffinity).
// The pod is checked for the labels and any missing labels are then checked in the minion
// that hosts the service pods (peers) for the given pod.
func
(
s
*
ServiceAffinity
)
CheckServiceAffinity
(
pod
api
.
Pod
,
existingPods
[]
api
.
Pod
,
node
string
)
(
bool
,
error
)
{
func
(
s
*
ServiceAffinity
)
CheckServiceAffinity
(
pod
api
.
Pod
,
existingPods
[]
api
.
Pod
,
node
string
)
(
bool
,
error
)
{
var
affinitySelector
labels
.
Selector
var
affinitySelector
labels
.
Selector
// check if the pod being scheduled has the affinity labels specified
// check if the pod being scheduled has the affinity labels specified
in its NodeSelector
affinityLabels
:=
map
[
string
]
string
{}
affinityLabels
:=
map
[
string
]
string
{}
nodeSelector
:=
labels
.
Set
(
pod
.
Spec
.
NodeSelector
)
labelsExist
:=
true
labelsExist
:=
true
for
_
,
l
:=
range
s
.
labels
{
for
_
,
l
:=
range
s
.
labels
{
if
labels
.
Set
(
pod
.
Labels
)
.
Has
(
l
)
{
if
nodeSelector
.
Has
(
l
)
{
affinityLabels
[
l
]
=
labels
.
Set
(
pod
.
Labels
)
.
Get
(
l
)
affinityLabels
[
l
]
=
nodeSelector
.
Get
(
l
)
}
else
{
}
else
{
// the current pod does not specify all the labels, look in the existing service pods
// the current pod does not specify all the labels, look in the existing service pods
labelsExist
=
false
labelsExist
=
false
...
@@ -238,9 +249,11 @@ func (s *ServiceAffinity) CheckServiceAffinity(pod api.Pod, existingPods []api.P
...
@@ -238,9 +249,11 @@ func (s *ServiceAffinity) CheckServiceAffinity(pod api.Pod, existingPods []api.P
// skip looking at other pods in the service if the current pod defines all the required affinity labels
// skip looking at other pods in the service if the current pod defines all the required affinity labels
if
!
labelsExist
{
if
!
labelsExist
{
service
,
err
:=
s
.
serviceLister
.
GetPodService
(
pod
)
service
s
,
err
:=
s
.
serviceLister
.
GetPodServices
(
pod
)
if
err
==
nil
{
if
err
==
nil
{
selector
:=
labels
.
SelectorFromSet
(
service
.
Spec
.
Selector
)
// just use the first service and get the other pods within the service
// TODO: a separate predicate can be created that tries to handle all services for the pod
selector
:=
labels
.
SelectorFromSet
(
services
[
0
]
.
Spec
.
Selector
)
servicePods
,
err
:=
s
.
podLister
.
ListPods
(
selector
)
servicePods
,
err
:=
s
.
podLister
.
ListPods
(
selector
)
if
err
!=
nil
{
if
err
!=
nil
{
return
false
,
err
return
false
,
err
...
...
pkg/scheduler/predicates_test.go
View file @
9e75a05d
...
@@ -502,14 +502,14 @@ func TestServiceAffinity(t *testing.T) {
...
@@ -502,14 +502,14 @@ func TestServiceAffinity(t *testing.T) {
test
:
"nothing scheduled"
,
test
:
"nothing scheduled"
,
},
},
{
{
pod
:
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Labels
:
map
[
string
]
string
{
"region"
:
"r1"
}}},
pod
:
api
.
Pod
{
Spec
:
api
.
PodSpec
{
NodeSelector
:
map
[
string
]
string
{
"region"
:
"r1"
}}},
node
:
"machine1"
,
node
:
"machine1"
,
fits
:
true
,
fits
:
true
,
labels
:
[]
string
{
"region"
},
labels
:
[]
string
{
"region"
},
test
:
"pod with region label match"
,
test
:
"pod with region label match"
,
},
},
{
{
pod
:
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Labels
:
map
[
string
]
string
{
"region"
:
"r2"
}}},
pod
:
api
.
Pod
{
Spec
:
api
.
PodSpec
{
NodeSelector
:
map
[
string
]
string
{
"region"
:
"r2"
}}},
node
:
"machine1"
,
node
:
"machine1"
,
fits
:
false
,
fits
:
false
,
labels
:
[]
string
{
"region"
},
labels
:
[]
string
{
"region"
},
...
...
pkg/scheduler/priorities.go
View file @
9e75a05d
...
@@ -103,9 +103,9 @@ func NewNodeLabelPriority(label string, presence bool) PriorityFunction {
...
@@ -103,9 +103,9 @@ func NewNodeLabelPriority(label string, presence bool) PriorityFunction {
return
labelPrioritizer
.
CalculateNodeLabelPriority
return
labelPrioritizer
.
CalculateNodeLabelPriority
}
}
// CalculateNodeLabelPriority checks whether a particular label exists on a minion or not, regardless of its value
// CalculateNodeLabelPriority checks whether a particular label exists on a minion or not, regardless of its value
.
//
Consider the cases where the minions are places in regions/zones/racks and these are identified by labels
//
If presence is true, prioritizes minions that have the specified label, regardless of value.
// I
n some cases, it is required that only minions that are part of ANY of the defined regions/zones/racks be selected
// I
f presence is false, prioritizes minions that do not have the specified label.
func
(
n
*
NodeLabelPrioritizer
)
CalculateNodeLabelPriority
(
pod
api
.
Pod
,
podLister
PodLister
,
minionLister
MinionLister
)
(
HostPriorityList
,
error
)
{
func
(
n
*
NodeLabelPrioritizer
)
CalculateNodeLabelPriority
(
pod
api
.
Pod
,
podLister
PodLister
,
minionLister
MinionLister
)
(
HostPriorityList
,
error
)
{
var
score
int
var
score
int
minions
,
err
:=
minionLister
.
List
()
minions
,
err
:=
minionLister
.
List
()
...
@@ -113,7 +113,6 @@ func (n *NodeLabelPrioritizer) CalculateNodeLabelPriority(pod api.Pod, podLister
...
@@ -113,7 +113,6 @@ func (n *NodeLabelPrioritizer) CalculateNodeLabelPriority(pod api.Pod, podLister
return
nil
,
err
return
nil
,
err
}
}
// find the zones that the minions belong to
labeledMinions
:=
map
[
string
]
bool
{}
labeledMinions
:=
map
[
string
]
bool
{}
for
_
,
minion
:=
range
minions
.
Items
{
for
_
,
minion
:=
range
minions
.
Items
{
exists
:=
labels
.
Set
(
minion
.
Labels
)
.
Has
(
n
.
label
)
exists
:=
labels
.
Set
(
minion
.
Labels
)
.
Has
(
n
.
label
)
...
...
pkg/scheduler/spreading.go
View file @
9e75a05d
...
@@ -41,9 +41,11 @@ func (s *ServiceSpread) CalculateSpreadPriority(pod api.Pod, podLister PodLister
...
@@ -41,9 +41,11 @@ func (s *ServiceSpread) CalculateSpreadPriority(pod api.Pod, podLister PodLister
var
pods
[]
api
.
Pod
var
pods
[]
api
.
Pod
var
err
error
var
err
error
service
,
err
:=
s
.
serviceLister
.
GetPodService
(
pod
)
service
s
,
err
:=
s
.
serviceLister
.
GetPodServices
(
pod
)
if
err
==
nil
{
if
err
==
nil
{
selector
:=
labels
.
SelectorFromSet
(
service
.
Spec
.
Selector
)
// just use the first service and get the other pods within the service
// TODO: a separate predicate can be created that tries to handle all services for the pod
selector
:=
labels
.
SelectorFromSet
(
services
[
0
]
.
Spec
.
Selector
)
pods
,
err
=
podLister
.
ListPods
(
selector
)
pods
,
err
=
podLister
.
ListPods
(
selector
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -94,13 +96,13 @@ func NewServiceAntiAffinityPriority(serviceLister ServiceLister, label string) P
...
@@ -94,13 +96,13 @@ func NewServiceAntiAffinityPriority(serviceLister ServiceLister, label string) P
}
}
func
(
s
*
ServiceAntiAffinity
)
CalculateAntiAffinityPriority
(
pod
api
.
Pod
,
podLister
PodLister
,
minionLister
MinionLister
)
(
HostPriorityList
,
error
)
{
func
(
s
*
ServiceAntiAffinity
)
CalculateAntiAffinityPriority
(
pod
api
.
Pod
,
podLister
PodLister
,
minionLister
MinionLister
)
(
HostPriorityList
,
error
)
{
var
service
api
.
Service
var
pods
[]
api
.
Pod
var
pods
[]
api
.
Pod
var
err
error
service
,
err
=
s
.
serviceLister
.
GetPodService
(
pod
)
service
s
,
err
:=
s
.
serviceLister
.
GetPodServices
(
pod
)
if
err
==
nil
{
if
err
==
nil
{
selector
:=
labels
.
SelectorFromSet
(
service
.
Spec
.
Selector
)
// just use the first service and get the other pods within the service
// TODO: a separate predicate can be created that tries to handle all services for the pod
selector
:=
labels
.
SelectorFromSet
(
services
[
0
]
.
Spec
.
Selector
)
pods
,
err
=
podLister
.
ListPods
(
selector
)
pods
,
err
=
podLister
.
ListPods
(
selector
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -112,43 +114,41 @@ func (s *ServiceAntiAffinity) CalculateAntiAffinityPriority(pod api.Pod, podList
...
@@ -112,43 +114,41 @@ func (s *ServiceAntiAffinity) CalculateAntiAffinityPriority(pod api.Pod, podList
return
nil
,
err
return
nil
,
err
}
}
//
find the zones that the minions belong to
//
separate out the minions that have the label from the ones that don't
o
pen
Minions
:=
[]
string
{}
o
ther
Minions
:=
[]
string
{}
zon
edMinions
:=
map
[
string
]
string
{}
label
edMinions
:=
map
[
string
]
string
{}
for
_
,
minion
:=
range
minions
.
Items
{
for
_
,
minion
:=
range
minions
.
Items
{
if
labels
.
Set
(
minion
.
Labels
)
.
Has
(
s
.
label
)
{
if
labels
.
Set
(
minion
.
Labels
)
.
Has
(
s
.
label
)
{
zone
:=
labels
.
Set
(
minion
.
Labels
)
.
Get
(
s
.
label
)
label
:=
labels
.
Set
(
minion
.
Labels
)
.
Get
(
s
.
label
)
zonedMinions
[
minion
.
Name
]
=
zone
labeledMinions
[
minion
.
Name
]
=
label
}
else
{
}
else
{
o
penMinions
=
append
(
open
Minions
,
minion
.
Name
)
o
therMinions
=
append
(
other
Minions
,
minion
.
Name
)
}
}
}
}
podCounts
:=
map
[
string
]
int
{}
podCounts
:=
map
[
string
]
int
{}
numServicePods
:=
len
(
pods
)
for
_
,
pod
:=
range
pods
{
if
numServicePods
>
0
{
zone
,
exists
:=
labeledMinions
[
pod
.
Status
.
Host
]
for
_
,
pod
:=
range
pods
{
if
!
exists
{
zone
,
exists
:=
zonedMinions
[
pod
.
Status
.
Host
]
continue
if
!
exists
{
continue
}
podCounts
[
zone
]
++
}
}
podCounts
[
zone
]
++
}
}
numServicePods
:=
len
(
pods
)
result
:=
[]
HostPriority
{}
result
:=
[]
HostPriority
{}
//score int - scale of 0-10
//score int - scale of 0-10
// 0 being the lowest priority and 10 being the highest
// 0 being the lowest priority and 10 being the highest
for
minion
:=
range
zon
edMinions
{
for
minion
:=
range
label
edMinions
{
// initializing to the default/max minion score of 10
// initializing to the default/max minion score of 10
fScore
:=
float32
(
10
)
fScore
:=
float32
(
10
)
if
numServicePods
>
0
{
if
numServicePods
>
0
{
fScore
=
10
*
(
float32
(
numServicePods
-
podCounts
[
zon
edMinions
[
minion
]])
/
float32
(
numServicePods
))
fScore
=
10
*
(
float32
(
numServicePods
-
podCounts
[
label
edMinions
[
minion
]])
/
float32
(
numServicePods
))
}
}
result
=
append
(
result
,
HostPriority
{
host
:
minion
,
score
:
int
(
fScore
)})
result
=
append
(
result
,
HostPriority
{
host
:
minion
,
score
:
int
(
fScore
)})
}
}
// add the open minions with a score of 0
// add the open minions with a score of 0
for
_
,
minion
:=
range
o
pen
Minions
{
for
_
,
minion
:=
range
o
ther
Minions
{
result
=
append
(
result
,
HostPriority
{
host
:
minion
,
score
:
0
})
result
=
append
(
result
,
HostPriority
{
host
:
minion
,
score
:
0
})
}
}
...
...
plugin/pkg/scheduler/algorithmprovider/affinity/affinity.go
View file @
9e75a05d
...
@@ -23,24 +23,34 @@ import (
...
@@ -23,24 +23,34 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/scheduler/factory"
"github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/scheduler/factory"
)
)
const
Provider
string
=
"AffinityProvider"
const
Affinity
Provider
string
=
"AffinityProvider"
func
init
()
{
func
init
()
{
factory
.
RegisterAlgorithmProvider
(
Provider
,
defaultPredicates
(),
default
Priorities
())
factory
.
RegisterAlgorithmProvider
(
AffinityProvider
,
affinityPredicates
(),
affinity
Priorities
())
}
}
func
default
Predicates
()
util
.
StringSet
{
func
affinity
Predicates
()
util
.
StringSet
{
return
util
.
NewStringSet
(
return
util
.
NewStringSet
(
// Fit is defined based on whether the minion has the specified label values as the pod being scheduled
"HostName"
,
// Alternately, if the pod does not specify any/all labels, the other pods in the service are looked at
"MatchNodeSelector"
,
"PodFitsPorts"
,
"PodFitsResources"
,
"NoDiskConflict"
,
// Ensures that all pods within the same service are hosted on minions within the same region as defined by the "region" label
factory
.
RegisterFitPredicate
(
"ServiceAffinity"
,
algorithm
.
NewServiceAffinityPredicate
(
factory
.
PodLister
,
factory
.
ServiceLister
,
factory
.
MinionLister
,
[]
string
{
"region"
})),
factory
.
RegisterFitPredicate
(
"ServiceAffinity"
,
algorithm
.
NewServiceAffinityPredicate
(
factory
.
PodLister
,
factory
.
ServiceLister
,
factory
.
MinionLister
,
[]
string
{
"region"
})),
// Fit is defined based on the presence/absence of the "region" label on a minion, regardless of value.
factory
.
RegisterFitPredicate
(
"NodeLabelPredicate"
,
algorithm
.
NewNodeLabelPredicate
(
factory
.
MinionLister
,
[]
string
{
"region"
},
true
)),
)
)
}
}
func
default
Priorities
()
util
.
StringSet
{
func
affinity
Priorities
()
util
.
StringSet
{
return
util
.
NewStringSet
(
return
util
.
NewStringSet
(
"LeastRequestedPriority"
,
"ServiceSpreadingPriority"
,
// spreads pods belonging to the same service across minions in different zones
// spreads pods belonging to the same service across minions in different zones
// region and zone can be nested infrastructure topology levels and defined by labels on minions
// region and zone can be nested infrastructure topology levels and defined by labels on minions
factory
.
RegisterPriorityFunction
(
"ZoneSpreadingPriority"
,
algorithm
.
NewServiceAntiAffinityPriority
(
factory
.
ServiceLister
,
"zone"
),
1
),
factory
.
RegisterPriorityFunction
(
"ZoneSpreadingPriority"
,
algorithm
.
NewServiceAntiAffinityPriority
(
factory
.
ServiceLister
,
"zone"
),
2
),
// Prioritize nodes based on the presence/absence of a label on a minion, regardless of value.
factory
.
RegisterPriorityFunction
(
"NodeLabelPriority"
,
algorithm
.
NewNodeLabelPriority
(
"zone"
,
true
),
1
),
)
)
}
}
plugin/pkg/scheduler/algorithmprovider/labelchecker/labelchecker.go
deleted
100644 → 0
View file @
3f722a3d
/*
Copyright 2014 Google Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// This is the default algorithm provider for the scheduler.
package
labelchecker
import
(
algorithm
"github.com/GoogleCloudPlatform/kubernetes/pkg/scheduler"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/scheduler/factory"
)
const
Provider
string
=
"LabelCheckerProvider"
func
init
()
{
factory
.
RegisterAlgorithmProvider
(
Provider
,
defaultPredicates
(),
defaultPriorities
())
}
func
defaultPredicates
()
util
.
StringSet
{
return
util
.
NewStringSet
(
// Fit is defined based on the presence/absence of a label on a minion, regardless of value.
factory
.
RegisterFitPredicate
(
"NodeLabelPredicate"
,
algorithm
.
NewNodeLabelPredicate
(
factory
.
MinionLister
,
[]
string
{
"region"
},
true
)),
)
}
func
defaultPriorities
()
util
.
StringSet
{
return
util
.
NewStringSet
(
// Prioritize nodes based on the presence/absence of a label on a minion, regardless of value.
factory
.
RegisterPriorityFunction
(
"NodeLabelPriority"
,
algorithm
.
NewNodeLabelPriority
(
""
,
true
),
1
),
)
}
plugin/pkg/scheduler/algorithmprovider/plugins.go
View file @
9e75a05d
...
@@ -18,5 +18,6 @@ limitations under the License.
...
@@ -18,5 +18,6 @@ limitations under the License.
package
algorithmprovider
package
algorithmprovider
import
(
import
(
_
"github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/scheduler/algorithmprovider/affinity"
_
"github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/scheduler/algorithmprovider/defaults"
_
"github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/scheduler/algorithmprovider/defaults"
)
)
plugin/pkg/scheduler/algorithmprovider/plugins_test.go
View file @
9e75a05d
...
@@ -19,12 +19,14 @@ package algorithmprovider
...
@@ -19,12 +19,14 @@ package algorithmprovider
import
(
import
(
"testing"
"testing"
"github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/scheduler/algorithmprovider/affinity"
"github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/scheduler/factory"
"github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/scheduler/factory"
)
)
var
(
var
(
algorithmProviderNames
=
[]
string
{
algorithmProviderNames
=
[]
string
{
factory
.
DefaultProvider
,
factory
.
DefaultProvider
,
affinity
.
AffinityProvider
,
}
}
)
)
...
...
plugin/pkg/scheduler/factory/factory.go
View file @
9e75a05d
...
@@ -238,8 +238,9 @@ func (s *storeToServiceLister) ListServices() (services api.ServiceList, err err
...
@@ -238,8 +238,9 @@ func (s *storeToServiceLister) ListServices() (services api.ServiceList, err err
return
services
,
nil
return
services
,
nil
}
}
func
(
s
*
storeToServiceLister
)
GetPodService
(
pod
api
.
Pod
)
(
service
api
.
Service
,
err
error
)
{
func
(
s
*
storeToServiceLister
)
GetPodService
s
(
pod
api
.
Pod
)
(
services
[]
api
.
Service
,
err
error
)
{
var
selector
labels
.
Selector
var
selector
labels
.
Selector
var
service
api
.
Service
for
_
,
m
:=
range
s
.
List
()
{
for
_
,
m
:=
range
s
.
List
()
{
service
=
*
m
.
(
*
api
.
Service
)
service
=
*
m
.
(
*
api
.
Service
)
...
@@ -249,10 +250,14 @@ func (s *storeToServiceLister) GetPodService(pod api.Pod) (service api.Service,
...
@@ -249,10 +250,14 @@ func (s *storeToServiceLister) GetPodService(pod api.Pod) (service api.Service,
}
}
selector
=
labels
.
Set
(
service
.
Spec
.
Selector
)
.
AsSelector
()
selector
=
labels
.
Set
(
service
.
Spec
.
Selector
)
.
AsSelector
()
if
selector
.
Matches
(
labels
.
Set
(
pod
.
Labels
))
{
if
selector
.
Matches
(
labels
.
Set
(
pod
.
Labels
))
{
return
service
,
nil
services
=
append
(
services
,
service
)
}
}
}
}
return
service
,
fmt
.
Errorf
(
"Could not find service for pod %s in namespace %s with labels: %v"
,
pod
.
Name
,
pod
.
Namespace
,
pod
.
Labels
)
if
len
(
services
)
==
0
{
err
=
fmt
.
Errorf
(
"Could not find service for pod %s in namespace %s with labels: %v"
,
pod
.
Name
,
pod
.
Namespace
,
pod
.
Labels
)
}
return
}
}
// Len returns the number of items in the node list.
// Len returns the number of items in the node list.
...
...
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