@@ -33,59 +33,36 @@ func (c *ConfigV1) AddRuntime(name string, path string, setAsDefault bool) error
3333 if c == nil || c .Tree == nil {
3434 return fmt .Errorf ("config is nil" )
3535 }
36+ defaultRuntimeOptions := c .GetDefaultRuntimeOptions ()
37+ return c .AddRuntimeWithOptions (name , path , setAsDefault , defaultRuntimeOptions )
38+ }
3639
37- config := * c .Tree
38-
39- config .Set ("version" , int64 (1 ))
40-
41- runtimeNamesForConfig := engine .GetLowLevelRuntimes (c )
42- for _ , r := range runtimeNamesForConfig {
43- options := config .GetSubtreeByPath ([]string {"plugins" , "cri" , "containerd" , "runtimes" , r })
44- if options == nil {
45- continue
46- }
47- c .Logger .Debugf ("using options from runtime %v: %v" , r , options )
48- config .SetPath ([]string {"plugins" , "cri" , "containerd" , "runtimes" , name }, options .Copy ())
49- break
50-
51- }
52-
53- if config .GetPath ([]string {"plugins" , "cri" , "containerd" , "runtimes" , name }) == nil {
54- c .Logger .Warningf ("could not infer options from runtimes %v; using defaults" , runtimeNamesForConfig )
55- config .SetPath ([]string {"plugins" , "cri" , "containerd" , "runtimes" , name , "runtime_type" }, c .RuntimeType )
56- config .SetPath ([]string {"plugins" , "cri" , "containerd" , "runtimes" , name , "runtime_root" }, "" )
57- config .SetPath ([]string {"plugins" , "cri" , "containerd" , "runtimes" , name , "runtime_engine" }, "" )
58- config .SetPath ([]string {"plugins" , "cri" , "containerd" , "runtimes" , name , "privileged_without_host_devices" }, false )
59- }
40+ func (c * ConfigV1 ) GetDefaultRuntimeOptions () interface {} {
41+ return (* Config )(c ).GetDefaultRuntimeOptions ()
42+ }
6043
61- if len (c .ContainerAnnotations ) > 0 {
62- annotations , err := (* Config )(c ).getRuntimeAnnotations ([]string {"plugins" , "cri" , "containerd" , "runtimes" , name , "container_annotations" })
63- if err != nil {
64- return err
65- }
66- annotations = append (c .ContainerAnnotations , annotations ... )
67- config .SetPath ([]string {"plugins" , "cri" , "containerd" , "runtimes" , name , "container_annotations" }, annotations )
44+ func (c * ConfigV1 ) AddRuntimeWithOptions (name string , path string , setAsDefault bool , options interface {}) error {
45+ if err := (* Config )(c ).AddRuntimeWithOptions (name , path , setAsDefault && ! c .UseLegacyConfig , options ); err != nil {
46+ return err
6847 }
69-
70- config .SetPath ([]string {"plugins" , "cri" , "containerd" , "runtimes" , name , "options" , "BinaryName" }, path )
48+ config := * c .Tree
7149 config .SetPath ([]string {"plugins" , "cri" , "containerd" , "runtimes" , name , "options" , "Runtime" }, path )
50+ * c .Tree = config
7251
73- if setAsDefault {
74- if ! c .UseLegacyConfig {
75- config .SetPath ([]string {"plugins" , "cri" , "containerd" , "default_runtime_name" }, name )
76- } else {
77- // Note: This is deprecated in containerd 1.4.0 and will be removed in 1.5.0
78- if config .GetPath ([]string {"plugins" , "cri" , "containerd" , "default_runtime" }) == nil {
79- config .SetPath ([]string {"plugins" , "cri" , "containerd" , "default_runtime" , "runtime_type" }, c .RuntimeType )
80- config .SetPath ([]string {"plugins" , "cri" , "containerd" , "default_runtime" , "runtime_root" }, "" )
81- config .SetPath ([]string {"plugins" , "cri" , "containerd" , "default_runtime" , "runtime_engine" }, "" )
82- config .SetPath ([]string {"plugins" , "cri" , "containerd" , "default_runtime" , "privileged_without_host_devices" }, false )
83- }
84- config .SetPath ([]string {"plugins" , "cri" , "containerd" , "default_runtime" , "options" , "BinaryName" }, path )
85- config .SetPath ([]string {"plugins" , "cri" , "containerd" , "default_runtime" , "options" , "Runtime" }, path )
86- }
52+ if ! c .UseLegacyConfig || ! setAsDefault {
53+ return nil
8754 }
8855
56+ config = * c .Tree
57+ // Note: This is deprecated in containerd 1.4.0 and will be removed in 1.5.0
58+ if config .GetPath ([]string {"plugins" , "cri" , "containerd" , "default_runtime" }) == nil {
59+ config .SetPath ([]string {"plugins" , "cri" , "containerd" , "default_runtime" , "runtime_type" }, c .RuntimeType )
60+ config .SetPath ([]string {"plugins" , "cri" , "containerd" , "default_runtime" , "runtime_root" }, "" )
61+ config .SetPath ([]string {"plugins" , "cri" , "containerd" , "default_runtime" , "runtime_engine" }, "" )
62+ config .SetPath ([]string {"plugins" , "cri" , "containerd" , "default_runtime" , "privileged_without_host_devices" }, false )
63+ }
64+ config .SetPath ([]string {"plugins" , "cri" , "containerd" , "default_runtime" , "options" , "BinaryName" }, path )
65+ config .SetPath ([]string {"plugins" , "cri" , "containerd" , "default_runtime" , "options" , "Runtime" }, path )
8966 * c .Tree = config
9067 return nil
9168}
0 commit comments