Merge pull request #783 from elezar/fix-config-file-path
Some checks failed
CodeQL / Analyze Go code with CodeQL (push) Has been cancelled
Golang / check (push) Has been cancelled
Golang / Unit test (push) Has been cancelled
Golang / Build (push) Has been cancelled
image / packages (${{github.event_name == 'pull_request'}}, centos7-aarch64) (push) Has been cancelled
image / packages (${{github.event_name == 'pull_request'}}, centos7-x86_64) (push) Has been cancelled
image / packages (${{github.event_name == 'pull_request'}}, centos8-ppc64le) (push) Has been cancelled
image / packages (${{github.event_name == 'pull_request'}}, ubuntu18.04-amd64) (push) Has been cancelled
image / packages (${{github.event_name == 'pull_request'}}, ubuntu18.04-arm64) (push) Has been cancelled
image / packages (${{github.event_name == 'pull_request'}}, ubuntu18.04-ppc64le) (push) Has been cancelled
image / image (packaging, ${{github.event_name == 'pull_request'}}) (push) Has been cancelled
image / image (ubi8, ${{github.event_name == 'pull_request'}}) (push) Has been cancelled
image / image (ubuntu20.04, ${{github.event_name == 'pull_request'}}) (push) Has been cancelled

Fix bug in default config file path
This commit is contained in:
Evan Lezar 2024-11-08 15:57:42 -08:00 committed by GitHub
commit 1995925a7d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -225,6 +225,17 @@ func (m command) validateFlags(c *cli.Context, config *config) error {
return fmt.Errorf("unrecognized Config Source: %v", config.configSource) return fmt.Errorf("unrecognized Config Source: %v", config.configSource)
} }
if config.configFilePath == "" {
switch config.runtime {
case "containerd":
config.configFilePath = defaultContainerdConfigFilePath
case "crio":
config.configFilePath = defaultCrioConfigFilePath
case "docker":
config.configFilePath = defaultDockerConfigFilePath
}
}
return nil return nil
} }
@ -241,9 +252,6 @@ func (m command) configureWrapper(c *cli.Context, config *config) error {
// configureConfigFile updates the specified container engine config file to enable the NVIDIA runtime. // configureConfigFile updates the specified container engine config file to enable the NVIDIA runtime.
func (m command) configureConfigFile(c *cli.Context, config *config) error { func (m command) configureConfigFile(c *cli.Context, config *config) error {
configFilePath := config.resolveConfigFilePath()
var err error
configSource, err := config.resolveConfigSource() configSource, err := config.resolveConfigSource()
if err != nil { if err != nil {
return err return err
@ -254,19 +262,19 @@ func (m command) configureConfigFile(c *cli.Context, config *config) error {
case "containerd": case "containerd":
cfg, err = containerd.New( cfg, err = containerd.New(
containerd.WithLogger(m.logger), containerd.WithLogger(m.logger),
containerd.WithPath(configFilePath), containerd.WithPath(config.configFilePath),
containerd.WithConfigSource(configSource), containerd.WithConfigSource(configSource),
) )
case "crio": case "crio":
cfg, err = crio.New( cfg, err = crio.New(
crio.WithLogger(m.logger), crio.WithLogger(m.logger),
crio.WithPath(configFilePath), crio.WithPath(config.configFilePath),
crio.WithConfigSource(configSource), crio.WithConfigSource(configSource),
) )
case "docker": case "docker":
cfg, err = docker.New( cfg, err = docker.New(
docker.WithLogger(m.logger), docker.WithLogger(m.logger),
docker.WithPath(configFilePath), docker.WithPath(config.configFilePath),
) )
default: default:
err = fmt.Errorf("unrecognized runtime '%v'", config.runtime) err = fmt.Errorf("unrecognized runtime '%v'", config.runtime)
@ -307,22 +315,6 @@ func (m command) configureConfigFile(c *cli.Context, config *config) error {
return nil return nil
} }
// resolveConfigFilePath returns the default config file path for the configured container engine
func (c *config) resolveConfigFilePath() string {
if c.configFilePath != "" {
return c.configFilePath
}
switch c.runtime {
case "containerd":
return defaultContainerdConfigFilePath
case "crio":
return defaultCrioConfigFilePath
case "docker":
return defaultDockerConfigFilePath
}
return ""
}
// resolveConfigSource returns the default config source or the user provided config source // resolveConfigSource returns the default config source or the user provided config source
func (c *config) resolveConfigSource() (toml.Loader, error) { func (c *config) resolveConfigSource() (toml.Loader, error) {
switch c.configSource { switch c.configSource {
@ -351,7 +343,7 @@ func (c *config) getOutputConfigPath() string {
if c.dryRun { if c.dryRun {
return "" return ""
} }
return c.resolveConfigFilePath() return c.configFilePath
} }
// configureOCIHook creates and configures the OCI hook for the NVIDIA runtime // configureOCIHook creates and configures the OCI hook for the NVIDIA runtime