Skip to content

Commit 11e4af3

Browse files
authored
Merge pull request #784 from elezar/fix-config-file-path
Fix bug in default config file path
2 parents b03e942 + edf5d97 commit 11e4af3

File tree

1 file changed

+15
-23
lines changed

1 file changed

+15
-23
lines changed

cmd/nvidia-ctk/runtime/configure/configure.go

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,17 @@ func (m command) validateFlags(c *cli.Context, config *config) error {
225225
return fmt.Errorf("unrecognized Config Source: %v", config.configSource)
226226
}
227227

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+
228239
return nil
229240
}
230241

@@ -241,9 +252,6 @@ func (m command) configureWrapper(c *cli.Context, config *config) error {
241252

242253
// configureConfigFile updates the specified container engine config file to enable the NVIDIA runtime.
243254
func (m command) configureConfigFile(c *cli.Context, config *config) error {
244-
configFilePath := config.resolveConfigFilePath()
245-
246-
var err error
247255
configSource, err := config.resolveConfigSource()
248256
if err != nil {
249257
return err
@@ -254,19 +262,19 @@ func (m command) configureConfigFile(c *cli.Context, config *config) error {
254262
case "containerd":
255263
cfg, err = containerd.New(
256264
containerd.WithLogger(m.logger),
257-
containerd.WithPath(configFilePath),
265+
containerd.WithPath(config.configFilePath),
258266
containerd.WithConfigSource(configSource),
259267
)
260268
case "crio":
261269
cfg, err = crio.New(
262270
crio.WithLogger(m.logger),
263-
crio.WithPath(configFilePath),
271+
crio.WithPath(config.configFilePath),
264272
crio.WithConfigSource(configSource),
265273
)
266274
case "docker":
267275
cfg, err = docker.New(
268276
docker.WithLogger(m.logger),
269-
docker.WithPath(configFilePath),
277+
docker.WithPath(config.configFilePath),
270278
)
271279
default:
272280
err = fmt.Errorf("unrecognized runtime '%v'", config.runtime)
@@ -307,22 +315,6 @@ func (m command) configureConfigFile(c *cli.Context, config *config) error {
307315
return nil
308316
}
309317

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-
326318
// resolveConfigSource returns the default config source or the user provided config source
327319
func (c *config) resolveConfigSource() (toml.Loader, error) {
328320
switch c.configSource {
@@ -351,7 +343,7 @@ func (c *config) getOutputConfigPath() string {
351343
if c.dryRun {
352344
return ""
353345
}
354-
return c.resolveConfigFilePath()
346+
return c.configFilePath
355347
}
356348

357349
// configureOCIHook creates and configures the OCI hook for the NVIDIA runtime

0 commit comments

Comments
 (0)