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
6fd0b181
Commit
6fd0b181
authored
Jan 07, 2015
by
Abhishek Gupta
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rebased onto the latest changes to the scheduler code
parent
9e75a05d
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
39 additions
and
54 deletions
+39
-54
listers.go
pkg/client/cache/listers.go
+28
-4
listers.go
pkg/scheduler/listers.go
+2
-2
predicates_test.go
pkg/scheduler/predicates_test.go
+1
-5
affinity.go
plugin/pkg/scheduler/algorithmprovider/affinity/affinity.go
+2
-3
factory.go
plugin/pkg/scheduler/factory/factory.go
+6
-40
No files found.
pkg/client/cache/listers.go
View file @
6fd0b181
...
...
@@ -75,17 +75,41 @@ func (s *StoreToNodeLister) GetNodeInfo(id string) (*api.Node, error) {
return
nil
,
fmt
.
Errorf
(
"minion '%v' is not in cache"
,
id
)
}
// StoreToServiceLister makes a Store
have
the List method of the client.ServiceInterface
// StoreToServiceLister makes a Store
that has
the List method of the client.ServiceInterface
// The Store must contain (only) Services.
type
StoreToServiceLister
struct
{
Store
}
func
(
s
*
StoreToServiceLister
)
List
()
(
s
vc
s
api
.
ServiceList
,
err
error
)
{
func
(
s
*
StoreToServiceLister
)
List
()
(
s
ervice
s
api
.
ServiceList
,
err
error
)
{
for
_
,
m
:=
range
s
.
Store
.
List
()
{
s
vcs
.
Items
=
append
(
svc
s
.
Items
,
*
(
m
.
(
*
api
.
Service
)))
s
ervices
.
Items
=
append
(
service
s
.
Items
,
*
(
m
.
(
*
api
.
Service
)))
}
return
svcs
,
nil
return
services
,
nil
}
// TODO: Move this back to scheduler as a helper function that takes a Store,
// rather than a method of StoreToServiceLister.
func
(
s
*
StoreToServiceLister
)
GetPodServices
(
pod
api
.
Pod
)
(
services
[]
api
.
Service
,
err
error
)
{
var
selector
labels
.
Selector
var
service
api
.
Service
for
_
,
m
:=
range
s
.
Store
.
List
()
{
service
=
*
m
.
(
*
api
.
Service
)
// consider only services that are in the same namespace as the pod
if
service
.
Namespace
!=
pod
.
Namespace
{
continue
}
selector
=
labels
.
Set
(
service
.
Spec
.
Selector
)
.
AsSelector
()
if
selector
.
Matches
(
labels
.
Set
(
pod
.
Labels
))
{
services
=
append
(
services
,
service
)
}
}
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
}
// TODO: add StoreToEndpointsLister for use in kube-proxy.
pkg/scheduler/listers.go
View file @
6fd0b181
...
...
@@ -58,7 +58,7 @@ func (f FakePodLister) List(s labels.Selector) (selected []api.Pod, err error) {
// ServiceLister interface represents anything that can produce a list of services; the list is consumed by a scheduler.
type
ServiceLister
interface
{
// Lists all the services
List
Services
()
(
api
.
ServiceList
,
error
)
List
()
(
api
.
ServiceList
,
error
)
// Gets the services for the given pod
GetPodServices
(
api
.
Pod
)
([]
api
.
Service
,
error
)
}
...
...
@@ -67,7 +67,7 @@ type ServiceLister interface {
type
FakeServiceLister
[]
api
.
Service
// FakeServiceLister returns api.ServiceList, the list of all services.
func
(
f
FakeServiceLister
)
List
Services
()
(
api
.
ServiceList
,
error
)
{
func
(
f
FakeServiceLister
)
List
()
(
api
.
ServiceList
,
error
)
{
return
api
.
ServiceList
{
Items
:
f
},
nil
}
...
...
pkg/scheduler/predicates_test.go
View file @
6fd0b181
...
...
@@ -32,9 +32,6 @@ func (n FakeNodeInfo) GetNodeInfo(nodeName string) (*api.Node, error) {
return
&
node
,
nil
}
<<<<<<<
HEAD
func
makeResources
(
milliCPU
int64
,
memory
int64
)
api
.
NodeResources
{
=======
type
FakeNodeListInfo
[]
api
.
Node
func
(
nodes
FakeNodeListInfo
)
GetNodeInfo
(
nodeName
string
)
(
*
api
.
Node
,
error
)
{
...
...
@@ -46,8 +43,7 @@ func (nodes FakeNodeListInfo) GetNodeInfo(nodeName string) (*api.Node, error) {
return
nil
,
fmt
.
Errorf
(
"Unable to find node: %s"
,
nodeName
)
}
func
makeResources
(
milliCPU
int
,
memory
int
)
api
.
NodeResources
{
>>>>>>>
e0101c2
...
Adding
service
affinity
predicate
func
makeResources
(
milliCPU
int64
,
memory
int64
)
api
.
NodeResources
{
return
api
.
NodeResources
{
Capacity
:
api
.
ResourceList
{
api
.
ResourceCPU
:
*
resource
.
NewMilliQuantity
(
milliCPU
,
resource
.
DecimalSI
),
...
...
plugin/pkg/scheduler/algorithmprovider/affinity/affinity.go
View file @
6fd0b181
...
...
@@ -38,7 +38,7 @@ func affinityPredicates() util.StringSet {
"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"
})),
// Fit is defined based on the presence
/absence
of the "region" label on a minion, regardless of value.
// Fit is defined based on the presence of the "region" label on a minion, regardless of value.
factory
.
RegisterFitPredicate
(
"NodeLabelPredicate"
,
algorithm
.
NewNodeLabelPredicate
(
factory
.
MinionLister
,
[]
string
{
"region"
},
true
)),
)
}
...
...
@@ -48,9 +48,8 @@ func affinityPriorities() util.StringSet {
"LeastRequestedPriority"
,
"ServiceSpreadingPriority"
,
// 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
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.
// Prioritize nodes based on the presence
of the "zone"
label on a minion, regardless of value.
factory
.
RegisterPriorityFunction
(
"NodeLabelPriority"
,
algorithm
.
NewNodeLabelPriority
(
"zone"
,
true
),
1
),
)
}
plugin/pkg/scheduler/factory/factory.go
View file @
6fd0b181
...
...
@@ -187,12 +187,12 @@ func (factory *ConfigFactory) pollMinions() (cache.Enumerator, error) {
return
&
nodeEnumerator
{
list
},
nil
}
// createServiceLW returns a
l
istWatch that gets all changes to services.
func
(
factory
*
ConfigFactory
)
createServiceLW
()
*
l
istWatch
{
return
&
l
istWatch
{
c
lient
:
factory
.
Client
,
f
ieldSelector
:
parseSelectorOrDie
(
""
),
r
esource
:
"services"
,
// createServiceLW returns a
cache.L
istWatch that gets all changes to services.
func
(
factory
*
ConfigFactory
)
createServiceLW
()
*
cache
.
L
istWatch
{
return
&
cache
.
L
istWatch
{
C
lient
:
factory
.
Client
,
F
ieldSelector
:
parseSelectorOrDie
(
""
),
R
esource
:
"services"
,
}
}
...
...
@@ -226,40 +226,6 @@ type nodeEnumerator struct {
*
api
.
NodeList
}
// storeToServiceLister turns a store into a service lister. The store must contain (only) services.
type
storeToServiceLister
struct
{
cache
.
Store
}
func
(
s
*
storeToServiceLister
)
ListServices
()
(
services
api
.
ServiceList
,
err
error
)
{
for
_
,
m
:=
range
s
.
List
()
{
services
.
Items
=
append
(
services
.
Items
,
*
(
m
.
(
*
api
.
Service
)))
}
return
services
,
nil
}
func
(
s
*
storeToServiceLister
)
GetPodServices
(
pod
api
.
Pod
)
(
services
[]
api
.
Service
,
err
error
)
{
var
selector
labels
.
Selector
var
service
api
.
Service
for
_
,
m
:=
range
s
.
List
()
{
service
=
*
m
.
(
*
api
.
Service
)
// consider only services that are in the same namespace as the pod
if
service
.
Namespace
!=
pod
.
Namespace
{
continue
}
selector
=
labels
.
Set
(
service
.
Spec
.
Selector
)
.
AsSelector
()
if
selector
.
Matches
(
labels
.
Set
(
pod
.
Labels
))
{
services
=
append
(
services
,
service
)
}
}
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.
func
(
ne
*
nodeEnumerator
)
Len
()
int
{
if
ne
.
NodeList
==
nil
{
...
...
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