diff --git a/pkg/device-plugin/nvidiadevice/nvinternal/plugin/server.go b/pkg/device-plugin/nvidiadevice/nvinternal/plugin/server.go index 8a3890ead5..a3c482ac2c 100644 --- a/pkg/device-plugin/nvidiadevice/nvinternal/plugin/server.go +++ b/pkg/device-plugin/nvidiadevice/nvinternal/plugin/server.go @@ -312,15 +312,19 @@ func (plugin *NvidiaDevicePlugin) Start(kubeletSocket string) error { klog.Warning("Falling back to non‑MIG configuration") } else { outStr := stdout.Bytes() - yaml.Unmarshal(outStr, &plugin.migCurrent) - writeMigConfig(outStr) - - HamiInitMigConfig, err := plugin.processMigConfigs(plugin.migCurrent.MigConfigs, deviceNumbers) - if err != nil { - klog.Infof("no device in node: %v", err) + if err := yaml.Unmarshal(outStr, &plugin.migCurrent); err != nil { + klog.Errorf("failed to unmarshal mig config: %v", err) + klog.Warning("Falling back to non-MIG configuration") } else { - plugin.migCurrent.MigConfigs["current"] = HamiInitMigConfig - migApplied = true + writeMigConfig(outStr) + + HamiInitMigConfig, err := plugin.processMigConfigs(plugin.migCurrent.MigConfigs, deviceNumbers) + if err != nil { + klog.Infof("no device in node: %v", err) + } else { + plugin.migCurrent.MigConfigs["current"] = HamiInitMigConfig + migApplied = true + } } } } @@ -673,12 +677,27 @@ func (plugin *NvidiaDevicePlugin) Allocate(ctx context.Context, reqs *kubeletdev response.Envs[util.CoreLimitSwitch] = "disable" } cacheFileHostDirectory := fmt.Sprintf("%s/vgpu/containers/%s_%s", hostHookPath, current.UID, currentCtr.Name) - os.RemoveAll(cacheFileHostDirectory) + if err := os.RemoveAll(cacheFileHostDirectory); err != nil { + PodAllocationFailed(nodename, current, NodeLockNvidia) + return &kubeletdevicepluginv1beta1.AllocateResponse{}, fmt.Errorf("failed to remove cache directory: %v", err) + } - os.MkdirAll(cacheFileHostDirectory, 0777) - os.Chmod(cacheFileHostDirectory, 0777) - os.MkdirAll("/tmp/vgpulock", 0777) - os.Chmod("/tmp/vgpulock", 0777) + if err := os.MkdirAll(cacheFileHostDirectory, 0777); err != nil { + PodAllocationFailed(nodename, current, NodeLockNvidia) + return &kubeletdevicepluginv1beta1.AllocateResponse{}, fmt.Errorf("failed to create cache directory: %v", err) + } + if err := os.Chmod(cacheFileHostDirectory, 0777); err != nil { + PodAllocationFailed(nodename, current, NodeLockNvidia) + return &kubeletdevicepluginv1beta1.AllocateResponse{}, fmt.Errorf("failed to chmod cache directory: %v", err) + } + if err := os.MkdirAll("/tmp/vgpulock", 0777); err != nil { + PodAllocationFailed(nodename, current, NodeLockNvidia) + return &kubeletdevicepluginv1beta1.AllocateResponse{}, fmt.Errorf("failed to create lock directory: %v", err) + } + if err := os.Chmod("/tmp/vgpulock", 0777); err != nil { + PodAllocationFailed(nodename, current, NodeLockNvidia) + return &kubeletdevicepluginv1beta1.AllocateResponse{}, fmt.Errorf("failed to chmod lock directory: %v", err) + } response.Mounts = append(response.Mounts, &kubeletdevicepluginv1beta1.Mount{ContainerPath: fmt.Sprintf("%s/vgpu/libvgpu.so", hostHookPath), HostPath: GetLibPath(), diff --git a/pkg/device-plugin/nvidiadevice/nvinternal/plugin/server_test.go b/pkg/device-plugin/nvidiadevice/nvinternal/plugin/server_test.go index 21ff292b90..7e450732fb 100644 --- a/pkg/device-plugin/nvidiadevice/nvinternal/plugin/server_test.go +++ b/pkg/device-plugin/nvidiadevice/nvinternal/plugin/server_test.go @@ -964,6 +964,10 @@ func TestAlignContainerDevicesWithAllocatedIDsRejectsLengthMismatch(t *testing.T } func TestAllocateUsesKubeletSelectedUUIDsForVGPUResponse(t *testing.T) { + previousHostHookPath := hostHookPath + hostHookPath = t.TempDir() + defer func() { hostHookPath = previousHostHookPath }() + deviceListStrategies, _ := v1.NewDeviceListStrategies([]string{"envvar"}) deviceIDStrategy := v1.DeviceIDStrategyUUID memScale := 1.0 @@ -1036,6 +1040,10 @@ func TestAllocateUsesKubeletSelectedUUIDsForVGPUResponse(t *testing.T) { } func TestAllocatePreservesContainerOrderWhenOneContainerFallsBack(t *testing.T) { + previousHostHookPath := hostHookPath + hostHookPath = t.TempDir() + defer func() { hostHookPath = previousHostHookPath }() + deviceListStrategies, _ := v1.NewDeviceListStrategies([]string{"envvar"}) deviceIDStrategy := v1.DeviceIDStrategyUUID memScale := 1.0 diff --git a/pkg/scheduler/routes/route.go b/pkg/scheduler/routes/route.go index 38dd0a7127..e8014b6cb0 100644 --- a/pkg/scheduler/routes/route.go +++ b/pkg/scheduler/routes/route.go @@ -86,11 +86,15 @@ func PredicateRoute(s *scheduler.Scheduler) httprouter.Handle { Error: fmt.Sprintf("Failed to marshal extender filter result: %s", err.Error()), } resultBody, _ = json.Marshal(extenderFilterResult) - w.Write(resultBody) + if _, err := w.Write(resultBody); err != nil { + klog.ErrorS(err, "Failed to write response") + } } else { w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) - w.Write(resultBody) + if _, err := w.Write(resultBody); err != nil { + klog.ErrorS(err, "Failed to write response") + } } } } @@ -128,12 +132,16 @@ func Bind(s *scheduler.Scheduler) httprouter.Handle { Error: fmt.Sprintf("Failed to marshal binding result: %s", err.Error()), } response, _ := json.Marshal(extenderBindingResult) - w.Write(response) + if _, err := w.Write(response); err != nil { + klog.ErrorS(err, "Failed to write response") + } } else { klog.V(5).InfoS("Returning bind response", "result", extenderBindingResult) w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) - w.Write(response) + if _, err := w.Write(response); err != nil { + klog.ErrorS(err, "Failed to write response") + } } } }