Skip to content

Commit 6458b11

Browse files
Merge pull request #321 from hzxuzhonghu/plugin
remove hardcoded plugin name
2 parents 6e08482 + d7ba392 commit 6458b11

File tree

7 files changed

+52
-43
lines changed

7 files changed

+52
-43
lines changed

pkg/scheduler/plugins/conformance/conformance.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ import (
2424
"volcano.sh/volcano/pkg/scheduler/framework"
2525
)
2626

27+
// PluginName indicates name of volcano scheduler plugin.
28+
const PluginName = "conformance"
29+
2730
type conformancePlugin struct {
2831
// Arguments given for the plugin
2932
pluginArguments framework.Arguments
@@ -35,7 +38,7 @@ func New(arguments framework.Arguments) framework.Plugin {
3538
}
3639

3740
func (pp *conformancePlugin) Name() string {
38-
return "conformance"
41+
return PluginName
3942
}
4043

4144
func (pp *conformancePlugin) OnSessionOpen(ssn *framework.Session) {

pkg/scheduler/plugins/factory.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ import (
3030

3131
func init() {
3232
// Plugins for Jobs
33-
framework.RegisterPluginBuilder("drf", drf.New)
34-
framework.RegisterPluginBuilder("gang", gang.New)
35-
framework.RegisterPluginBuilder("predicates", predicates.New)
36-
framework.RegisterPluginBuilder("priority", priority.New)
37-
framework.RegisterPluginBuilder("nodeorder", nodeorder.New)
38-
framework.RegisterPluginBuilder("conformance", conformance.New)
33+
framework.RegisterPluginBuilder(drf.PluginName, drf.New)
34+
framework.RegisterPluginBuilder(gang.PluginName, gang.New)
35+
framework.RegisterPluginBuilder(predicates.PluginName, predicates.New)
36+
framework.RegisterPluginBuilder(priority.PluginName, priority.New)
37+
framework.RegisterPluginBuilder(nodeorder.PluginName, nodeorder.New)
38+
framework.RegisterPluginBuilder(conformance.PluginName, conformance.New)
3939

4040
// Plugins for Queues
41-
framework.RegisterPluginBuilder("proportion", proportion.New)
41+
framework.RegisterPluginBuilder(proportion.PluginName, proportion.New)
4242
}

pkg/scheduler/plugins/gang/gang.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ import (
3030
"volcano.sh/volcano/pkg/scheduler/metrics"
3131
)
3232

33+
// PluginName indicates name of volcano scheduler plugin.
34+
const PluginName = "gang"
35+
3336
type gangPlugin struct {
3437
// Arguments given for the plugin
3538
pluginArguments framework.Arguments
@@ -41,7 +44,7 @@ func New(arguments framework.Arguments) framework.Plugin {
4144
}
4245

4346
func (gp *gangPlugin) Name() string {
44-
return "gang"
47+
return PluginName
4548
}
4649

4750
func (gp *gangPlugin) OnSessionOpen(ssn *framework.Session) {

pkg/scheduler/plugins/nodeorder/nodeorder.go

+25-31
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ import (
3232
)
3333

3434
const (
35+
// PluginName indicates name of volcano scheduler plugin.
36+
PluginName = "nodeorder"
37+
3538
// NodeAffinityWeight is the key for providing Node Affinity Priority Weight in YAML
3639
NodeAffinityWeight = "nodeaffinity.weight"
3740
// PodAffinityWeight is the key for providing Pod Affinity Priority Weight in YAML
@@ -47,43 +50,13 @@ type nodeOrderPlugin struct {
4750
pluginArguments framework.Arguments
4851
}
4952

50-
func getInterPodAffinityScore(name string, interPodAffinityScore schedulerapi.HostPriorityList) int {
51-
for _, hostPriority := range interPodAffinityScore {
52-
if hostPriority.Host == name {
53-
return hostPriority.Score
54-
}
55-
}
56-
return 0
57-
}
58-
59-
type cachedNodeInfo struct {
60-
session *framework.Session
61-
}
62-
63-
func (c *cachedNodeInfo) GetNodeInfo(name string) (*v1.Node, error) {
64-
node, found := c.session.Nodes[name]
65-
if !found {
66-
for _, cacheNode := range c.session.Nodes {
67-
pods := cacheNode.Pods()
68-
for _, pod := range pods {
69-
if pod.Spec.NodeName == "" {
70-
return cacheNode.Node, nil
71-
}
72-
}
73-
}
74-
return nil, fmt.Errorf("failed to find node <%s>", name)
75-
}
76-
77-
return node.Node, nil
78-
}
79-
8053
//New function returns prioritizePlugin object
8154
func New(aruguments framework.Arguments) framework.Plugin {
8255
return &nodeOrderPlugin{pluginArguments: aruguments}
8356
}
8457

8558
func (pp *nodeOrderPlugin) Name() string {
86-
return "nodeorder"
59+
return PluginName
8760
}
8861

8962
type priorityWeight struct {
@@ -249,3 +222,24 @@ func (pp *nodeOrderPlugin) OnSessionOpen(ssn *framework.Session) {
249222

250223
func (pp *nodeOrderPlugin) OnSessionClose(ssn *framework.Session) {
251224
}
225+
226+
type cachedNodeInfo struct {
227+
session *framework.Session
228+
}
229+
230+
func (c *cachedNodeInfo) GetNodeInfo(name string) (*v1.Node, error) {
231+
node, found := c.session.Nodes[name]
232+
if !found {
233+
for _, cacheNode := range c.session.Nodes {
234+
pods := cacheNode.Pods()
235+
for _, pod := range pods {
236+
if pod.Spec.NodeName == "" {
237+
return cacheNode.Node, nil
238+
}
239+
}
240+
}
241+
return nil, fmt.Errorf("failed to find node <%s>", name)
242+
}
243+
244+
return node.Node, nil
245+
}

pkg/scheduler/plugins/predicates/predicates.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ import (
3232
)
3333

3434
const (
35+
// PluginName indicates name of volcano scheduler plugin.
36+
PluginName = "predicates"
37+
3538
// MemoryPressurePredicate is the key for enabling Memory Pressure Predicate in YAML
3639
MemoryPressurePredicate = "predicate.MemoryPressureEnable"
3740
// DiskPressurePredicate is the key for enabling Disk Pressure Predicate in YAML
@@ -51,7 +54,7 @@ func New(arguments framework.Arguments) framework.Plugin {
5154
}
5255

5356
func (pp *predicatesPlugin) Name() string {
54-
return "predicates"
57+
return PluginName
5558
}
5659

5760
func formatReason(reasons []algorithm.PredicateFailureReason) string {

pkg/scheduler/plugins/priority/priority.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ import (
2222
"volcano.sh/volcano/pkg/scheduler/framework"
2323
)
2424

25+
// PluginName indicates name of volcano scheduler plugin.
26+
const PluginName = "priority"
27+
2528
type priorityPlugin struct {
2629
// Arguments given for the plugin
2730
pluginArguments framework.Arguments
@@ -33,7 +36,7 @@ func New(arguments framework.Arguments) framework.Plugin {
3336
}
3437

3538
func (pp *priorityPlugin) Name() string {
36-
return "priority"
39+
return PluginName
3740
}
3841

3942
func (pp *priorityPlugin) OnSessionOpen(ssn *framework.Session) {

pkg/scheduler/plugins/proportion/proportion.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ import (
2424
"volcano.sh/volcano/pkg/scheduler/framework"
2525
)
2626

27+
// PluginName indicates name of volcano scheduler plugin.
28+
const PluginName = "proportion"
29+
2730
type proportionPlugin struct {
2831
totalResource *api.Resource
2932
queueOpts map[api.QueueID]*queueAttr
@@ -52,7 +55,7 @@ func New(arguments framework.Arguments) framework.Plugin {
5255
}
5356

5457
func (pp *proportionPlugin) Name() string {
55-
return "proportion"
58+
return PluginName
5659
}
5760

5861
func (pp *proportionPlugin) OnSessionOpen(ssn *framework.Session) {

0 commit comments

Comments
 (0)