From f78fec9f751bbd5344385340c09fd0d5ea90153d Mon Sep 17 00:00:00 2001 From: limengxuan <391013634@qq.com> Date: Mon, 17 Jul 2023 20:48:17 +0800 Subject: [PATCH] mv devicescore to a new plugin called devicescore --- .../plugins/devicescore/devicescore.go | 65 +++++++++++++++++++ .../plugins/predicates/predicates.go | 20 ------ 2 files changed, 65 insertions(+), 20 deletions(-) create mode 100644 pkg/scheduler/plugins/devicescore/devicescore.go diff --git a/pkg/scheduler/plugins/devicescore/devicescore.go b/pkg/scheduler/plugins/devicescore/devicescore.go new file mode 100644 index 00000000000..bccc96257f8 --- /dev/null +++ b/pkg/scheduler/plugins/devicescore/devicescore.go @@ -0,0 +1,65 @@ +/* +Copyright 2018 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package devicescore + +import ( + "k8s.io/klog/v2" + + "volcano.sh/volcano/pkg/scheduler/api" + "volcano.sh/volcano/pkg/scheduler/framework" +) + +// PluginName indicates name of volcano scheduler plugin. +const PluginName = "devicescore" + +type priorityPlugin struct { + // Arguments given for the plugin + pluginArguments framework.Arguments +} + +// New return priority plugin +func New(arguments framework.Arguments) framework.Plugin { + return &priorityPlugin{pluginArguments: arguments} +} + +func (pp *priorityPlugin) Name() string { + return PluginName +} + +func (pp *priorityPlugin) OnSessionOpen(ssn *framework.Session) { + ssn.AddNodeOrderFn(pp.Name(), func(task *api.TaskInfo, node *api.NodeInfo) (float64, error) { + score := float64(0) + for _, val := range api.RegisteredDevices { + if devices, ok := node.Others[val].(api.Devices); ok { + if !devices.HasDeviceRequest(task.Pod) { + continue + } + tmp, err := devices.ScoreNode(task.Pod) + if err != nil { + klog.Warningln("scoreNode failed in predicate nodeorderFn", err.Error()) + return 0, err + } + score += tmp + } else { + klog.Warningf("Devices %s assertion conversion failed, skip", val) + } + } + return score, nil + }) +} + +func (pp *priorityPlugin) OnSessionClose(ssn *framework.Session) {} diff --git a/pkg/scheduler/plugins/predicates/predicates.go b/pkg/scheduler/plugins/predicates/predicates.go index 64ae724613f..c4d61108515 100644 --- a/pkg/scheduler/plugins/predicates/predicates.go +++ b/pkg/scheduler/plugins/predicates/predicates.go @@ -393,26 +393,6 @@ func (pp *predicatesPlugin) OnSessionOpen(ssn *framework.Session) { return nil }) - ssn.AddNodeOrderFn(pp.Name(), func(task *api.TaskInfo, node *api.NodeInfo) (float64, error) { - score := float64(0) - for _, val := range api.RegisteredDevices { - if devices, ok := node.Others[val].(api.Devices); ok { - if !devices.HasDeviceRequest(task.Pod) { - continue - } - tmp, err := devices.ScoreNode(task.Pod) - if err != nil { - klog.Warningln("scoreNode failed in predicate nodeorderFn", err.Error()) - return 0, err - } - score += tmp - } else { - klog.Warningf("Devices %s assertion conversion failed, skip", val) - } - } - return score, nil - }) - ssn.AddPredicateFn(pp.Name(), func(task *api.TaskInfo, node *api.NodeInfo) error { nodeInfo, found := nodeMap[node.Name] if !found {