diff --git a/cmd/nvidia-ctk/runtime/configure/configure.go b/cmd/nvidia-ctk/runtime/configure/configure.go index d2528853..5a7c16a1 100644 --- a/cmd/nvidia-ctk/runtime/configure/configure.go +++ b/cmd/nvidia-ctk/runtime/configure/configure.go @@ -292,9 +292,8 @@ func (m command) configureConfigFile(c *cli.Context, config *config) error { 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) + if config.cdi.enabled { + cfg.EnableCDI() } outputPath := config.getOutputConfigPath() @@ -354,19 +353,3 @@ func (m *command) configureOCIHook(c *cli.Context, config *config) error { } 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 -} diff --git a/pkg/config/engine/api.go b/pkg/config/engine/api.go index 8c7d1b50..9cb10bf7 100644 --- a/pkg/config/engine/api.go +++ b/pkg/config/engine/api.go @@ -20,6 +20,7 @@ package engine type Interface interface { AddRuntime(string, string, bool) error DefaultRuntime() string + EnableCDI() GetRuntimeConfig(string) (RuntimeConfig, error) RemoveRuntime(string) error Save(string) (int64, error) diff --git a/pkg/config/engine/containerd/config.go b/pkg/config/engine/containerd/config.go index 52a336ba..0d7d82e5 100644 --- a/pkg/config/engine/containerd/config.go +++ b/pkg/config/engine/containerd/config.go @@ -111,6 +111,11 @@ func (c Config) DefaultRuntime() string { 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 func (c *Config) RemoveRuntime(name string) error { if c == nil || c.Tree == nil { diff --git a/pkg/config/engine/containerd/config_v1.go b/pkg/config/engine/containerd/config_v1.go index 10b6d087..770b9cb4 100644 --- a/pkg/config/engine/containerd/config_v1.go +++ b/pkg/config/engine/containerd/config_v1.go @@ -165,3 +165,7 @@ func (c *ConfigV1) GetRuntimeConfig(name string) (engine.RuntimeConfig, error) { tree: runtimeData, }, nil } + +func (c *ConfigV1) EnableCDI() { + c.Set("enable_cdi", true) +} diff --git a/pkg/config/engine/crio/crio.go b/pkg/config/engine/crio/crio.go index 3d5629d7..c0cc60be 100644 --- a/pkg/config/engine/crio/crio.go +++ b/pkg/config/engine/crio/crio.go @@ -153,6 +153,9 @@ func (c *Config) GetRuntimeConfig(name string) (engine.RuntimeConfig, error) { }, 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 func CommandLineSource(hostRoot string) toml.Loader { return toml.LoadFirst( diff --git a/pkg/config/engine/docker/docker.go b/pkg/config/engine/docker/docker.go index eda700d0..cfc6cdff 100644 --- a/pkg/config/engine/docker/docker.go +++ b/pkg/config/engine/docker/docker.go @@ -103,6 +103,11 @@ func (c Config) DefaultRuntime() string { 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 func (c *Config) RemoveRuntime(name string) error { if c == nil {