From f625242ed679dc743c724b21ecfa56e552a99ea8 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Mon, 27 Jan 2025 15:38:55 +0100 Subject: [PATCH] Remove Set from engine config API Signed-off-by: Evan Lezar --- pkg/config/engine/api.go | 1 - pkg/config/engine/containerd/config.go | 11 +++-------- pkg/config/engine/containerd/config_v1.go | 11 +++-------- pkg/config/engine/docker/docker.go | 7 +------ 4 files changed, 7 insertions(+), 23 deletions(-) diff --git a/pkg/config/engine/api.go b/pkg/config/engine/api.go index 9cb10bf7..d27f09e9 100644 --- a/pkg/config/engine/api.go +++ b/pkg/config/engine/api.go @@ -24,7 +24,6 @@ type Interface interface { GetRuntimeConfig(string) (RuntimeConfig, error) RemoveRuntime(string) error Save(string) (int64, error) - Set(string, interface{}) String() string } diff --git a/pkg/config/engine/containerd/config.go b/pkg/config/engine/containerd/config.go index 0d7d82e5..62468fe5 100644 --- a/pkg/config/engine/containerd/config.go +++ b/pkg/config/engine/containerd/config.go @@ -96,13 +96,6 @@ 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{}) { - config := *c.Tree - config.SetPath([]string{"plugins", c.CRIRuntimePluginName, key}, value) - *c.Tree = config -} - // DefaultRuntime returns the default runtime for the cri-o config func (c Config) DefaultRuntime() string { if runtime, ok := c.GetPath([]string{"plugins", c.CRIRuntimePluginName, "containerd", "default_runtime_name"}).(string); ok { @@ -113,7 +106,9 @@ func (c Config) DefaultRuntime() string { // EnableCDI sets the enable_cdi field in the Containerd config to true. func (c *Config) EnableCDI() { - c.Set("enable_cdi", true) + config := *c.Tree + config.SetPath([]string{"plugins", c.CRIRuntimePluginName, "enable_cdi"}, true) + *c.Tree = config } // RemoveRuntime removes a runtime from the docker config diff --git a/pkg/config/engine/containerd/config_v1.go b/pkg/config/engine/containerd/config_v1.go index 770b9cb4..2189a8de 100644 --- a/pkg/config/engine/containerd/config_v1.go +++ b/pkg/config/engine/containerd/config_v1.go @@ -143,13 +143,6 @@ func (c *ConfigV1) RemoveRuntime(name string) error { return nil } -// Set sets the specified containerd option. -func (c *ConfigV1) Set(key string, value interface{}) { - config := *c.Tree - config.SetPath([]string{"plugins", "cri", "containerd", key}, value) - *c.Tree = config -} - // Save writes the config to a file func (c ConfigV1) Save(path string) (int64, error) { return (Config)(c).Save(path) @@ -167,5 +160,7 @@ func (c *ConfigV1) GetRuntimeConfig(name string) (engine.RuntimeConfig, error) { } func (c *ConfigV1) EnableCDI() { - c.Set("enable_cdi", true) + config := *c.Tree + config.SetPath([]string{"plugins", "cri", "containerd", "enable_cdi"}, true) + *c.Tree = config } diff --git a/pkg/config/engine/docker/docker.go b/pkg/config/engine/docker/docker.go index cfc6cdff..83d68615 100644 --- a/pkg/config/engine/docker/docker.go +++ b/pkg/config/engine/docker/docker.go @@ -105,7 +105,7 @@ func (c Config) DefaultRuntime() string { // EnableCDI sets features.cdi to true in the docker config. func (c *Config) EnableCDI() { - c.Set("features", map[string]bool{"cdi": true}) + (*c)["features"] = map[string]bool{"cdi": true} } // RemoveRuntime removes a runtime from the docker config @@ -137,11 +137,6 @@ func (c *Config) RemoveRuntime(name string) error { return nil } -// Set sets the specified docker option -func (c *Config) Set(key string, value interface{}) { - (*c)[key] = value -} - // Save writes the config to the specified path func (c Config) Save(path string) (int64, error) { output, err := json.MarshalIndent(c, "", " ")