@@ -19,13 +19,11 @@ package containerd
1919import (
2020 "fmt"
2121
22- "github.com/pelletier/go-toml"
23-
24- "github.com/NVIDIA/nvidia-container-toolkit/pkg/config/engine"
22+ "github.com/NVIDIA/nvidia-container-toolkit/pkg/config/toml"
2523)
2624
2725// AddRuntime adds a runtime to the containerd config
28- func (c * Config ) AddRuntime (name string , path string , setAsDefault bool , configOverrides ... map [ string ] interface {} ) error {
26+ func (c * Config ) AddRuntime (name string , path string , setAsDefault bool ) error {
2927 if c == nil || c .Tree == nil {
3028 return fmt .Errorf ("config is nil" )
3129 }
@@ -39,12 +37,13 @@ func (c *Config) AddRuntime(name string, path string, setAsDefault bool, configO
3937 runtimeNamesForConfig = append (runtimeNamesForConfig , name )
4038 }
4139 for _ , r := range runtimeNamesForConfig {
42- if options , ok := config .GetPath ([]string {"plugins" , "io.containerd.grpc.v1.cri" , "containerd" , "runtimes" , r }).(* toml.Tree ); ok {
43- c .Logger .Debugf ("using options from runtime %v: %v" , r , options .String ())
44- options , _ = toml .Load (options .String ())
45- config .SetPath ([]string {"plugins" , "io.containerd.grpc.v1.cri" , "containerd" , "runtimes" , name }, options )
46- break
40+ options := config .GetSubtreeByPath ([]string {"plugins" , "io.containerd.grpc.v1.cri" , "containerd" , "runtimes" , r })
41+ if options == nil {
42+ continue
4743 }
44+ c .Logger .Debugf ("using options from runtime %v: %v" , r , options )
45+ config .SetPath ([]string {"plugins" , "io.containerd.grpc.v1.cri" , "containerd" , "runtimes" , name }, options .Copy ())
46+ break
4847 }
4948
5049 if config .GetPath ([]string {"plugins" , "io.containerd.grpc.v1.cri" , "containerd" , "runtimes" , name }) == nil {
@@ -70,11 +69,6 @@ func (c *Config) AddRuntime(name string, path string, setAsDefault bool, configO
7069 config .SetPath ([]string {"plugins" , "io.containerd.grpc.v1.cri" , "containerd" , "default_runtime_name" }, name )
7170 }
7271
73- runtimeSubtree := subtreeAtPath (config , "plugins" , "io.containerd.grpc.v1.cri" , "containerd" , "runtimes" , name )
74- if err := runtimeSubtree .applyOverrides (configOverrides ... ); err != nil {
75- return fmt .Errorf ("failed to apply config overrides: %w" , err )
76- }
77-
7872 * c .Tree = config
7973 return nil
8074}
@@ -151,15 +145,3 @@ func (c *Config) RemoveRuntime(name string) error {
151145 * c .Tree = config
152146 return nil
153147}
154-
155- // Save writes the config to the specified path
156- func (c Config ) Save (path string ) (int64 , error ) {
157- config := c .Tree
158- output , err := config .Marshal ()
159- if err != nil {
160- return 0 , fmt .Errorf ("unable to convert to TOML: %v" , err )
161- }
162-
163- n , err := engine .Config (path ).Write (output )
164- return int64 (n ), err
165- }
0 commit comments