mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2024-11-25 21:39:10 +00:00
Merge branch 'cherry-pick-enable-cdi' into 'release-1.14'
Add cdi.enabled option to runtime configure See merge request nvidia/container-toolkit/container-toolkit!539
This commit is contained in:
commit
d167812ce3
@ -9,6 +9,8 @@
|
|||||||
* Added detection of libnvdxgdmal.so.1 on WSL2.
|
* Added detection of libnvdxgdmal.so.1 on WSL2.
|
||||||
* Fix bug in determining default nvidia-container-runtime.user config value on SUSE-based systems.
|
* Fix bug in determining default nvidia-container-runtime.user config value on SUSE-based systems.
|
||||||
* Add `crun` to the list of configured low-level runtimes.
|
* Add `crun` to the list of configured low-level runtimes.
|
||||||
|
* Add `--cdi.enabled` option to `nvidia-ctk runtime configure` command to enable CDI in containerd.
|
||||||
|
* Added support for `nvidia-ctk runtime configure --enable-cdi` for the `docker` runtime. Note that this requires Docker >= 25.
|
||||||
|
|
||||||
* [toolkit-container] Bump CUDA base image version to 12.3.1.
|
* [toolkit-container] Bump CUDA base image version to 12.3.1.
|
||||||
* [libnvidia-container] Added detection of libnvdxgdmal.so.1 on WSL2.
|
* [libnvidia-container] Added detection of libnvdxgdmal.so.1 on WSL2.
|
||||||
|
@ -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 (
|
||||||
@ -71,6 +72,11 @@ type config struct {
|
|||||||
hookPath string
|
hookPath string
|
||||||
setAsDefault bool
|
setAsDefault bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// cdi-specific options
|
||||||
|
cdi struct {
|
||||||
|
enabled bool
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m command) build() *cli.Command {
|
func (m command) build() *cli.Command {
|
||||||
@ -141,6 +147,11 @@ func (m command) build() *cli.Command {
|
|||||||
Usage: "set the NVIDIA runtime as the default runtime",
|
Usage: "set the NVIDIA runtime as the default runtime",
|
||||||
Destination: &config.nvidiaRuntime.setAsDefault,
|
Destination: &config.nvidiaRuntime.setAsDefault,
|
||||||
},
|
},
|
||||||
|
&cli.BoolFlag{
|
||||||
|
Name: "cdi.enabled",
|
||||||
|
Usage: "Enable CDI in the configured runtime",
|
||||||
|
Destination: &config.cdi.enabled,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
return &configure
|
return &configure
|
||||||
@ -175,6 +186,13 @@ func (m command) validateFlags(c *cli.Context, config *config) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if config.runtime != "containerd" && config.runtime != "docker" {
|
||||||
|
if config.cdi.enabled {
|
||||||
|
m.logger.Warningf("Ignoring cdi.enabled flag for %v", config.runtime)
|
||||||
|
}
|
||||||
|
config.cdi.enabled = false
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -227,6 +245,11 @@ 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = enableCDI(config, cfg)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to enable CDI in %s: %w", config.runtime, err)
|
||||||
|
}
|
||||||
|
|
||||||
outputPath := config.getOuputConfigPath()
|
outputPath := config.getOuputConfigPath()
|
||||||
n, err := cfg.Save(outputPath)
|
n, err := cfg.Save(outputPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -277,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)
|
||||||
|
}
|
||||||
|
@ -20,6 +20,7 @@ package engine
|
|||||||
type Interface interface {
|
type Interface interface {
|
||||||
DefaultRuntime() string
|
DefaultRuntime() string
|
||||||
AddRuntime(string, string, bool) error
|
AddRuntime(string, string, bool) error
|
||||||
|
Set(string, interface{}) error
|
||||||
RemoveRuntime(string) error
|
RemoveRuntime(string) error
|
||||||
Save(string) (int64, error)
|
Save(string) (int64, error)
|
||||||
}
|
}
|
||||||
|
@ -134,6 +134,14 @@ func (c *ConfigV1) RemoveRuntime(name string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetOption sets the specified containerd option.
|
||||||
|
func (c *ConfigV1) Set(key string, value interface{}) error {
|
||||||
|
config := *c.Tree
|
||||||
|
config.SetPath([]string{"plugins", "cri", "containerd", key}, value)
|
||||||
|
*c.Tree = config
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Save wrotes the config to a file
|
// Save wrotes the config to a file
|
||||||
func (c ConfigV1) Save(path string) (int64, error) {
|
func (c ConfigV1) Save(path string) (int64, error) {
|
||||||
return (Config)(c).Save(path)
|
return (Config)(c).Save(path)
|
||||||
|
@ -90,6 +90,14 @@ func (c *Config) getRuntimeAnnotations(path []string) ([]string, error) {
|
|||||||
return annotations, nil
|
return annotations, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set sets the specified containerd option.
|
||||||
|
func (c *Config) Set(key string, value interface{}) error {
|
||||||
|
config := *c.Tree
|
||||||
|
config.SetPath([]string{"plugins", "io.containerd.grpc.v1.cri", key}, value)
|
||||||
|
*c.Tree = config
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// DefaultRuntime returns the default runtime for the cri-o config
|
// DefaultRuntime returns the default runtime for the cri-o config
|
||||||
func (c Config) DefaultRuntime() string {
|
func (c Config) DefaultRuntime() string {
|
||||||
if runtime, ok := c.GetPath([]string{"plugins", "io.containerd.grpc.v1.cri", "containerd", "default_runtime_name"}).(string); ok {
|
if runtime, ok := c.GetPath([]string{"plugins", "io.containerd.grpc.v1.cri", "containerd", "default_runtime_name"}).(string); ok {
|
||||||
|
@ -99,6 +99,11 @@ func (c *Config) RemoveRuntime(name string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set is not supported for cri-o configs.
|
||||||
|
func (c *Config) Set(key string, value interface{}) error {
|
||||||
|
return fmt.Errorf("Set is not supported for crio configs")
|
||||||
|
}
|
||||||
|
|
||||||
// Save writes the config to the specified path
|
// Save writes the config to the specified path
|
||||||
func (c Config) Save(path string) (int64, error) {
|
func (c Config) Save(path string) (int64, error) {
|
||||||
config := (toml.Tree)(c)
|
config := (toml.Tree)(c)
|
||||||
|
@ -114,6 +114,12 @@ func (c *Config) RemoveRuntime(name string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set sets the specified docker option
|
||||||
|
func (c *Config) Set(key string, value interface{}) error {
|
||||||
|
(*c)[key] = value
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Save writes the config to the specified path
|
// Save writes the config to the specified path
|
||||||
func (c Config) Save(path string) (int64, error) {
|
func (c Config) Save(path string) (int64, error) {
|
||||||
output, err := json.MarshalIndent(c, "", " ")
|
output, err := json.MarshalIndent(c, "", " ")
|
||||||
|
Loading…
Reference in New Issue
Block a user