diff --git a/pkg/scheduler/api/device_info.go b/pkg/scheduler/api/device_info.go index fc5f8d8f94..1f85792532 100644 --- a/pkg/scheduler/api/device_info.go +++ b/pkg/scheduler/api/device_info.go @@ -56,12 +56,11 @@ func (g *GPUDevice) getUsedGPUMemory() uint { // isIdleGPU check if the device is idled. func (g *GPUDevice) isIdleGPU() bool { if g.PodMap == nil { - return true + return true } return false } - // GetGPUResourceOfPod returns the GPU resource required by the pod. func GetGPUResourceOfPod(pod *v1.Pod) uint { var mem uint @@ -80,12 +79,11 @@ func getGPUResourceOfContainer(container *v1.Container) uint { return mem } - // GetGPUNumberOfPod returns the number of GPUs required by the pod. func GetGPUNumberOfPod(pod *v1.Pod) int { var gpus int for _, container := range pod.Spec.Containers { - gpus += getGPUNumberOfContainer(&container) + gpus += getGPUNumberOfContainer(&container) } return gpus } @@ -97,4 +95,4 @@ func getGPUNumberOfContainer(container *v1.Container) int { gpus = int(val.Value()) } return gpus -} \ No newline at end of file +} diff --git a/pkg/scheduler/api/node_info.go b/pkg/scheduler/api/node_info.go index 9b86a9507c..244edc1f71 100644 --- a/pkg/scheduler/api/node_info.go +++ b/pkg/scheduler/api/node_info.go @@ -500,23 +500,22 @@ func (ni *NodeInfo) getDevicesAllGPUMemory() map[int]uint { func (ni *NodeInfo) GetDevicesIdleGPUs() []int { res := []int{} for _, device := range ni.GPUDevices { - if device.isIdleGPU(){ - res = append(res, device.ID) + if device.isIdleGPU() { + res = append(res, device.ID) } } return res } - // AddGPUResource adds the pod to GPU pool if it is assigned func (ni *NodeInfo) AddGPUResource(pod *v1.Pod) { gpuRes := GetGPUResourceOfPod(pod) if gpuRes > 0 { ids := GetGPUIndex(pod) for _, id := range ids { - if dev := ni.GPUDevices[id]; dev != nil { - dev.PodMap[string(pod.UID)] = pod - } + if dev := ni.GPUDevices[id]; dev != nil { + dev.PodMap[string(pod.UID)] = pod + } } } } @@ -527,9 +526,9 @@ func (ni *NodeInfo) SubGPUResource(pod *v1.Pod) { if gpuRes > 0 { ids := GetGPUIndex(pod) for _, id := range ids { - if dev := ni.GPUDevices[id]; dev != nil { - delete(dev.PodMap, string(pod.UID)) - } + if dev := ni.GPUDevices[id]; dev != nil { + delete(dev.PodMap, string(pod.UID)) + } } } } diff --git a/pkg/scheduler/api/pod_info.go b/pkg/scheduler/api/pod_info.go index b126d5ef6b..5b816fe1f1 100644 --- a/pkg/scheduler/api/pod_info.go +++ b/pkg/scheduler/api/pod_info.go @@ -147,13 +147,13 @@ func GetGPUIndex(pod *v1.Pod) []int { ids := strings.Split(value, ",") idSlice := make([]int, len(ids)) for idx, id := range ids { - j, err := strconv.Atoi(id) - if err != nil { - klog.Errorf("invalid %s=%s", GPUIndex, value) - return nil - } - idSlice[idx] = j - } + j, err := strconv.Atoi(id) + if err != nil { + klog.Errorf("invalid %s=%s", GPUIndex, value) + return nil + } + idSlice[idx] = j + } return idSlice } } @@ -170,7 +170,7 @@ func escapeJSONPointer(p string) string { // AddGPUIndexPatch returns the patch adding GPU index func AddGPUIndexPatch(ids []int) string { - idsstring := strings.Trim(strings.Replace(fmt.Sprint(ids), " ", ",", -1), "[]") + idsstring := strings.Trim(strings.Replace(fmt.Sprint(ids), " ", ",", -1), "[]") return fmt.Sprintf(`[{"op": "add", "path": "/metadata/annotations/%s", "value":"%d"},`+ `{"op": "add", "path": "/metadata/annotations/%s", "value": "%s"}]`, escapeJSONPointer(PredicateTime), time.Now().UnixNano(), diff --git a/pkg/scheduler/plugins/predicates/gpu.go b/pkg/scheduler/plugins/predicates/gpu.go index 7e0ab71a3c..e176e5bb52 100644 --- a/pkg/scheduler/plugins/predicates/gpu.go +++ b/pkg/scheduler/plugins/predicates/gpu.go @@ -25,7 +25,6 @@ import ( "volcano.sh/volcano/pkg/scheduler/api" ) - // checkNodeGPUSharingPredicate checks if a pod with gpu requirement can be scheduled on a node. func checkNodeGPUSharingPredicate(pod *v1.Pod, nodeInfo *api.NodeInfo) (bool, error) { // no gpu sharing request @@ -42,13 +41,13 @@ func checkNodeGPUSharingPredicate(pod *v1.Pod, nodeInfo *api.NodeInfo) (bool, er func checkNodeGPUNumberPredicate(pod *v1.Pod, nodeInfo *api.NodeInfo) (bool, error) { //no gpu number request if api.GetGPUNumberOfPod(pod) <= 0 { - return true, nil + return true, nil } ids := predicateGPUbyNumber(pod, nodeInfo) - if ids == nil{ + if ids == nil { return false, fmt.Errorf("no enough gpu number on node %s", nodeInfo.Name) } - return true, nil + return true, nil } // predicateGPU returns the available GPU ID @@ -79,16 +78,16 @@ func predicateGPUbyNumber(pod *v1.Pod, node *api.NodeInfo) []int { var devIDs []int if len(allocatableGPUs) < gpuRequest { - klog.Errorf("Not enough gpu cards") - return nil - } + klog.Errorf("Not enough gpu cards") + return nil + } for devID := 0; devID < len(allocatableGPUs); devID++ { devIDs = append(devIDs, allocatableGPUs[devID]) - if len(devIDs) == gpuRequest{ - return devIDs; - } + if len(devIDs) == gpuRequest { + return devIDs + } } return nil -} \ No newline at end of file +} diff --git a/pkg/scheduler/plugins/predicates/predicates.go b/pkg/scheduler/plugins/predicates/predicates.go index 2341191589..666b82b600 100644 --- a/pkg/scheduler/plugins/predicates/predicates.go +++ b/pkg/scheduler/plugins/predicates/predicates.go @@ -46,7 +46,7 @@ const ( // GPUSharingPredicate is the key for enabling GPU Sharing Predicate in YAML GPUSharingPredicate = "predicate.GPUSharingEnable" - GPUNumberPredicate = "predicate.GPUNumberEnable" + GPUNumberPredicate = "predicate.GPUNumberEnable" // CachePredicate control cache predicate feature CachePredicate = "predicate.CacheEnable" @@ -123,8 +123,8 @@ func enablePredicate(args framework.Arguments) predicateEnable { args.GetBool(&predicate.gpuSharingEnable, GPUSharingPredicate) args.GetBool(&predicate.gpuNumberEnable, GPUNumberPredicate) - if predicate.gpuSharingEnable && predicate.gpuNumberEnable{ - klog.Errorf("can not define true in both gpu sharing and gpu number") + if predicate.gpuSharingEnable && predicate.gpuNumberEnable { + klog.Errorf("can not define true in both gpu sharing and gpu number") } args.GetBool(&predicate.cacheEnable, CachePredicate) @@ -183,7 +183,7 @@ func (pp *predicatesPlugin) OnSessionOpen(ssn *framework.Session) { } //predicate gpu sharing - if predicate.gpuSharingEnable && api.GetGPUResourceOfPod(pod) > 0 { + if predicate.gpuSharingEnable && api.GetGPUResourceOfPod(pod) > 0 { nodeInfo, ok := ssn.Nodes[nodeName] if !ok { klog.Errorf("Failed to get node %s info from cache", nodeName) @@ -201,18 +201,18 @@ func (pp *predicatesPlugin) OnSessionOpen(ssn *framework.Session) { return } for _, id := range ids { - dev, ok := nodeInfo.GPUDevices[id] - if !ok { - klog.Errorf("Failed to get GPU %d from node %s", id, nodeName) - return - } - dev.PodMap[string(pod.UID)] = pod + dev, ok := nodeInfo.GPUDevices[id] + if !ok { + klog.Errorf("Failed to get GPU %d from node %s", id, nodeName) + return + } + dev.PodMap[string(pod.UID)] = pod } klog.V(4).Infof("predicates with gpu sharing, update pod %s/%s allocate to node [%s]", pod.Namespace, pod.Name, nodeName) } //predicate gpu number - if predicate.gpuNumberEnable && api.GetGPUNumberOfPod(pod) > 0 { + if predicate.gpuNumberEnable && api.GetGPUNumberOfPod(pod) > 0 { nodeInfo, ok := ssn.Nodes[nodeName] if !ok { klog.Errorf("Failed to get node %s info from cache", nodeName) @@ -230,12 +230,12 @@ func (pp *predicatesPlugin) OnSessionOpen(ssn *framework.Session) { return } for _, id := range ids { - dev, ok := nodeInfo.GPUDevices[id] - if !ok { - klog.Errorf("Failed to get GPU %d from node %s", id, nodeName) - return - } - dev.PodMap[string(pod.UID)] = pod + dev, ok := nodeInfo.GPUDevices[id] + if !ok { + klog.Errorf("Failed to get GPU %d from node %s", id, nodeName) + return + } + dev.PodMap[string(pod.UID)] = pod } klog.V(4).Infof("predicates with gpu number, update pod %s/%s allocate to node [%s]", pod.Namespace, pod.Name, nodeName) } @@ -268,9 +268,9 @@ func (pp *predicatesPlugin) OnSessionOpen(ssn *framework.Session) { return } for _, id := range ids { - if dev, ok := nodeInfo.GPUDevices[id]; ok { - delete(dev.PodMap, string(pod.UID)) - } + if dev, ok := nodeInfo.GPUDevices[id]; ok { + delete(dev.PodMap, string(pod.UID)) + } } klog.V(4).Infof("predicates with gpu sharing, update pod %s/%s deallocate from node [%s]", pod.Namespace, pod.Name, nodeName) @@ -403,7 +403,7 @@ func (pp *predicatesPlugin) OnSessionOpen(ssn *framework.Session) { if predicate.gpuNumberEnable { //CheckGPUNumberPredicate fit, err := checkNodeGPUNumberPredicate(task.Pod, node) - if err != nil{ + if err != nil { return err }