Merge branch 'CNT-4764/cleanup-engine-interface' into 'main'

Refactor the engine.Interface such that the Set() API does not return an extraneous error

See merge request nvidia/container-toolkit/container-toolkit!515
This commit is contained in:
Christopher Desiniotis 2023-12-04 23:05:30 +00:00
commit 527248ef5b
7 changed files with 16 additions and 13 deletions

View File

@ -308,9 +308,11 @@ func enableCDI(config *config, cfg engine.Interface) error {
}
switch config.runtime {
case "containerd":
return cfg.Set("enable_cdi", true)
cfg.Set("enable_cdi", true)
case "docker":
return cfg.Set("experimental", true)
cfg.Set("experimental", true)
default:
return fmt.Errorf("enabling CDI in %s is not supported", config.runtime)
}
return fmt.Errorf("enabling CDI in %s is not supported", config.runtime)
return nil
}

View File

@ -20,7 +20,7 @@ package engine
type Interface interface {
DefaultRuntime() string
AddRuntime(string, string, bool) error
Set(string, interface{}) error
Set(string, interface{})
RemoveRuntime(string) error
Save(string) (int64, error)
}

View File

@ -135,11 +135,10 @@ func (c *ConfigV1) RemoveRuntime(name string) error {
}
// SetOption sets the specified containerd option.
func (c *ConfigV1) Set(key string, value interface{}) error {
func (c *ConfigV1) Set(key string, value interface{}) {
config := *c.Tree
config.SetPath([]string{"plugins", "cri", "containerd", key}, value)
*c.Tree = config
return nil
}
// Save wrotes the config to a file

View File

@ -91,11 +91,10 @@ func (c *Config) getRuntimeAnnotations(path []string) ([]string, error) {
}
// Set sets the specified containerd option.
func (c *Config) Set(key string, value interface{}) error {
func (c *Config) Set(key string, value interface{}) {
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

View File

@ -31,6 +31,8 @@ type Config struct {
ContainerAnnotations []string
}
var _ engine.Interface = (*Config)(nil)
// New creates a containerd config with the specified options
func New(opts ...Option) (engine.Interface, error) {
b := &builder{}

View File

@ -27,6 +27,8 @@ import (
// Config represents the cri-o config
type Config toml.Tree
var _ engine.Interface = (*Config)(nil)
// New creates a cri-o config with the specified options
func New(opts ...Option) (engine.Interface, error) {
b := &builder{}
@ -100,9 +102,7 @@ func (c *Config) RemoveRuntime(name string) error {
}
// 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")
}
func (c *Config) Set(key string, value interface{}) {}
// Save writes the config to the specified path
func (c Config) Save(path string) (int64, error) {

View File

@ -32,6 +32,8 @@ const (
// TODO: This should not be public, but we need to access it from the tests in tools/container/docker
type Config map[string]interface{}
var _ engine.Interface = (*Config)(nil)
// New creates a docker config with the specified options
func New(opts ...Option) (engine.Interface, error) {
b := &builder{}
@ -115,9 +117,8 @@ func (c *Config) RemoveRuntime(name string) error {
}
// Set sets the specified docker option
func (c *Config) Set(key string, value interface{}) error {
func (c *Config) Set(key string, value interface{}) {
(*c)[key] = value
return nil
}
// Save writes the config to the specified path