@@ -44,6 +44,10 @@ const (
4444 defaultContainerdConfigFilePath = "/etc/containerd/config.toml"
4545 defaultCrioConfigFilePath = "/etc/crio/crio.conf"
4646 defaultDockerConfigFilePath = "/etc/docker/daemon.json"
47+
48+ runtimeContainerd = "containerd"
49+ runtimeCrio = "crio"
50+ runtimeDocker = "docker"
4751)
4852
4953type command struct {
@@ -174,14 +178,14 @@ func (m command) validateFlags(c *cli.Context, config *config) error {
174178 config .mode = "config-file"
175179
176180 switch config .runtime {
177- case "containerd" , "crio" , "docker" :
181+ case runtimeContainerd , runtimeCrio , runtimeDocker :
178182 break
179183 default :
180184 return fmt .Errorf ("unrecognized runtime '%v'" , config .runtime )
181185 }
182186
183187 switch config .runtime {
184- case "containerd" , "crio" :
188+ case runtimeContainerd , runtimeCrio :
185189 if config .nvidiaRuntime .path == defaultNVIDIARuntimeExecutable {
186190 config .nvidiaRuntime .path = defaultNVIDIARuntimeExpecutablePath
187191 }
@@ -190,7 +194,7 @@ func (m command) validateFlags(c *cli.Context, config *config) error {
190194 }
191195 }
192196
193- if config .runtime != "containerd" && config .runtime != "docker" {
197+ if config .runtime != runtimeContainerd && config .runtime != runtimeDocker {
194198 if config .cdi .enabled {
195199 m .logger .Warningf ("Ignoring cdi.enabled flag for %v" , config .runtime )
196200 }
@@ -219,23 +223,24 @@ func (m command) configureWrapper(c *cli.Context, config *config) error {
219223// configureConfigFile updates the specified container engine config file to enable the NVIDIA runtime.
220224func (m command ) configureConfigFile (c * cli.Context , config * config ) error {
221225 configFilePath := config .resolveConfigFilePath ()
226+ configCommand := config .resolveConfigCommand ()
222227
223228 var cfg engine.Interface
224229 var err error
225230 switch config .runtime {
226- case "containerd" :
231+ case runtimeContainerd :
227232 cfg , err = containerd .New (
228233 containerd .WithLogger (m .logger ),
229234 containerd .WithPath (configFilePath ),
230- containerd .WithConfigSource (toml .FromFile ( configFilePath )),
235+ containerd .WithConfigSource (toml .FromCommandLine ( configCommand )),
231236 )
232- case "crio" :
237+ case runtimeCrio :
233238 cfg , err = crio .New (
234239 crio .WithLogger (m .logger ),
235240 crio .WithPath (configFilePath ),
236- crio .WithConfigSource (toml .FromFile ( configFilePath )),
241+ crio .WithConfigSource (toml .FromCommandLine ( configCommand )),
237242 )
238- case "docker" :
243+ case runtimeDocker :
239244 cfg , err = docker .New (
240245 docker .WithLogger (m .logger ),
241246 docker .WithPath (configFilePath ),
@@ -285,16 +290,27 @@ func (c *config) resolveConfigFilePath() string {
285290 return c .configFilePath
286291 }
287292 switch c .runtime {
288- case "containerd" :
293+ case runtimeContainerd :
289294 return defaultContainerdConfigFilePath
290- case "crio" :
295+ case runtimeCrio :
291296 return defaultCrioConfigFilePath
292- case "docker" :
297+ case runtimeDocker :
293298 return defaultDockerConfigFilePath
294299 }
295300 return ""
296301}
297302
303+ // resolveConfigCommand returns the default cli command to fetch the current runtime config
304+ func (c * config ) resolveConfigCommand () []string {
305+ switch c .runtime {
306+ case runtimeContainerd :
307+ return []string {"containerd" , "config" , "dump" }
308+ case runtimeCrio :
309+ return []string {"crio" , "status" , "config" }
310+ }
311+ return []string {}
312+ }
313+
298314// getOuputConfigPath returns the configured config path or "" if dry-run is enabled
299315func (c * config ) getOuputConfigPath () string {
300316 if c .dryRun {
@@ -318,9 +334,9 @@ func enableCDI(config *config, cfg engine.Interface) error {
318334 return nil
319335 }
320336 switch config .runtime {
321- case "containerd" :
337+ case runtimeContainerd :
322338 cfg .Set ("enable_cdi" , true )
323- case "docker" :
339+ case runtimeDocker :
324340 cfg .Set ("features" , map [string ]bool {"cdi" : true })
325341 default :
326342 return fmt .Errorf ("enabling CDI in %s is not supported" , config .runtime )
0 commit comments