@@ -25,6 +25,7 @@ import (
2525
2626 "github.com/NVIDIA/nvidia-container-toolkit/pkg/config/engine"
2727 "github.com/NVIDIA/nvidia-container-toolkit/pkg/config/engine/containerd"
28+ "github.com/NVIDIA/nvidia-container-toolkit/pkg/config/toml"
2829 "github.com/NVIDIA/nvidia-container-toolkit/tools/container"
2930)
3031
@@ -84,13 +85,7 @@ func Flags(opts *Options) []cli.Flag {
8485func Setup (c * cli.Context , o * container.Options , co * Options ) error {
8586 log .Infof ("Starting 'setup' for %v" , c .App .Name )
8687
87- cfg , err := containerd .New (
88- containerd .WithPath (o .Config ),
89- containerd .WithConfigSource (containerd .CommandLineSource (o .HostRootMount )),
90- containerd .WithRuntimeType (co .runtimeType ),
91- containerd .WithUseLegacyConfig (co .useLegacyConfig ),
92- containerd .WithContainerAnnotations (co .containerAnnotationsFromCDIPrefixes ()... ),
93- )
88+ cfg , err := getRuntimeConfig (o , co )
9489 if err != nil {
9590 return fmt .Errorf ("unable to load config: %v" , err )
9691 }
@@ -114,13 +109,7 @@ func Setup(c *cli.Context, o *container.Options, co *Options) error {
114109func Cleanup (c * cli.Context , o * container.Options , co * Options ) error {
115110 log .Infof ("Starting 'cleanup' for %v" , c .App .Name )
116111
117- cfg , err := containerd .New (
118- containerd .WithPath (o .Config ),
119- containerd .WithConfigSource (containerd .CommandLineSource (o .HostRootMount )),
120- containerd .WithRuntimeType (co .runtimeType ),
121- containerd .WithUseLegacyConfig (co .useLegacyConfig ),
122- containerd .WithContainerAnnotations (co .containerAnnotationsFromCDIPrefixes ()... ),
123- )
112+ cfg , err := getRuntimeConfig (o , co )
124113 if err != nil {
125114 return fmt .Errorf ("unable to load config: %v" , err )
126115 }
@@ -169,13 +158,24 @@ func (o *Options) runtimeConfigOverride() (map[string]interface{}, error) {
169158}
170159
171160func GetLowlevelRuntimePaths (o * container.Options , co * Options ) ([]string , error ) {
172- cfg , err := containerd .New (
173- containerd .WithConfigSource (containerd .CommandLineSource (o .HostRootMount )),
174- containerd .WithRuntimeType (co .runtimeType ),
175- containerd .WithUseLegacyConfig (co .useLegacyConfig ),
176- )
161+ cfg , err := getRuntimeConfig (o , co )
177162 if err != nil {
178163 return nil , fmt .Errorf ("unable to load containerd config: %w" , err )
179164 }
180165 return engine .GetBinaryPathsForRuntimes (cfg ), nil
181166}
167+
168+ func getRuntimeConfig (o * container.Options , co * Options ) (engine.Interface , error ) {
169+ return containerd .New (
170+ containerd .WithPath (o .Config ),
171+ containerd .WithConfigSource (
172+ toml .LoadFirst (
173+ containerd .CommandLineSource (o .HostRootMount ),
174+ toml .FromFile (o .Config ),
175+ ),
176+ ),
177+ containerd .WithRuntimeType (co .runtimeType ),
178+ containerd .WithUseLegacyConfig (co .useLegacyConfig ),
179+ containerd .WithContainerAnnotations (co .containerAnnotationsFromCDIPrefixes ()... ),
180+ )
181+ }
0 commit comments