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
142fd773
Commit
142fd773
authored
Mar 27, 2015
by
Abhishek Gupta
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updating priority function weight based on specified configuration
parent
525bbfd1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
25 deletions
+41
-25
defaults.go
plugin/pkg/scheduler/algorithmprovider/defaults/defaults.go
+5
-5
plugins.go
plugin/pkg/scheduler/factory/plugins.go
+36
-20
No files found.
plugin/pkg/scheduler/algorithmprovider/defaults/defaults.go
View file @
142fd773
...
@@ -59,11 +59,11 @@ func defaultPriorities() util.StringSet {
...
@@ -59,11 +59,11 @@ func defaultPriorities() util.StringSet {
// spreads pods by minimizing the number of pods (belonging to the same service) on the same minion.
// spreads pods by minimizing the number of pods (belonging to the same service) on the same minion.
factory
.
RegisterPriorityConfigFactory
(
factory
.
RegisterPriorityConfigFactory
(
"ServiceSpreadingPriority"
,
"ServiceSpreadingPriority"
,
f
unc
(
args
factory
.
PluginFactoryArgs
)
algorithm
.
PriorityConfig
{
f
actory
.
PriorityConfigFactory
{
return
algorithm
.
PriorityConfig
{
Function
:
func
(
args
factory
.
PluginFactoryArgs
)
algorithm
.
PriorityFunction
{
Function
:
algorithm
.
NewServiceSpreadPriority
(
args
.
ServiceLister
),
return
algorithm
.
NewServiceSpreadPriority
(
args
.
ServiceLister
)
Weight
:
1
,
}
,
}
Weight
:
1
,
},
},
),
),
// EqualPriority is a prioritizer function that gives an equal weight of one to all minions
// EqualPriority is a prioritizer function that gives an equal weight of one to all minions
...
...
plugin/pkg/scheduler/factory/plugins.go
View file @
142fd773
...
@@ -40,7 +40,13 @@ type PluginFactoryArgs struct {
...
@@ -40,7 +40,13 @@ type PluginFactoryArgs struct {
type
FitPredicateFactory
func
(
PluginFactoryArgs
)
algorithm
.
FitPredicate
type
FitPredicateFactory
func
(
PluginFactoryArgs
)
algorithm
.
FitPredicate
// A PriorityFunctionFactory produces a PriorityConfig from the given args.
// A PriorityFunctionFactory produces a PriorityConfig from the given args.
type
PriorityConfigFactory
func
(
PluginFactoryArgs
)
algorithm
.
PriorityConfig
type
PriorityFunctionFactory
func
(
PluginFactoryArgs
)
algorithm
.
PriorityFunction
// A PriorityConfigFactory produces a PriorityConfig from the given function and weight
type
PriorityConfigFactory
struct
{
Function
PriorityFunctionFactory
Weight
int
}
var
(
var
(
schedulerFactoryMutex
sync
.
Mutex
schedulerFactoryMutex
sync
.
Mutex
...
@@ -127,8 +133,11 @@ func IsFitPredicateRegistered(name string) bool {
...
@@ -127,8 +133,11 @@ func IsFitPredicateRegistered(name string) bool {
// Registers a priority function with the algorithm registry. Returns the name,
// Registers a priority function with the algorithm registry. Returns the name,
// with which the function was registered.
// with which the function was registered.
func
RegisterPriorityFunction
(
name
string
,
function
algorithm
.
PriorityFunction
,
weight
int
)
string
{
func
RegisterPriorityFunction
(
name
string
,
function
algorithm
.
PriorityFunction
,
weight
int
)
string
{
return
RegisterPriorityConfigFactory
(
name
,
func
(
PluginFactoryArgs
)
algorithm
.
PriorityConfig
{
return
RegisterPriorityConfigFactory
(
name
,
PriorityConfigFactory
{
return
algorithm
.
PriorityConfig
{
Function
:
function
,
Weight
:
weight
}
Function
:
func
(
PluginFactoryArgs
)
algorithm
.
PriorityFunction
{
return
function
},
Weight
:
1
,
})
})
}
}
...
@@ -143,43 +152,47 @@ func RegisterPriorityConfigFactory(name string, pcf PriorityConfigFactory) strin
...
@@ -143,43 +152,47 @@ func RegisterPriorityConfigFactory(name string, pcf PriorityConfigFactory) strin
// Registers a custom priority function with the algorithm registry.
// Registers a custom priority function with the algorithm registry.
// Returns the name, with which the priority function was registered.
// Returns the name, with which the priority function was registered.
func
RegisterCustomPriorityFunction
(
policy
schedulerapi
.
PriorityPolicy
)
string
{
func
RegisterCustomPriorityFunction
(
policy
schedulerapi
.
PriorityPolicy
)
string
{
var
pcf
PriorityConfigFactory
var
pcf
*
PriorityConfigFactory
validatePriorityOrDie
(
policy
)
validatePriorityOrDie
(
policy
)
// generate the priority function, if a custom priority is requested
// generate the priority function, if a custom priority is requested
if
policy
.
Argument
!=
nil
{
if
policy
.
Argument
!=
nil
{
if
policy
.
Argument
.
ServiceAntiAffinity
!=
nil
{
if
policy
.
Argument
.
ServiceAntiAffinity
!=
nil
{
pcf
=
func
(
args
PluginFactoryArgs
)
algorithm
.
PriorityConfig
{
pcf
=
&
PriorityConfigFactory
{
return
algorithm
.
PriorityConfig
{
Function
:
func
(
args
PluginFactoryArgs
)
algorithm
.
PriorityFunction
{
Function
:
algorithm
.
NewServiceAntiAffinityPriority
(
return
algorithm
.
NewServiceAntiAffinityPriority
(
args
.
ServiceLister
,
args
.
ServiceLister
,
policy
.
Argument
.
ServiceAntiAffinity
.
Label
,
policy
.
Argument
.
ServiceAntiAffinity
.
Label
,
)
,
)
Weight
:
policy
.
Weight
,
}
,
}
Weight
:
policy
.
Weight
,
}
}
}
else
if
policy
.
Argument
.
LabelPreference
!=
nil
{
}
else
if
policy
.
Argument
.
LabelPreference
!=
nil
{
pcf
=
func
(
args
PluginFactoryArgs
)
algorithm
.
PriorityConfig
{
pcf
=
&
PriorityConfigFactory
{
return
algorithm
.
PriorityConfig
{
Function
:
func
(
args
PluginFactoryArgs
)
algorithm
.
PriorityFunction
{
Function
:
algorithm
.
NewNodeLabelPriority
(
return
algorithm
.
NewNodeLabelPriority
(
policy
.
Argument
.
LabelPreference
.
Label
,
policy
.
Argument
.
LabelPreference
.
Label
,
policy
.
Argument
.
LabelPreference
.
Presence
,
policy
.
Argument
.
LabelPreference
.
Presence
,
)
,
)
Weight
:
policy
.
Weight
,
}
,
}
Weight
:
policy
.
Weight
,
}
}
}
}
}
else
if
_
,
ok
:=
priorityFunctionMap
[
policy
.
Name
];
ok
{
}
else
if
existing_pcf
,
ok
:=
priorityFunctionMap
[
policy
.
Name
];
ok
{
glog
.
V
(
2
)
.
Infof
(
"Priority type %s already registered, reusing."
,
policy
.
Name
)
glog
.
V
(
2
)
.
Infof
(
"Priority type %s already registered, reusing."
,
policy
.
Name
)
return
policy
.
Name
// set/update the weight based on the policy
pcf
=
&
PriorityConfigFactory
{
Function
:
existing_pcf
.
Function
,
Weight
:
policy
.
Weight
,
}
}
}
if
pcf
==
nil
{
if
pcf
==
nil
{
glog
.
Fatalf
(
"Invalid configuration: Priority type not found for %s"
,
policy
.
Name
)
glog
.
Fatalf
(
"Invalid configuration: Priority type not found for %s"
,
policy
.
Name
)
}
}
return
RegisterPriorityConfigFactory
(
policy
.
Name
,
pcf
)
return
RegisterPriorityConfigFactory
(
policy
.
Name
,
*
pcf
)
}
}
// This check is useful for testing providers.
// This check is useful for testing providers.
...
@@ -242,7 +255,10 @@ func getPriorityFunctionConfigs(names util.StringSet, args PluginFactoryArgs) ([
...
@@ -242,7 +255,10 @@ func getPriorityFunctionConfigs(names util.StringSet, args PluginFactoryArgs) ([
if
!
ok
{
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"Invalid priority name %s specified - no corresponding function found"
,
name
)
return
nil
,
fmt
.
Errorf
(
"Invalid priority name %s specified - no corresponding function found"
,
name
)
}
}
configs
=
append
(
configs
,
factory
(
args
))
configs
=
append
(
configs
,
algorithm
.
PriorityConfig
{
Function
:
factory
.
Function
(
args
),
Weight
:
factory
.
Weight
,
})
}
}
return
configs
,
nil
return
configs
,
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