-
Notifications
You must be signed in to change notification settings - Fork 804
refactor: replace NVML util panics with error returns #2234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -121,29 +121,25 @@ var eraseNextDeviceTypeFromAnnotation = func(dtype string, p corev1.Pod) error { | |
| return util.PatchPodAnnotations(&p, newannos) | ||
| } | ||
|
|
||
| func GetIndexAndTypeFromUUID(uuid string) (string, int) { | ||
| func GetIndexAndTypeFromUUID(uuid string) (string, int, error) { | ||
| defer nvml.Shutdown() | ||
| if nvret := nvml.Init(); nvret != nvml.SUCCESS { | ||
| klog.Errorln("nvml Init err: ", nvret) | ||
| panic(0) | ||
| return "", 0, fmt.Errorf("nvml Init err: %v", nvret) | ||
| } | ||
| originuuid := strings.Split(uuid, "[")[0] | ||
| ndev, ret := nvml.DeviceGetHandleByUUID(originuuid) | ||
| if ret != nvml.SUCCESS { | ||
| klog.Error("nvml get handlebyuuid error ret=", ret) | ||
| panic(0) | ||
| return "", 0, fmt.Errorf("nvml get handlebyuuid error ret=%v", ret) | ||
| } | ||
| Model, ret := ndev.GetName() | ||
| if ret != nvml.SUCCESS { | ||
| klog.Error("nvml get name error ret=", ret) | ||
| panic(0) | ||
| return "", 0, fmt.Errorf("nvml get name error ret=%v", ret) | ||
| } | ||
| index, ret := ndev.GetIndex() | ||
| if ret != nvml.SUCCESS { | ||
| klog.Error("nvml get index error ret=", ret) | ||
| panic(0) | ||
| return "", 0, fmt.Errorf("nvml get index error ret=%v", ret) | ||
| } | ||
| return Model, index | ||
| return Model, index, nil | ||
| } | ||
|
|
||
| func GetMigUUIDFromSmiOutput(output string, uuid string, idx int) string { | ||
|
|
@@ -178,17 +174,15 @@ func GetMigUUIDFromSmiOutput(output string, uuid string, idx int) string { | |
| return "" | ||
| } | ||
|
|
||
| func GetMigUUIDFromIndex(uuid string, idx int) string { | ||
| func GetMigUUIDFromIndex(uuid string, idx int) (string, error) { | ||
| defer nvml.Shutdown() | ||
| if nvret := nvml.Init(); nvret != nvml.SUCCESS { | ||
| klog.Errorln("nvml Init err: ", nvret) | ||
| panic(0) | ||
| return "", fmt.Errorf("nvml Init err: %v", nvret) | ||
| } | ||
| originuuid := strings.Split(uuid, "[")[0] | ||
| ndev, ret := nvml.DeviceGetHandleByUUID(originuuid) | ||
| if ret != nvml.SUCCESS { | ||
| klog.Error(`nvml get device uuid error ret=`, ret) | ||
| panic(0) | ||
| return "", fmt.Errorf("nvml get device uuid error ret=%v", ret) | ||
| } | ||
| migdev, ret := nvml.DeviceGetMigDeviceHandleByIndex(ndev, idx) | ||
| if ret != nvml.SUCCESS { | ||
|
|
@@ -199,18 +193,17 @@ func GetMigUUIDFromIndex(uuid string, idx int) string { | |
| cmd.Stderr = &stderr | ||
| err := cmd.Run() | ||
| if err != nil { | ||
| klog.Fatalf("nvidia-smi -L failed with %s\n", err) | ||
| return "", fmt.Errorf("nvidia-smi -L failed with %s", err) | ||
| } | ||
| outStr := stdout.String() | ||
| uuid := GetMigUUIDFromSmiOutput(outStr, originuuid, idx) | ||
| return uuid | ||
| return uuid, nil | ||
| } | ||
| res, ret := migdev.GetUUID() | ||
| if ret != nvml.SUCCESS { | ||
| klog.Error(`nvml get mig uuid error ret=`, ret) | ||
| panic(0) | ||
| return "", fmt.Errorf("nvml get mig uuid error ret=%v", ret) | ||
| } | ||
| return res | ||
| return res, nil | ||
| } | ||
|
|
||
| func GetMigGpuInstanceIdFromIndex(uuid string, idx int) (int, error) { | ||
|
|
@@ -465,7 +458,11 @@ func (nv *NvidiaDevicePlugin) GetContainerDeviceStrArray(c device.ContainerDevic | |
| if !strings.Contains(val.UUID, "[") { | ||
| tmp = append(tmp, val.UUID) | ||
| } else { | ||
| devtype, devindex := GetIndexAndTypeFromUUID(val.UUID) | ||
| devtype, devindex, err := GetIndexAndTypeFromUUID(val.UUID) | ||
| if err != nil { | ||
| klog.Errorf("failed to get index and type from UUID %s: %v", val.UUID, err) | ||
| continue | ||
| } | ||
|
Comment on lines
+461
to
+465
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift Fail allocation when conversion drops a requested device. These Return an error from Also applies to: 500-505 🤖 Prompt for AI Agents |
||
| position, needsreset = nv.GenerateMigTemplate(devtype, devindex, val) | ||
| if needsreset { | ||
| nv.ApplyMigTemplate() | ||
|
|
@@ -500,7 +497,12 @@ func (nv *NvidiaDevicePlugin) GetContainerDeviceStrArray(c device.ContainerDevic | |
| } | ||
| } | ||
| } | ||
| tmp = append(tmp, GetMigUUIDFromIndex(val.UUID, position)) | ||
| migUUID, err := GetMigUUIDFromIndex(val.UUID, position) | ||
| if err != nil { | ||
| klog.Errorf("failed to get mig uuid for %s: %v", val.UUID, err) | ||
| continue | ||
| } | ||
| tmp = append(tmp, migUUID) | ||
| } | ||
| } | ||
| klog.V(3).Infoln("mig current=", nv.migCurrent, ":", needsreset, "position=", position, "uuid lists", tmp) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Return an error when the fallback does not find a MIG UUID.
GetMigUUIDFromSmiOutputreturns""when the requested MIG device is absent from the output. Lines 198-200 currently report that result as success. Line 505 then appends an empty device identifier.Return a non-nil error when
migUUID == ""so the existing error path logs and skips the device.Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents