-
Notifications
You must be signed in to change notification settings - Fork 435
Load settings from config.toml file during CDI generation #1107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This pull request adds logic to load configuration from a config.toml file during CDI generation and listing, ensuring the proper order of precedence when determining settings (command line, environment variable, then config file).
- Introduces a MockLogger for internal logging tests
- Extends flag validation in the list and generate commands to incorporate config file values
- Updates tests to cover configuration loading and flag precedence
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| internal/logger/mock.go | Adds a mock logger implementation |
| cmd/nvidia-ctk/cdi/list/list_test.go | Adds tests for flag precedence in the list cmd |
| cmd/nvidia-ctk/cdi/list/list.go | Implements loading config file for list command |
| cmd/nvidia-ctk/cdi/generate/generate_test.go | Adds tests for config loading in generate command |
| cmd/nvidia-ctk/cdi/generate/generate.go | Integrates config file values into generate flags |
e7c94d1 to
d572260
Compare
|
Let's first agree on #1123 , I'll then rebase this PR and continnue the work here |
|
PR updated now with a centralized logic at |
Pull Request Test Coverage Report for Build 15447921501Details
💛 - Coveralls |
2453fb2 to
1676931
Compare
| &cli.StringSliceFlag{ | ||
| Name: "folder", | ||
| Usage: "Specify a folder to add to /etc/ld.so.conf before updating the ld cache", | ||
| Destination: &cfg.folders, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have a reference for this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moving all the c.something into the c:= cli.Command initialization
cmd/nvidia-cdi-hook/chmod/chmod.go
Outdated
| UseShortOptionHandling: true, | ||
| EnableShellCompletion: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: This functionality is new.
cmd/nvidia-cdi-hook/chmod/chmod.go
Outdated
| Action: func(ctx context.Context, cmd *cli.Command) error { | ||
| return m.run(cmd, &cfg) | ||
| Action: func(_ context.Context, _ *cli.Command) error { | ||
| return m.run(nil, &cfg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't pass nil into the run() function. This also doesn't seem to be related to adding a config file.
elezar
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The last commit has more changes than I would expect -- which I would expect to be limited to the generate.go and up the chain to nvidia-ctk main.go.
Signed-off-by: Carlos Eduardo Arango Gutierrez <[email protected]>
Signed-off-by: Carlos Eduardo Arango Gutierrez <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR migrates the CLI to urfave/cli v3, adds a --config flag and config-file support for loading settings (command line, env, config.toml precedence), and updates the generate command to pull default values from a TOML config.
- Bump Go version and replace
urfave/cli/v2imports withurfave/cli/v3and addcli-altsrc/v3 - Introduce
configAsValueSourceto allow flags to be loaded fromconfig.tomlincdi generate - Update all subcommands to use
Sources: cli.EnvVarsand the new context-basedBefore/Actionsignatures
Reviewed Changes
Copilot reviewed 35 out of 159 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| go.mod | Updated Go version, added toolchain, switched CLI deps |
| cmd/nvidia-ctk/main.go | Converted root CLI to v3, added global --config flag |
| cmd/nvidia-ctk/config/create-default/create-default.go | Migrated to v3 but removed validation call |
| cmd/nvidia-ctk/cdi/generate/config.go | Added configAsValueSource for TOML-backed flag sources |
| cmd/nvidia-ctk/system/system.go | Added unused configFile field in system commands |
| many others | Updated Before/Action signatures, replaced EnvVars |
Comments suppressed due to low confidence (2)
cmd/nvidia-ctk/cdi/generate/config.go:31
- [nitpick] Consider adding unit tests for configAsValueSource (e.g., From, loadIfRequired, ValueSource.Lookup) to verify configuration flags are correctly loaded from TOML files.
func (o *options) Config() *configAsValueSource {
cmd/nvidia-ctk/config/create-default/create-default.go:71
- This validateFlags implementation always returns nil, disabling the previous opts.Validate() logic. Restore a call to opts.Validate() or add equivalent checks to ensure flags are valid.
func (m command) validateFlags(c *cli.Command, opts *flags.Options) error {
Signed-off-by: Carlos Eduardo Arango Gutierrez <[email protected]>
Signed-off-by: Carlos Eduardo Arango Gutierrez <[email protected]> Signed-off-by: Evan Lezar <[email protected]>
Signed-off-by: Evan Lezar <[email protected]>
Signed-off-by: Evan Lezar <[email protected]>
Signed-off-by: Evan Lezar <[email protected]>
ca6cc0f to
e31290a
Compare
Signed-off-by: Carlos Eduardo Arango Gutierrez <[email protected]>
elezar
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the migration to v3 will be valuable for some of our other projects too -- although this is not critical.
This pull request adds logic for
nvidia-ctk cdi generateto load settings from the config.toml file, the order of importance if (1) command line, (2) environment variable(for those flags with an ENV VAR option), (3) config file.[no-relnote] extra: migrates to urfave v3
Fixes #1075