Skip to content

Commit ee141f9

Browse files
committed
Reorganise setting toolkit config options
Signed-off-by: Evan Lezar <[email protected]>
1 parent 646503f commit ee141f9

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

tools/container/toolkit/toolkit.go

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -361,24 +361,28 @@ func installToolkitConfig(c *cli.Context, toolkitConfigPath string, nvidiaContai
361361
}
362362
defer targetConfig.Close()
363363

364-
// Set the options in the root toml table
365-
config.Set("accept-nvidia-visible-devices-envvar-when-unprivileged", opts.acceptNVIDIAVisibleDevicesWhenUnprivileged)
366-
config.Set("accept-nvidia-visible-devices-as-volume-mounts", opts.acceptNVIDIAVisibleDevicesAsVolumeMounts)
367-
368-
nvidiaContainerCliKey := func(p string) []string {
369-
return []string{"nvidia-container-cli", p}
370-
}
371-
372364
// Read the ldconfig path from the config as this may differ per platform
373365
// On ubuntu-based systems this ends in `.real`
374-
ldconfigPath := fmt.Sprintf("%s", config.GetPath(nvidiaContainerCliKey("ldconfig")))
375-
366+
ldconfigPath := fmt.Sprintf("%s", config.GetDefault("nvidia-container-cli.ldconfig", "/sbin/ldconfig"))
376367
// Use the driver run root as the root:
377368
driverLdconfigPath := "@" + filepath.Join(opts.DriverRoot, strings.TrimPrefix(ldconfigPath, "@/"))
378369

379-
config.SetPath(nvidiaContainerCliKey("root"), opts.DriverRoot)
380-
config.SetPath(nvidiaContainerCliKey("path"), nvidiaContainerCliExecutablePath)
381-
config.SetPath(nvidiaContainerCliKey("ldconfig"), driverLdconfigPath)
370+
configValues := map[string]interface{}{
371+
// Set the options in the root toml table
372+
"accept-nvidia-visible-devices-envvar-when-unprivileged": opts.acceptNVIDIAVisibleDevicesWhenUnprivileged,
373+
"accept-nvidia-visible-devices-as-volume-mounts": opts.acceptNVIDIAVisibleDevicesAsVolumeMounts,
374+
// Set the nvidia-container-cli options
375+
"nvidia-container-cli.root": opts.DriverRoot,
376+
"nvidia-container-cli.path": nvidiaContainerCliExecutablePath,
377+
"nvidia-container-cli.ldconfig": driverLdconfigPath,
378+
// Set nvidia-ctk options
379+
"nvidia-ctk.path": nvidiaCTKPath,
380+
// Set the nvidia-container-runtime-hook options
381+
"nvidia-container-runtime-hook.skip-mode-detection": opts.ContainerRuntimeHookSkipModeDetection,
382+
}
383+
for key, value := range configValues {
384+
config.Set(key, value)
385+
}
382386

383387
// Set the optional config options
384388
optionalConfigValues := map[string]interface{}{
@@ -416,12 +420,6 @@ func installToolkitConfig(c *cli.Context, toolkitConfigPath string, nvidiaContai
416420
config.Set(key, value)
417421
}
418422

419-
// Set nvidia-ctk options
420-
config.Set("nvidia-ctk.path", nvidiaCTKPath)
421-
422-
// Set the nvidia-container-runtime-hook options
423-
config.Set("nvidia-container-runtime-hook.skip-mode-detection", opts.ContainerRuntimeHookSkipModeDetection)
424-
425423
_, err = config.WriteTo(targetConfig)
426424
if err != nil {
427425
return fmt.Errorf("error writing config: %v", err)

0 commit comments

Comments
 (0)