mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2024-11-25 05:21:33 +00:00
Add cdi.enabled option to runtime configure
Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
parent
b8b134f389
commit
61595aa0fa
@ -71,6 +71,11 @@ type config struct {
|
||||
hookPath string
|
||||
setAsDefault bool
|
||||
}
|
||||
|
||||
// cdi-specific options
|
||||
cdi struct {
|
||||
enabled bool
|
||||
}
|
||||
}
|
||||
|
||||
func (m command) build() *cli.Command {
|
||||
@ -141,6 +146,11 @@ func (m command) build() *cli.Command {
|
||||
Usage: "set the NVIDIA runtime as the default runtime",
|
||||
Destination: &config.nvidiaRuntime.setAsDefault,
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "cdi.enabled",
|
||||
Usage: "Enable CDI in the configured runtime",
|
||||
Destination: &config.cdi.enabled,
|
||||
},
|
||||
}
|
||||
|
||||
return &configure
|
||||
@ -175,6 +185,13 @@ func (m command) validateFlags(c *cli.Context, config *config) error {
|
||||
}
|
||||
}
|
||||
|
||||
if config.runtime != "containerd" {
|
||||
if config.cdi.enabled {
|
||||
m.logger.Warningf("Ignoring cdi.enabled flag for %v", config.runtime)
|
||||
}
|
||||
config.cdi.enabled = false
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -227,6 +244,12 @@ func (m command) configureConfigFile(c *cli.Context, config *config) error {
|
||||
return fmt.Errorf("unable to update config: %v", err)
|
||||
}
|
||||
|
||||
if config.cdi.enabled {
|
||||
if err := cfg.Set("enable_cdi", true); err != nil {
|
||||
return fmt.Errorf("failed enable CDI in containerd: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
outputPath := config.getOuputConfigPath()
|
||||
n, err := cfg.Save(outputPath)
|
||||
if err != nil {
|
||||
|
@ -20,6 +20,7 @@ package engine
|
||||
type Interface interface {
|
||||
DefaultRuntime() string
|
||||
AddRuntime(string, string, bool) error
|
||||
Set(string, interface{}) error
|
||||
RemoveRuntime(string) error
|
||||
Save(string) (int64, error)
|
||||
}
|
||||
|
@ -133,6 +133,14 @@ func (c *ConfigV1) RemoveRuntime(name string) error {
|
||||
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
|
||||
func (c ConfigV1) Save(path string) (int64, error) {
|
||||
return (Config)(c).Save(path)
|
||||
|
@ -89,6 +89,14 @@ func (c *Config) getRuntimeAnnotations(path []string) ([]string, error) {
|
||||
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
|
||||
func (c Config) DefaultRuntime() string {
|
||||
if runtime, ok := c.GetPath([]string{"plugins", "io.containerd.grpc.v1.cri", "containerd", "default_runtime_name"}).(string); ok {
|
||||
|
@ -98,6 +98,11 @@ func (c *Config) RemoveRuntime(name string) error {
|
||||
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
|
||||
func (c Config) Save(path string) (int64, error) {
|
||||
config := (toml.Tree)(c)
|
||||
|
@ -114,6 +114,11 @@ func (c *Config) RemoveRuntime(name string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Set is not supported for docker 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
|
||||
func (c Config) Save(path string) (int64, error) {
|
||||
output, err := json.MarshalIndent(c, "", " ")
|
||||
|
Loading…
Reference in New Issue
Block a user