Skip to content

Commit

Permalink
Merge pull request #41 from Project-HAMi/fix_multinode
Browse files Browse the repository at this point in the history
fix find pending pod error on multi nodes scenario
  • Loading branch information
archlitchi authored Dec 13, 2024
2 parents 680cd35 + 24ab2f1 commit 69e8c3c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
github.com/NVIDIA/go-nvml v0.12.4-0
github.com/NVIDIA/gpu-monitoring-tools v0.0.0-20201109160820-d08ea3cdcce4
github.com/fsnotify/fsnotify v1.4.9
github.com/mitchellh/gox v1.0.1 // indirect
github.com/prometheus/client_golang v1.0.0
github.com/prometheus/common v0.4.1
github.com/spf13/cobra v0.0.5
Expand Down
12 changes: 7 additions & 5 deletions pkg/plugin/vgpu/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,25 @@ func GetPendingPod(node string) (*v1.Pod, error) {
return nil, err
}

oldestPod := getOldestPod(podList.Items)
oldestPod := getOldestPod(podList.Items, node)
if oldestPod == nil {
return nil, fmt.Errorf("cannot get valid pod")
}

return oldestPod, nil
}

func getOldestPod(pods []v1.Pod) *v1.Pod {
func getOldestPod(pods []v1.Pod, nodename string) *v1.Pod {
if len(pods) == 0 {
return nil
}
oldest := pods[0]
for _, pod := range pods {
klog.V(4).Infof("pod %s, predicate time: %s", pod.Name, pod.Annotations[AssignedTimeAnnotations])
if getPredicateTimeFromPodAnnotation(&oldest) > getPredicateTimeFromPodAnnotation(&pod) {
oldest = pod
if pod.Annotations[AssignedNodeAnnotations] == nodename {
klog.V(4).Infof("pod %s, predicate time: %s", pod.Name, pod.Annotations[AssignedTimeAnnotations])
if getPredicateTimeFromPodAnnotation(&oldest) > getPredicateTimeFromPodAnnotation(&pod) {
oldest = pod
}
}
}
klog.V(4).Infof("oldest pod %#v, predicate time: %#v", oldest.Name,
Expand Down

0 comments on commit 69e8c3c

Please sign in to comment.