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
a04e600f
Commit
a04e600f
authored
Feb 27, 2015
by
Abhishek Gupta
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added test cases
parent
e5d319d6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
81 additions
and
1 deletion
+81
-1
generic_scheduler.go
pkg/scheduler/generic_scheduler.go
+7
-0
latest.go
plugin/pkg/scheduler/api/latest/latest.go
+1
-1
factory_test.go
plugin/pkg/scheduler/factory/factory_test.go
+73
-0
No files found.
pkg/scheduler/generic_scheduler.go
View file @
a04e600f
...
@@ -135,6 +135,13 @@ func findNodesThatFit(pod api.Pod, podLister PodLister, predicates map[string]Fi
...
@@ -135,6 +135,13 @@ func findNodesThatFit(pod api.Pod, podLister PodLister, predicates map[string]Fi
// All scores are finally combined (added) to get the total weighted scores of all minions
// All scores are finally combined (added) to get the total weighted scores of all minions
func
prioritizeNodes
(
pod
api
.
Pod
,
podLister
PodLister
,
priorityConfigs
[]
PriorityConfig
,
minionLister
MinionLister
)
(
HostPriorityList
,
error
)
{
func
prioritizeNodes
(
pod
api
.
Pod
,
podLister
PodLister
,
priorityConfigs
[]
PriorityConfig
,
minionLister
MinionLister
)
(
HostPriorityList
,
error
)
{
result
:=
HostPriorityList
{}
result
:=
HostPriorityList
{}
// If no priority configs are provided, then the EqualPriority function is applied
// This is required to generate the priority list in the required format
if
len
(
priorityConfigs
)
==
0
{
return
EqualPriority
(
pod
,
podLister
,
minionLister
)
}
combinedScores
:=
map
[
string
]
int
{}
combinedScores
:=
map
[
string
]
int
{}
for
_
,
priorityConfig
:=
range
priorityConfigs
{
for
_
,
priorityConfig
:=
range
priorityConfigs
{
weight
:=
priorityConfig
.
Weight
weight
:=
priorityConfig
.
Weight
...
...
plugin/pkg/scheduler/api/latest/latest.go
View file @
a04e600f
...
@@ -33,6 +33,6 @@ const OldestVersion = "v1"
...
@@ -33,6 +33,6 @@ const OldestVersion = "v1"
var
Versions
=
[]
string
{
"v1"
}
var
Versions
=
[]
string
{
"v1"
}
// Codec is the default codec for serializing input that should use
// Codec is the default codec for serializing input that should use
// the latest supported version.
Use this Codec when reading from the file.
// the latest supported version.
// This codec can decode any object that Kubernetes is aware of.
// This codec can decode any object that Kubernetes is aware of.
var
Codec
=
v1
.
Codec
var
Codec
=
v1
.
Codec
plugin/pkg/scheduler/factory/factory_test.go
View file @
a04e600f
...
@@ -30,7 +30,10 @@ import (
...
@@ -30,7 +30,10 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/cache"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/cache"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
algorithm
"github.com/GoogleCloudPlatform/kubernetes/pkg/scheduler"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
schedulerapi
"github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/scheduler/api"
latestschedulerapi
"github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/scheduler/api/latest"
)
)
func
TestCreate
(
t
*
testing
.
T
)
{
func
TestCreate
(
t
*
testing
.
T
)
{
...
@@ -46,6 +49,76 @@ func TestCreate(t *testing.T) {
...
@@ -46,6 +49,76 @@ func TestCreate(t *testing.T) {
factory
.
Create
()
factory
.
Create
()
}
}
func
TestCreateFromConfig
(
t
*
testing
.
T
)
{
var
configData
[]
byte
var
policy
schedulerapi
.
Policy
handler
:=
util
.
FakeHandler
{
StatusCode
:
500
,
ResponseBody
:
""
,
T
:
t
,
}
server
:=
httptest
.
NewServer
(
&
handler
)
defer
server
.
Close
()
client
:=
client
.
NewOrDie
(
&
client
.
Config
{
Host
:
server
.
URL
,
Version
:
testapi
.
Version
()})
factory
:=
NewConfigFactory
(
client
)
// Register the predicate and priority functions
// These would be registered by the DefaultProvider in regular operation
RegisterFitPredicate
(
"PodFitsPorts"
,
algorithm
.
PodFitsPorts
)
RegisterFitPredicate
(
"PodFitsResources"
,
algorithm
.
NewResourceFitPredicate
(
MinionLister
))
RegisterFitPredicate
(
"NoDiskConflict"
,
algorithm
.
NoDiskConflict
)
RegisterFitPredicate
(
"MatchNodeSelector"
,
algorithm
.
NewSelectorMatchPredicate
(
MinionLister
))
RegisterFitPredicate
(
"HostName"
,
algorithm
.
PodFitsHost
)
RegisterPriorityFunction
(
"LeastRequestedPriority"
,
algorithm
.
LeastRequestedPriority
,
1
)
RegisterPriorityFunction
(
"ServiceSpreadingPriority"
,
algorithm
.
NewServiceSpreadPriority
(
ServiceLister
),
1
)
RegisterPriorityFunction
(
"EqualPriority"
,
algorithm
.
EqualPriority
,
0
)
configData
=
[]
byte
(
`{
"kind" : "Policy",
"apiVersion" : "v1",
"predicates" : [
{"name" : "TestZoneAffinity", "argument" : {"serviceAffinity" : {"labels" : ["zone"]}}},
{"name" : "TestRequireZone", "argument" : {"labelsPresence" : {"labels" : ["zone"], "presence" : true}}},
{"name" : "PodFitsPorts"},
{"name" : "MatchNodeSelector"}
],
"priorities" : [
{"name" : "RackSpread", "weight" : 2, "argument" : {"serviceAntiAffinity" : {"label" : "rack"}}},
{"name" : "ServiceSpreadingPriority", "weight" : 1}
]
}`
)
err
:=
latestschedulerapi
.
Codec
.
DecodeInto
(
configData
,
&
policy
)
if
err
!=
nil
{
t
.
Errorf
(
"Invalid configuration: %v"
,
err
)
}
factory
.
CreateFromConfig
(
policy
)
}
func
TestCreateFromEmptyConfig
(
t
*
testing
.
T
)
{
var
configData
[]
byte
var
policy
schedulerapi
.
Policy
handler
:=
util
.
FakeHandler
{
StatusCode
:
500
,
ResponseBody
:
""
,
T
:
t
,
}
server
:=
httptest
.
NewServer
(
&
handler
)
defer
server
.
Close
()
client
:=
client
.
NewOrDie
(
&
client
.
Config
{
Host
:
server
.
URL
,
Version
:
testapi
.
Version
()})
factory
:=
NewConfigFactory
(
client
)
configData
=
[]
byte
(
`{}`
)
err
:=
latestschedulerapi
.
Codec
.
DecodeInto
(
configData
,
&
policy
)
if
err
!=
nil
{
t
.
Errorf
(
"Invalid configuration: %v"
,
err
)
}
factory
.
CreateFromConfig
(
policy
)
}
func
TestPollMinions
(
t
*
testing
.
T
)
{
func
TestPollMinions
(
t
*
testing
.
T
)
{
table
:=
[]
struct
{
table
:=
[]
struct
{
minions
[]
api
.
Node
minions
[]
api
.
Node
...
...
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