@@ -225,6 +225,17 @@ func (m command) validateFlags(c *cli.Context, config *config) error {
225
225
return fmt .Errorf ("unrecognized Config Source: %v" , config .configSource )
226
226
}
227
227
228
+ if config .configFilePath == "" {
229
+ switch config .runtime {
230
+ case "containerd" :
231
+ config .configFilePath = defaultContainerdConfigFilePath
232
+ case "crio" :
233
+ config .configFilePath = defaultCrioConfigFilePath
234
+ case "docker" :
235
+ config .configFilePath = defaultDockerConfigFilePath
236
+ }
237
+ }
238
+
228
239
return nil
229
240
}
230
241
@@ -241,9 +252,6 @@ func (m command) configureWrapper(c *cli.Context, config *config) error {
241
252
242
253
// configureConfigFile updates the specified container engine config file to enable the NVIDIA runtime.
243
254
func (m command ) configureConfigFile (c * cli.Context , config * config ) error {
244
- configFilePath := config .resolveConfigFilePath ()
245
-
246
- var err error
247
255
configSource , err := config .resolveConfigSource ()
248
256
if err != nil {
249
257
return err
@@ -254,19 +262,19 @@ func (m command) configureConfigFile(c *cli.Context, config *config) error {
254
262
case "containerd" :
255
263
cfg , err = containerd .New (
256
264
containerd .WithLogger (m .logger ),
257
- containerd .WithPath (configFilePath ),
265
+ containerd .WithPath (config . configFilePath ),
258
266
containerd .WithConfigSource (configSource ),
259
267
)
260
268
case "crio" :
261
269
cfg , err = crio .New (
262
270
crio .WithLogger (m .logger ),
263
- crio .WithPath (configFilePath ),
271
+ crio .WithPath (config . configFilePath ),
264
272
crio .WithConfigSource (configSource ),
265
273
)
266
274
case "docker" :
267
275
cfg , err = docker .New (
268
276
docker .WithLogger (m .logger ),
269
- docker .WithPath (configFilePath ),
277
+ docker .WithPath (config . configFilePath ),
270
278
)
271
279
default :
272
280
err = fmt .Errorf ("unrecognized runtime '%v'" , config .runtime )
@@ -307,22 +315,6 @@ func (m command) configureConfigFile(c *cli.Context, config *config) error {
307
315
return nil
308
316
}
309
317
310
- // resolveConfigFilePath returns the default config file path for the configured container engine
311
- func (c * config ) resolveConfigFilePath () string {
312
- if c .configFilePath != "" {
313
- return c .configFilePath
314
- }
315
- switch c .runtime {
316
- case "containerd" :
317
- return defaultContainerdConfigFilePath
318
- case "crio" :
319
- return defaultCrioConfigFilePath
320
- case "docker" :
321
- return defaultDockerConfigFilePath
322
- }
323
- return ""
324
- }
325
-
326
318
// resolveConfigSource returns the default config source or the user provided config source
327
319
func (c * config ) resolveConfigSource () (toml.Loader , error ) {
328
320
switch c .configSource {
@@ -351,7 +343,7 @@ func (c *config) getOutputConfigPath() string {
351
343
if c .dryRun {
352
344
return ""
353
345
}
354
- return c .resolveConfigFilePath ()
346
+ return c .configFilePath
355
347
}
356
348
357
349
// configureOCIHook creates and configures the OCI hook for the NVIDIA runtime
0 commit comments