From d7ba3928f44713a95ea153477e63ca317e8b0f69 Mon Sep 17 00:00:00 2001 From: xuzhonghu Date: Wed, 10 Jul 2019 18:33:48 +0800 Subject: [PATCH] remove hardcoded plugin name --- .../plugins/conformance/conformance.go | 5 +- pkg/scheduler/plugins/drf/drf.go | 5 +- pkg/scheduler/plugins/factory.go | 14 ++--- pkg/scheduler/plugins/gang/gang.go | 5 +- pkg/scheduler/plugins/nodeorder/nodeorder.go | 56 +++++++++---------- .../plugins/predicates/predicates.go | 5 +- pkg/scheduler/plugins/priority/priority.go | 5 +- .../plugins/proportion/proportion.go | 5 +- 8 files changed, 56 insertions(+), 44 deletions(-) diff --git a/pkg/scheduler/plugins/conformance/conformance.go b/pkg/scheduler/plugins/conformance/conformance.go index 980870d7c6..ff76582f23 100644 --- a/pkg/scheduler/plugins/conformance/conformance.go +++ b/pkg/scheduler/plugins/conformance/conformance.go @@ -24,6 +24,9 @@ import ( "volcano.sh/volcano/pkg/scheduler/framework" ) +// PluginName indicates name of volcano scheduler plugin. +const PluginName = "conformance" + type conformancePlugin struct { // Arguments given for the plugin pluginArguments framework.Arguments @@ -35,7 +38,7 @@ func New(arguments framework.Arguments) framework.Plugin { } func (pp *conformancePlugin) Name() string { - return "conformance" + return PluginName } func (pp *conformancePlugin) OnSessionOpen(ssn *framework.Session) { diff --git a/pkg/scheduler/plugins/drf/drf.go b/pkg/scheduler/plugins/drf/drf.go index 7d81ca43f3..e89755f1d3 100644 --- a/pkg/scheduler/plugins/drf/drf.go +++ b/pkg/scheduler/plugins/drf/drf.go @@ -26,6 +26,9 @@ import ( "volcano.sh/volcano/pkg/scheduler/framework" ) +// PluginName indicates name of volcano scheduler plugin. +const PluginName = "drf" + var shareDelta = 0.000001 type drfAttr struct { @@ -54,7 +57,7 @@ func New(arguments framework.Arguments) framework.Plugin { } func (drf *drfPlugin) Name() string { - return "drf" + return PluginName } func (drf *drfPlugin) OnSessionOpen(ssn *framework.Session) { diff --git a/pkg/scheduler/plugins/factory.go b/pkg/scheduler/plugins/factory.go index e4b8419486..a061ac38d4 100644 --- a/pkg/scheduler/plugins/factory.go +++ b/pkg/scheduler/plugins/factory.go @@ -30,13 +30,13 @@ import ( func init() { // Plugins for Jobs - framework.RegisterPluginBuilder("drf", drf.New) - framework.RegisterPluginBuilder("gang", gang.New) - framework.RegisterPluginBuilder("predicates", predicates.New) - framework.RegisterPluginBuilder("priority", priority.New) - framework.RegisterPluginBuilder("nodeorder", nodeorder.New) - framework.RegisterPluginBuilder("conformance", conformance.New) + framework.RegisterPluginBuilder(drf.PluginName, drf.New) + framework.RegisterPluginBuilder(gang.PluginName, gang.New) + framework.RegisterPluginBuilder(predicates.PluginName, predicates.New) + framework.RegisterPluginBuilder(priority.PluginName, priority.New) + framework.RegisterPluginBuilder(nodeorder.PluginName, nodeorder.New) + framework.RegisterPluginBuilder(conformance.PluginName, conformance.New) // Plugins for Queues - framework.RegisterPluginBuilder("proportion", proportion.New) + framework.RegisterPluginBuilder(proportion.PluginName, proportion.New) } diff --git a/pkg/scheduler/plugins/gang/gang.go b/pkg/scheduler/plugins/gang/gang.go index bb390bc6b5..a29cc80723 100644 --- a/pkg/scheduler/plugins/gang/gang.go +++ b/pkg/scheduler/plugins/gang/gang.go @@ -30,6 +30,9 @@ import ( "volcano.sh/volcano/pkg/scheduler/metrics" ) +// PluginName indicates name of volcano scheduler plugin. +const PluginName = "gang" + type gangPlugin struct { // Arguments given for the plugin pluginArguments framework.Arguments @@ -41,7 +44,7 @@ func New(arguments framework.Arguments) framework.Plugin { } func (gp *gangPlugin) Name() string { - return "gang" + return PluginName } func (gp *gangPlugin) OnSessionOpen(ssn *framework.Session) { diff --git a/pkg/scheduler/plugins/nodeorder/nodeorder.go b/pkg/scheduler/plugins/nodeorder/nodeorder.go index 92423bda50..5cda0a8865 100644 --- a/pkg/scheduler/plugins/nodeorder/nodeorder.go +++ b/pkg/scheduler/plugins/nodeorder/nodeorder.go @@ -32,6 +32,9 @@ import ( ) const ( + // PluginName indicates name of volcano scheduler plugin. + PluginName = "nodeorder" + // NodeAffinityWeight is the key for providing Node Affinity Priority Weight in YAML NodeAffinityWeight = "nodeaffinity.weight" // PodAffinityWeight is the key for providing Pod Affinity Priority Weight in YAML @@ -47,43 +50,13 @@ type nodeOrderPlugin struct { pluginArguments framework.Arguments } -func getInterPodAffinityScore(name string, interPodAffinityScore schedulerapi.HostPriorityList) int { - for _, hostPriority := range interPodAffinityScore { - if hostPriority.Host == name { - return hostPriority.Score - } - } - return 0 -} - -type cachedNodeInfo struct { - session *framework.Session -} - -func (c *cachedNodeInfo) GetNodeInfo(name string) (*v1.Node, error) { - node, found := c.session.Nodes[name] - if !found { - for _, cacheNode := range c.session.Nodes { - pods := cacheNode.Pods() - for _, pod := range pods { - if pod.Spec.NodeName == "" { - return cacheNode.Node, nil - } - } - } - return nil, fmt.Errorf("failed to find node <%s>", name) - } - - return node.Node, nil -} - //New function returns prioritizePlugin object func New(aruguments framework.Arguments) framework.Plugin { return &nodeOrderPlugin{pluginArguments: aruguments} } func (pp *nodeOrderPlugin) Name() string { - return "nodeorder" + return PluginName } type priorityWeight struct { @@ -249,3 +222,24 @@ func (pp *nodeOrderPlugin) OnSessionOpen(ssn *framework.Session) { func (pp *nodeOrderPlugin) OnSessionClose(ssn *framework.Session) { } + +type cachedNodeInfo struct { + session *framework.Session +} + +func (c *cachedNodeInfo) GetNodeInfo(name string) (*v1.Node, error) { + node, found := c.session.Nodes[name] + if !found { + for _, cacheNode := range c.session.Nodes { + pods := cacheNode.Pods() + for _, pod := range pods { + if pod.Spec.NodeName == "" { + return cacheNode.Node, nil + } + } + } + return nil, fmt.Errorf("failed to find node <%s>", name) + } + + return node.Node, nil +} diff --git a/pkg/scheduler/plugins/predicates/predicates.go b/pkg/scheduler/plugins/predicates/predicates.go index 08f5ef1540..1a8503c9b6 100644 --- a/pkg/scheduler/plugins/predicates/predicates.go +++ b/pkg/scheduler/plugins/predicates/predicates.go @@ -32,6 +32,9 @@ import ( ) const ( + // PluginName indicates name of volcano scheduler plugin. + PluginName = "predicates" + // MemoryPressurePredicate is the key for enabling Memory Pressure Predicate in YAML MemoryPressurePredicate = "predicate.MemoryPressureEnable" // DiskPressurePredicate is the key for enabling Disk Pressure Predicate in YAML @@ -51,7 +54,7 @@ func New(arguments framework.Arguments) framework.Plugin { } func (pp *predicatesPlugin) Name() string { - return "predicates" + return PluginName } func formatReason(reasons []algorithm.PredicateFailureReason) string { diff --git a/pkg/scheduler/plugins/priority/priority.go b/pkg/scheduler/plugins/priority/priority.go index 5ecd6ed444..0562c0ae77 100644 --- a/pkg/scheduler/plugins/priority/priority.go +++ b/pkg/scheduler/plugins/priority/priority.go @@ -22,6 +22,9 @@ import ( "volcano.sh/volcano/pkg/scheduler/framework" ) +// PluginName indicates name of volcano scheduler plugin. +const PluginName = "priority" + type priorityPlugin struct { // Arguments given for the plugin pluginArguments framework.Arguments @@ -33,7 +36,7 @@ func New(arguments framework.Arguments) framework.Plugin { } func (pp *priorityPlugin) Name() string { - return "priority" + return PluginName } func (pp *priorityPlugin) OnSessionOpen(ssn *framework.Session) { diff --git a/pkg/scheduler/plugins/proportion/proportion.go b/pkg/scheduler/plugins/proportion/proportion.go index a66143eec8..d266450526 100644 --- a/pkg/scheduler/plugins/proportion/proportion.go +++ b/pkg/scheduler/plugins/proportion/proportion.go @@ -24,6 +24,9 @@ import ( "volcano.sh/volcano/pkg/scheduler/framework" ) +// PluginName indicates name of volcano scheduler plugin. +const PluginName = "proportion" + type proportionPlugin struct { totalResource *api.Resource queueOpts map[api.QueueID]*queueAttr @@ -52,7 +55,7 @@ func New(arguments framework.Arguments) framework.Plugin { } func (pp *proportionPlugin) Name() string { - return "proportion" + return PluginName } func (pp *proportionPlugin) OnSessionOpen(ssn *framework.Session) {