Add support for specifying the config file path in an environment variable#763
Conversation
91aadb7 to
3a304b0
Compare
This change adds support for explicitly specifying the path to the config file through an environment variable. The NVIDIA_CTK_CONFIG_FILE_PATH variable is used for both the nvidia-container-runtime and nvidia-container-runtime-hook. Signed-off-by: Evan Lezar <elezar@nvidia.com>
Signed-off-by: Evan Lezar <elezar@nvidia.com>
3a304b0 to
77457b4
Compare
Pull Request Test Coverage Report for Build 15733658255Details
💛 - Coveralls |
Signed-off-by: Evan Lezar <elezar@nvidia.com>
77457b4 to
849691d
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR enables overriding the location of the nvidia-container-runtime config file via the NVIDIA_CTK_CONFIG_FILE_PATH environment variable for both the runtime and hook, and refactors related installer APIs to propagate the explicit path.
- Introduce
FilePathOverrideEnvVarandRelativeFilePathconstants and updateGetConfigFilePathto respectNVIDIA_CTK_CONFIG_FILE_PATH - Refactor installer (
ToolkitInstaller) to accept and propagate a concrete config file path - Update tests and hook code to use the new override logic and remove direct
-configflag usage
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| internal/config/config.go | Added FilePathOverrideEnvVar/RelativeFilePath and updated GetConfigFilePath logic |
| internal/config/config_test.go | Adjusted tests to cover both root override and file-path override |
| cmd/nvidia-ctk-installer/toolkit/toolkit.go | Pass explicit config path into installToolkitConfig |
| cmd/nvidia-ctk-installer/toolkit/installer/options.go | Renamed toolkitInstaller receiver to ToolkitInstaller in options |
| cmd/nvidia-ctk-installer/toolkit/installer/libraries.go | Updated receiver type for collectLibraries |
| cmd/nvidia-ctk-installer/toolkit/installer/installer_test.go | Switched to ToolkitInstaller in test setup and updated env vars |
| cmd/nvidia-ctk-installer/toolkit/installer/installer.go | Renamed type, made New return *ToolkitInstaller, added ConfigFilePath |
| cmd/nvidia-ctk-installer/toolkit/installer/executables_test.go | Removed Args-related tests following wrapper refactor |
| cmd/nvidia-ctk-installer/toolkit/installer/executables.go | Dropped CLI-arg support, now uses env-var override in wrappers |
| cmd/nvidia-ctk-installer/toolkit/installer/directory.go | Renamed receiver on createDirectory |
| cmd/nvidia-container-runtime-hook/hook_config.go | Simplified loadConfig, now honors flag/env/default path |
Comments suppressed due to low confidence (6)
internal/config/config.go:34
- Add a GoDoc comment for the exported constant FilePathOverrideEnvVar to explain its purpose and usage.
FilePathOverrideEnvVar = "NVIDIA_CTK_CONFIG_FILE_PATH"
internal/config/config.go:35
- Add a GoDoc comment for the exported constant RelativeFilePath to clarify that it represents the default relative path to the configuration file.
RelativeFilePath = "nvidia-container-runtime/config.toml"
internal/config/config_test.go:28
- [nitpick] The test name TestGetConfigWithCustomConfig does not clearly reflect that it verifies behavior under the XDG_CONFIG_HOME override. Consider renaming to TestGetConfigWithConfigRootOverride.
func TestGetConfigWithCustomConfig(t *testing.T) {
internal/config/config_test.go:34
- [nitpick] This comment appears misleading because the test actually writes a debug path into the file contents. Update or remove it to accurately describe what the test is verifying.
// By default debug is disabled
cmd/nvidia-ctk-installer/toolkit/installer/installer.go:49
- [nitpick] Changing the signature of New to return *ToolkitInstaller instead of Installer is a breaking API change. Ensure all consumers are updated or consider providing an overload to maintain backward compatibility.
func New(opts ...Option) (*ToolkitInstaller, error) {
cmd/nvidia-container-runtime-hook/hook_config.go:21
- The previous fallback to loading the config from the driver directory (/run/nvidia/driver/etc) was removed. If that behavior is still required for legacy installs, consider reintroducing the driverPath fallback logic.
func loadConfig() (*config.Config, error) {
| if configFilePathOverride := os.Getenv(FilePathOverrideEnvVar); configFilePathOverride != "" { | ||
| return configFilePathOverride | ||
| } | ||
| configRoot := "/etc" |
There was a problem hiding this comment.
nit: maybe a newline before configRoot :=...
|
@elezar I think the PR title should be updated to better reflect the intent of the PR. |
|
@ArangoGutierrez is the change you require the PR title, or are you blocking on the nit? |
This change allows the config file used by the
nvidia-container-runtimeandnvidia-container-runtime-hookto be explicitly set using anNVIDIA_CTK_CONFIG_FILE_PATHenvironment variable. This removes the need to inject a-configoption when installing thenvidia-contianer-runtime-hookwrapper from the toolkit container and allows the two components to treat this consistently.This would allow the changes of #700 to be integrated more easily.