Skip to content

Commit 7ff2399

Browse files
cdesiniotiselezar
authored andcommitted
Add option to nvidia-ctk to enable CDI in docker
Signed-off-by: Christopher Desiniotis <[email protected]> Signed-off-by: Evan Lezar <[email protected]>
1 parent a9b01a4 commit 7ff2399

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* Fix bug in determining default nvidia-container-runtime.user config value on SUSE-based systems.
1111
* Add `crun` to the list of configured low-level runtimes.
1212
* Add `--cdi.enabled` option to `nvidia-ctk runtime configure` command to enable CDI in containerd.
13+
* Added support for `nvidia-ctk runtime configure --enable-cdi` for the `docker` runtime. Note that this requires Docker >= 25.
1314

1415
* [toolkit-container] Bump CUDA base image version to 12.3.1.
1516
* [libnvidia-container] Added detection of libnvdxgdmal.so.1 on WSL2.

cmd/nvidia-ctk/runtime/configure/configure.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ import (
2020
"fmt"
2121
"path/filepath"
2222

23+
"github.com/urfave/cli/v2"
24+
2325
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
2426
"github.com/NVIDIA/nvidia-container-toolkit/pkg/config/engine"
2527
"github.com/NVIDIA/nvidia-container-toolkit/pkg/config/engine/containerd"
2628
"github.com/NVIDIA/nvidia-container-toolkit/pkg/config/engine/crio"
2729
"github.com/NVIDIA/nvidia-container-toolkit/pkg/config/engine/docker"
2830
"github.com/NVIDIA/nvidia-container-toolkit/pkg/config/ocihook"
29-
"github.com/urfave/cli/v2"
3031
)
3132

3233
const (
@@ -185,7 +186,7 @@ func (m command) validateFlags(c *cli.Context, config *config) error {
185186
}
186187
}
187188

188-
if config.runtime != "containerd" {
189+
if config.runtime != "containerd" && config.runtime != "docker" {
189190
if config.cdi.enabled {
190191
m.logger.Warningf("Ignoring cdi.enabled flag for %v", config.runtime)
191192
}
@@ -244,10 +245,9 @@ func (m command) configureConfigFile(c *cli.Context, config *config) error {
244245
return fmt.Errorf("unable to update config: %v", err)
245246
}
246247

247-
if config.cdi.enabled {
248-
if err := cfg.Set("enable_cdi", true); err != nil {
249-
return fmt.Errorf("failed enable CDI in containerd: %w", err)
250-
}
248+
err = enableCDI(config, cfg)
249+
if err != nil {
250+
return fmt.Errorf("failed to enable CDI in %s: %w", config.runtime, err)
251251
}
252252

253253
outputPath := config.getOuputConfigPath()
@@ -300,3 +300,17 @@ func (m *command) configureOCIHook(c *cli.Context, config *config) error {
300300
}
301301
return nil
302302
}
303+
304+
// enableCDI enables the use of CDI in the corresponding container engine
305+
func enableCDI(config *config, cfg engine.Interface) error {
306+
if !config.cdi.enabled {
307+
return nil
308+
}
309+
switch config.runtime {
310+
case "containerd":
311+
return cfg.Set("enable_cdi", true)
312+
case "docker":
313+
return cfg.Set("experimental", true)
314+
}
315+
return fmt.Errorf("enabling CDI in %s is not supported", config.runtime)
316+
}

pkg/config/engine/docker/docker.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,10 @@ func (c *Config) RemoveRuntime(name string) error {
114114
return nil
115115
}
116116

117-
// Set is not supported for docker configs.
117+
// Set sets the specified docker option
118118
func (c *Config) Set(key string, value interface{}) error {
119-
return fmt.Errorf("Set is not supported for crio configs")
119+
(*c)[key] = value
120+
return nil
120121
}
121122

122123
// Save writes the config to the specified path

0 commit comments

Comments
 (0)