mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2024-11-22 08:18:32 +00:00
Add option to nvidia-ctk to enable CDI in docker
Signed-off-by: Christopher Desiniotis <cdesiniotis@nvidia.com> Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
parent
16a4de1a2b
commit
64fb26b086
@ -6,6 +6,7 @@
|
|||||||
* Include `vulkan/icd.d/nvidia_layers.json` in list of graphics mounts.
|
* Include `vulkan/icd.d/nvidia_layers.json` in list of graphics mounts.
|
||||||
* Add support for `--library-search-paths` to `nvidia-ctk cdi generate` command.
|
* Add support for `--library-search-paths` to `nvidia-ctk cdi generate` command.
|
||||||
* Add support for injecting /dev/nvidia-nvswitch* devices if the NVIDIA_NVSWITCH=enabled envvar is specified.
|
* Add support for injecting /dev/nvidia-nvswitch* devices if the NVIDIA_NVSWITCH=enabled envvar is specified.
|
||||||
|
* Added support for `nvidia-ctk runtime configure --enable-cdi` for the `docker` runtime. Note that this requires Docker >= 25.
|
||||||
|
|
||||||
* [libnvidia-container] Fix device permission check when using cgroupv2 (fixes #227)
|
* [libnvidia-container] Fix device permission check when using cgroupv2 (fixes #227)
|
||||||
|
|
||||||
|
@ -20,13 +20,14 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/urfave/cli/v2"
|
||||||
|
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/pkg/config/engine"
|
"github.com/NVIDIA/nvidia-container-toolkit/pkg/config/engine"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/pkg/config/engine/containerd"
|
"github.com/NVIDIA/nvidia-container-toolkit/pkg/config/engine/containerd"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/pkg/config/engine/crio"
|
"github.com/NVIDIA/nvidia-container-toolkit/pkg/config/engine/crio"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/pkg/config/engine/docker"
|
"github.com/NVIDIA/nvidia-container-toolkit/pkg/config/engine/docker"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/pkg/config/ocihook"
|
"github.com/NVIDIA/nvidia-container-toolkit/pkg/config/ocihook"
|
||||||
"github.com/urfave/cli/v2"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -185,7 +186,7 @@ func (m command) validateFlags(c *cli.Context, config *config) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.runtime != "containerd" {
|
if config.runtime != "containerd" && config.runtime != "docker" {
|
||||||
if config.cdi.enabled {
|
if config.cdi.enabled {
|
||||||
m.logger.Warningf("Ignoring cdi.enabled flag for %v", config.runtime)
|
m.logger.Warningf("Ignoring cdi.enabled flag for %v", config.runtime)
|
||||||
}
|
}
|
||||||
@ -244,10 +245,9 @@ func (m command) configureConfigFile(c *cli.Context, config *config) error {
|
|||||||
return fmt.Errorf("unable to update config: %v", err)
|
return fmt.Errorf("unable to update config: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.cdi.enabled {
|
err = enableCDI(config, cfg)
|
||||||
if err := cfg.Set("enable_cdi", true); err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed enable CDI in containerd: %w", err)
|
return fmt.Errorf("failed to enable CDI in %s: %w", config.runtime, err)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
outputPath := config.getOuputConfigPath()
|
outputPath := config.getOuputConfigPath()
|
||||||
@ -300,3 +300,17 @@ func (m *command) configureOCIHook(c *cli.Context, config *config) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// enableCDI enables the use of CDI in the corresponding container engine
|
||||||
|
func enableCDI(config *config, cfg engine.Interface) error {
|
||||||
|
if !config.cdi.enabled {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
switch config.runtime {
|
||||||
|
case "containerd":
|
||||||
|
return cfg.Set("enable_cdi", true)
|
||||||
|
case "docker":
|
||||||
|
return cfg.Set("experimental", true)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("enabling CDI in %s is not supported", config.runtime)
|
||||||
|
}
|
||||||
|
@ -114,9 +114,10 @@ func (c *Config) RemoveRuntime(name string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set is not supported for docker configs.
|
// Set sets the specified docker option
|
||||||
func (c *Config) Set(key string, value interface{}) error {
|
func (c *Config) Set(key string, value interface{}) error {
|
||||||
return fmt.Errorf("Set is not supported for crio configs")
|
(*c)[key] = value
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save writes the config to the specified path
|
// Save writes the config to the specified path
|
||||||
|
Loading…
Reference in New Issue
Block a user