Skip to content

Conversation

ArangoGutierrez
Copy link
Collaborator

This pull request introduces environment variable support for various CLI flags across multiple commands in the nvidia-ctk cdi command.

These changes enhance configurability by allowing users to set default values for CLI flags via environment variables.

ENV VAR follows a logic of NVIDIA_CTK_CDI_*

@ArangoGutierrez ArangoGutierrez requested review from elezar and Copilot June 2, 2025 11:28
@ArangoGutierrez ArangoGutierrez self-assigned this Jun 2, 2025
Copy link

@Copilot Copilot AI left a 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 introduces environment variable support for various nvidia-ctk cdi CLI flags, allowing defaults to be set via NVIDIA_CTK_CDI_* variables.

  • Adds EnvVars definitions to flags in the transform root, list, and generate commands.
  • Ensures each CLI option can now read from the corresponding NVIDIA_CTK_CDI_* environment variable.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
cmd/nvidia-ctk/cdi/transform/root/root.go Added EnvVars to all flags of the transform root subcommand
cmd/nvidia-ctk/cdi/list/list.go Added EnvVars to the list command’s spec-dir flag
cmd/nvidia-ctk/cdi/generate/generate.go Added EnvVars to multiple flags in the generate subcommand
Comments suppressed due to low confidence (4)

cmd/nvidia-ctk/cdi/transform/root/root.go:76

  • No tests have been added to verify that the new EnvVars fields actually populate the CLI flags from environment variables. Consider adding unit or integration tests to cover this behavior.
EnvVars:     []string{"NVIDIA_CTK_CDI_TRANSFORM_ROOT_FROM"},

cmd/nvidia-ctk/cdi/list/list.go:67

  • The addition of the EnvVars here isn’t accompanied by tests to confirm that NVIDIA_CTK_CDI_LIST_SPEC_DIR is correctly read. Please add tests to validate this new env var behavior.
EnvVars:     []string{"NVIDIA_CTK_CDI_LIST_SPEC_DIR"},

cmd/nvidia-ctk/cdi/generate/generate.go:99

  • There are several new EnvVars entries in this file but no corresponding tests. Add coverage to ensure each NVIDIA_CTK_CDI_GENERATE_* variable is applied correctly.
EnvVars:     []string{"NVIDIA_CTK_CDI_GENERATE_CONFIG_SEARCH_PATH"},

cmd/nvidia-ctk/cdi/transform/root/root.go:75

  • Consider updating the flag Usage strings to mention the corresponding environment variables (e.g., “can also be set via NVIDIA_CTK_CDI_TRANSFORM_ROOT_FROM”) so users are aware of the new option.
Usage:       "specify the root to be transformed",

},
&cli.StringFlag{
Name: "output",
Usage: "Specify the file to output the generated CDI specification to. If this is '' the specification is output to STDOUT",
Destination: &opts.output,
EnvVars: []string{"NVIDIA_CTK_CDI_GENERATE_OUTPUT"},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would NVIDIA_CTK_OUTPUT or NVIDIA_CTK_CDI_OUTPUT make sense here? Do we want to be more verbose and have NVIDIA_CTK_CDI_OUTPUT_FILENAME?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specify the file to output

Specify the output file path. And that makes me want an env var name ending on _PATH

:)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NVIDIA_CTK_CDI_OUTPUT_FILE_PATH

},
&cli.StringFlag{
Name: "format",
Usage: "The output format for the generated spec [json | yaml]. This overrides the format defined by the output file extension (if specified).",
Value: spec.FormatYAML,
Destination: &opts.format,
EnvVars: []string{"NVIDIA_CTK_CDI_GENERATE_FORMAT"},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
EnvVars: []string{"NVIDIA_CTK_CDI_GENERATE_FORMAT"},
EnvVars: []string{"NVIDIA_CTK_CDI_GENERATE_OUTPUT_FORMAT"},

},
&cli.StringFlag{
Name: "dev-root",
Usage: "Specify the root where `/dev` is located. If this is not specified, the driver-root is assumed.",
Destination: &opts.devRoot,
EnvVars: []string{"NVIDIA_CTK_CDI_GENERATE_DEV_ROOT"},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think NVIDIA_CTK_DEV_ROOT makes sense here. This is the kind of option that should be consistent across the entire CLI.

},
&cli.StringSliceFlag{
Name: "library-search-path",
Usage: "Specify the path to search for libraries when discovering the entities that should be included in the CDI specification.\n\tNote: This option only applies to CSV mode.",
Destination: &opts.librarySearchPaths,
EnvVars: []string{"NVIDIA_CTK_CDI_GENERATE_LIBRARY_SEARCH_PATH"},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
EnvVars: []string{"NVIDIA_CTK_CDI_GENERATE_LIBRARY_SEARCH_PATH"},
EnvVars: []string{"NVIDIA_CTK_CDI_GENERATE_LIBRARY_SEARCH_PATHS"},

@@ -145,36 +153,42 @@ func (m command) build() *cli.Command {
"If not specified, the PATH will be searched for `nvidia-cdi-hook`. " +
"NOTE: That if this is specified as `nvidia-ctk`, the PATH will be searched for `nvidia-ctk` instead.",
Destination: &opts.nvidiaCDIHookPath,
EnvVars: []string{"NVIDIA_CTK_CDI_GENERATE_NVIDIA_CDI_HOOK_PATH"},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
EnvVars: []string{"NVIDIA_CTK_CDI_GENERATE_NVIDIA_CDI_HOOK_PATH"},
EnvVars: []string{"NVIDIA_CTK_CDI_HOOK_PATH"},

or

Suggested change
EnvVars: []string{"NVIDIA_CTK_CDI_GENERATE_NVIDIA_CDI_HOOK_PATH"},
EnvVars: []string{"NVIDIA_CDI_HOOK_PATH"},

since I would also expect this to be globally consistent.

},
&cli.StringSliceFlag{
Name: "csv.file",
Usage: "The path to the list of CSV files to use when generating the CDI specification in CSV mode.",
Value: cli.NewStringSlice(csv.DefaultFileList()...),
Destination: &opts.csv.files,
EnvVars: []string{"NVIDIA_CTK_CDI_GENERATE_CSV_FILE"},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
EnvVars: []string{"NVIDIA_CTK_CDI_GENERATE_CSV_FILE"},
EnvVars: []string{"NVIDIA_CTK_CDI_GENERATE_CSV_FILES"},

},
&cli.StringSliceFlag{
Name: "device-name-strategy",
Usage: "Specify the strategy for generating device names. If this is specified multiple times, the devices will be duplicated for each strategy. One of [index | uuid | type-index]",
Value: cli.NewStringSlice(nvcdi.DeviceNameStrategyIndex, nvcdi.DeviceNameStrategyUUID),
Destination: &opts.deviceNameStrategies,
EnvVars: []string{"NVIDIA_CTK_CDI_GENERATE_DEVICE_NAME_STRATEGY"},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
EnvVars: []string{"NVIDIA_CTK_CDI_GENERATE_DEVICE_NAME_STRATEGY"},
EnvVars: []string{"NVIDIA_CTK_CDI_GENERATE_DEVICE_NAME_STRATEGIES"},

},
&cli.StringFlag{
Name: "driver-root",
Usage: "Specify the NVIDIA GPU driver root to use when discovering the entities that should be included in the CDI specification.",
Destination: &opts.driverRoot,
EnvVars: []string{"NVIDIA_CTK_CDI_GENERATE_DRIVER_ROOT"},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
EnvVars: []string{"NVIDIA_CTK_CDI_GENERATE_DRIVER_ROOT"},
EnvVars: []string{"NVIDIA_CTK_DRIVER_ROOT"},

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's leave the transform command out of scope for this PR.

@@ -64,6 +64,7 @@ func (m command) build() *cli.Command {
Usage: "specify the directories to scan for CDI specifications",
Value: cli.NewStringSlice(cdi.DefaultSpecDirs...),
Destination: &cfg.cdiSpecDirs,
EnvVars: []string{"NVIDIA_CTK_CDI_LIST_SPEC_DIR"},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about:

Suggested change
EnvVars: []string{"NVIDIA_CTK_CDI_LIST_SPEC_DIR"},
EnvVars: []string{"NVIDIA_CTK_CDI_SPEC_DIRS"},

Since we would expect them to be globally consistent. Not a blocker though.

},
&cli.StringSliceFlag{
Name: "csv.ignore-pattern",
Usage: "Specify a pattern the CSV mount specifications.",
Destination: &opts.csv.ignorePatterns,
EnvVars: []string{"NVIDIA_CTK_CDI_GENERATE_CSV_IGNORE_PATTERN"},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
EnvVars: []string{"NVIDIA_CTK_CDI_GENERATE_CSV_IGNORE_PATTERN"},
EnvVars: []string{"NVIDIA_CTK_CDI_GENERATE_CSV_IGNORE_PATTERNS"},

@@ -96,17 +96,20 @@ func (m command) build() *cli.Command {
Name: "config-search-path",
Usage: "Specify the path to search for config files when discovering the entities that should be included in the CDI specification.",
Destination: &opts.configSearchPaths,
EnvVars: []string{"NVIDIA_CTK_CDI_GENERATE_CONFIG_SEARCH_PATH"},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
EnvVars: []string{"NVIDIA_CTK_CDI_GENERATE_CONFIG_SEARCH_PATH"},
EnvVars: []string{"NVIDIA_CTK_CDI_GENERATE_CONFIG_SEARCH_PATHS"},

Copy link

@Copilot Copilot AI left a 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 introduces support for setting default values of various nvidia-ctk cdi CLI flags via environment variables.

  • Adds an EnvVars entry for the list command’s spec-dirs flag.
  • Adds EnvVars entries for multiple flags in the generate command.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
cmd/nvidia-ctk/cdi/list/list.go Added EnvVars for the spec-dirs flag.
cmd/nvidia-ctk/cdi/generate/generate.go Added EnvVars for several generate command flags.
Comments suppressed due to low confidence (3)

cmd/nvidia-ctk/cdi/generate/generate.go:128

  • [nitpick] The environment variable name here omits the CDI_GENERATE segment—consider renaming to NVIDIA_CTK_CDI_GENERATE_DEV_ROOT for consistency with other flags.
EnvVars:     []string{"NVIDIA_CTK_DEV_ROOT"},

cmd/nvidia-ctk/cdi/generate/generate.go:141

  • [nitpick] The environment variable name here omits the CDI_GENERATE segment—consider renaming to NVIDIA_CTK_CDI_GENERATE_DRIVER_ROOT to align with the pattern used by other flags in this command.
EnvVars:     []string{"NVIDIA_CTK_DRIVER_ROOT"},

cmd/nvidia-ctk/cdi/generate/generate.go:156

  • [nitpick] The environment variable name here omits GENERATE—consider renaming to NVIDIA_CTK_CDI_GENERATE_HOOK_PATH for consistency with other generate command flags.
EnvVars:     []string{"NVIDIA_CTK_CDI_HOOK_PATH"},

@ArangoGutierrez ArangoGutierrez force-pushed the cdi_generate_env_cli branch 2 times, most recently from 1e2d93b to d44a199 Compare June 3, 2025 13:21
Signed-off-by: Carlos Eduardo Arango Gutierrez <[email protected]>
@coveralls
Copy link

Pull Request Test Coverage Report for Build 15463397348

Details

  • 0 of 16 (0.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.04%) to 33.228%

Changes Missing Coverage Covered Lines Changed/Added Lines %
cmd/nvidia-ctk/cdi/list/list.go 0 1 0.0%
cmd/nvidia-ctk/cdi/generate/generate.go 0 15 0.0%
Totals Coverage Status
Change from base Build 15437228265: -0.04%
Covered Lines: 4215
Relevant Lines: 12685

💛 - Coveralls

@ArangoGutierrez ArangoGutierrez merged commit 28add0a into NVIDIA:main Jun 5, 2025
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants