mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2025-02-04 03:56:23 +00:00
Add EnableCDI() method to engine.Interface
This change adds an EnableCDI method to the container engine config files and Updates the 'nvidia-ctk runtime configure' command to use this new method. Signed-off-by: Christopher Desiniotis <cdesiniotis@nvidia.com>
This commit is contained in:
parent
89f33bdf71
commit
df73db7e1e
@ -292,9 +292,8 @@ 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 config.cdi.enabled {
|
||||||
if err != nil {
|
cfg.EnableCDI()
|
||||||
return fmt.Errorf("failed to enable CDI in %s: %w", config.runtime, err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
outputPath := config.getOutputConfigPath()
|
outputPath := config.getOutputConfigPath()
|
||||||
@ -354,19 +353,3 @@ 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":
|
|
||||||
cfg.Set("enable_cdi", true)
|
|
||||||
case "docker":
|
|
||||||
cfg.Set("features", map[string]bool{"cdi": true})
|
|
||||||
default:
|
|
||||||
return fmt.Errorf("enabling CDI in %s is not supported", config.runtime)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
@ -20,6 +20,7 @@ package engine
|
|||||||
type Interface interface {
|
type Interface interface {
|
||||||
AddRuntime(string, string, bool) error
|
AddRuntime(string, string, bool) error
|
||||||
DefaultRuntime() string
|
DefaultRuntime() string
|
||||||
|
EnableCDI()
|
||||||
GetRuntimeConfig(string) (RuntimeConfig, error)
|
GetRuntimeConfig(string) (RuntimeConfig, error)
|
||||||
RemoveRuntime(string) error
|
RemoveRuntime(string) error
|
||||||
Save(string) (int64, error)
|
Save(string) (int64, error)
|
||||||
|
@ -111,6 +111,11 @@ func (c Config) DefaultRuntime() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EnableCDI sets the enable_cdi field in the Containerd config to true.
|
||||||
|
func (c *Config) EnableCDI() {
|
||||||
|
c.Set("enable_cdi", true)
|
||||||
|
}
|
||||||
|
|
||||||
// RemoveRuntime removes a runtime from the docker config
|
// RemoveRuntime removes a runtime from the docker config
|
||||||
func (c *Config) RemoveRuntime(name string) error {
|
func (c *Config) RemoveRuntime(name string) error {
|
||||||
if c == nil || c.Tree == nil {
|
if c == nil || c.Tree == nil {
|
||||||
|
@ -165,3 +165,7 @@ func (c *ConfigV1) GetRuntimeConfig(name string) (engine.RuntimeConfig, error) {
|
|||||||
tree: runtimeData,
|
tree: runtimeData,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *ConfigV1) EnableCDI() {
|
||||||
|
c.Set("enable_cdi", true)
|
||||||
|
}
|
||||||
|
@ -153,6 +153,9 @@ func (c *Config) GetRuntimeConfig(name string) (engine.RuntimeConfig, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EnableCDI is a no-op for CRI-O since it always enabled where supported.
|
||||||
|
func (c *Config) EnableCDI() {}
|
||||||
|
|
||||||
// CommandLineSource returns the CLI-based crio config loader
|
// CommandLineSource returns the CLI-based crio config loader
|
||||||
func CommandLineSource(hostRoot string) toml.Loader {
|
func CommandLineSource(hostRoot string) toml.Loader {
|
||||||
return toml.LoadFirst(
|
return toml.LoadFirst(
|
||||||
|
@ -103,6 +103,11 @@ func (c Config) DefaultRuntime() string {
|
|||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EnableCDI sets features.cdi to true in the docker config.
|
||||||
|
func (c *Config) EnableCDI() {
|
||||||
|
c.Set("features", map[string]bool{"cdi": true})
|
||||||
|
}
|
||||||
|
|
||||||
// RemoveRuntime removes a runtime from the docker config
|
// RemoveRuntime removes a runtime from the docker config
|
||||||
func (c *Config) RemoveRuntime(name string) error {
|
func (c *Config) RemoveRuntime(name string) error {
|
||||||
if c == nil {
|
if c == nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user