Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove hardcoded plugin name #321

Merged
merged 1 commit into from
Jul 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pkg/scheduler/plugins/conformance/conformance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down
5 changes: 4 additions & 1 deletion pkg/scheduler/plugins/drf/drf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down
14 changes: 7 additions & 7 deletions pkg/scheduler/plugins/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
5 changes: 4 additions & 1 deletion pkg/scheduler/plugins/gang/gang.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down
56 changes: 25 additions & 31 deletions pkg/scheduler/plugins/nodeorder/nodeorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}
5 changes: 4 additions & 1 deletion pkg/scheduler/plugins/predicates/predicates.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion pkg/scheduler/plugins/priority/priority.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down
5 changes: 4 additions & 1 deletion pkg/scheduler/plugins/proportion/proportion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down