From 9277ceaf62640b24ae75e3ac87c58c9fd02a5f1d Mon Sep 17 00:00:00 2001 From: googs1025 Date: Wed, 1 May 2024 12:14:58 +0800 Subject: [PATCH] fix: FilterNode err miss predicateStatus Signed-off-by: googs1025 --- pkg/scheduler/api/shared_device_pool.go | 12 +++++------ .../plugins/deviceshare/deviceshare.go | 20 +++++++++++-------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/pkg/scheduler/api/shared_device_pool.go b/pkg/scheduler/api/shared_device_pool.go index 865dba0dcd..7d89f5b50b 100644 --- a/pkg/scheduler/api/shared_device_pool.go +++ b/pkg/scheduler/api/shared_device_pool.go @@ -32,13 +32,13 @@ type Devices interface { //following two functions used in node_info //AddResource is to add the corresponding device resource of this 'pod' into current scheduler cache AddResource(pod *v1.Pod) - //SubResoure is to substract the corresponding device resource of this 'pod' from current scheduler cache + //SubResource is to subtract the corresponding device resource of this 'pod' from current scheduler cache SubResource(pod *v1.Pod) //following four functions used in predicate //HasDeviceRequest checks if the 'pod' request this device HasDeviceRequest(pod *v1.Pod) bool - //FiltreNode checks if the 'pod' fit in current node + // FilterNode checks if the 'pod' fit in current node // The first return value represents the filtering result, and the value range is "0, 1, 2, 3" // 0: Success // Success means that plugin ran correctly and found pod schedulable. @@ -58,15 +58,15 @@ type Devices interface { // that the pod can get scheduled with preemption. // The accompanying status message should explain why the pod is unschedulable. FilterNode(pod *v1.Pod) (int, string, error) - //Allocate action in predicate + // Allocate action in predicate Allocate(kubeClient kubernetes.Interface, pod *v1.Pod) error - //Release action in predicate + // Release action in predicate Release(kubeClient kubernetes.Interface, pod *v1.Pod) error - //IgnredDevices notify vc-scheduler to ignore devices in return list + // GetIgnoredDevices notify vc-scheduler to ignore devices in return list GetIgnoredDevices() []string - //used for debug and monitor + // GetStatus used for debug and monitor GetStatus() string } diff --git a/pkg/scheduler/plugins/deviceshare/deviceshare.go b/pkg/scheduler/plugins/deviceshare/deviceshare.go index 0fd3d2b710..0b35952323 100644 --- a/pkg/scheduler/plugins/deviceshare/deviceshare.go +++ b/pkg/scheduler/plugins/deviceshare/deviceshare.go @@ -68,6 +68,14 @@ func enablePredicate(args framework.Arguments) { } } +func createStatus(code int, reason string) *api.Status { + status := api.Status{ + Code: code, + Reason: reason, + } + return &status +} + func (dp *deviceSharePlugin) OnSessionOpen(ssn *framework.Session) { enablePredicate(dp.pluginArguments) // Register event handlers to update task info in PodLister & nodeMap @@ -77,20 +85,16 @@ func (dp *deviceSharePlugin) OnSessionOpen(ssn *framework.Session) { for _, val := range api.RegisteredDevices { if dev, ok := node.Others[val].(api.Devices); ok { if dev == nil { - predicateStatus = append(predicateStatus, &api.Status{ - Code: devices.Unschedulable, - Reason: "node not initialized with device" + val, - }) + predicateStatus = append(predicateStatus, + createStatus(devices.Unschedulable, "node not initialized with device"+val)) return predicateStatus, fmt.Errorf("node not initialized with device %s", val) } code, msg, err := dev.FilterNode(task.Pod) - filterNodeStatus := &api.Status{ - Code: code, - Reason: msg, - } if err != nil { + predicateStatus = append(predicateStatus, createStatus(code, msg)) return predicateStatus, err } + filterNodeStatus := createStatus(code, msg) if filterNodeStatus.Code != api.Success { predicateStatus = append(predicateStatus, filterNodeStatus) return predicateStatus, fmt.Errorf("plugin device filternode predicates failed %s", msg)