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

Signed-off-by: Christopher Desiniotis <cdesiniotis@nvidia.com>
This commit is contained in:
Christopher Desiniotis 2023-12-01 15:59:34 -08:00
parent ffe7ed313a
commit 83ad09b179
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 { switch config.runtime {
case "containerd": case "containerd":
return cfg.Set("enable_cdi", true) cfg.Set("enable_cdi", true)
case "docker": 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 { type Interface interface {
DefaultRuntime() string DefaultRuntime() string
AddRuntime(string, string, bool) error AddRuntime(string, string, bool) error
Set(string, interface{}) error Set(string, interface{})
RemoveRuntime(string) error RemoveRuntime(string) error
Save(string) (int64, error) Save(string) (int64, error)
} }

View File

@ -135,11 +135,10 @@ func (c *ConfigV1) RemoveRuntime(name string) error {
} }
// SetOption sets the specified containerd option. // 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 := *c.Tree
config.SetPath([]string{"plugins", "cri", "containerd", key}, value) config.SetPath([]string{"plugins", "cri", "containerd", key}, value)
*c.Tree = config *c.Tree = config
return nil
} }
// Save wrotes the config to a file // 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. // 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 := *c.Tree
config.SetPath([]string{"plugins", "io.containerd.grpc.v1.cri", key}, value) config.SetPath([]string{"plugins", "io.containerd.grpc.v1.cri", key}, value)
*c.Tree = config *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

View File

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

View File

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

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