fix: Prevent config option from reverting modified configurations#1694
Open
sunjq1 wants to merge 2 commits intoNVIDIA:mainfrom
Open
fix: Prevent config option from reverting modified configurations#1694sunjq1 wants to merge 2 commits intoNVIDIA:mainfrom
sunjq1 wants to merge 2 commits intoNVIDIA:mainfrom
Conversation
Signed-off-by: Sun Jianqiang <sunjianqiangv@foxmail.com>
elezar
reviewed
Mar 4, 2026
Member
elezar
left a comment
There was a problem hiding this comment.
As a general comment, could we add unit tests to validate the original behaviour and then verify that the fix addresses this.
Signed-off-by: Sun Jianqiang <sunjianqiangv@foxmail.com>
Author
I have updated the PR with a unit test: Before Fix$ go test
--- FAIL: TestLoadConfigToml (0.00s)
--- FAIL: TestLoadConfigToml/save_uncommented_configuration_items_to_file (0.00s)
toml_test.go:388:
Error Trace: nvidia-container-toolkit/api/config/v1/toml_test.go:388
Error: Not equal:
...
Diff:
--- Expected
+++ Actual
@@ -7,3 +7,3 @@
[nvidia-container-cli]
-debug = "/var/log/nvidia-container-toolkit.log"
+#debug = "/var/log/nvidia-container-toolkit.log"
environment = []
@@ -18,3 +18,3 @@
[nvidia-container-runtime]
-debug = "/var/log/nvidia-container-runtime.log"
+#debug = "/var/log/nvidia-container-runtime.log"
log-level = "info"
Test: TestLoadConfigToml/save_uncommented_configuration_items_to_file
FAIL
exit status 1
FAIL github.com/NVIDIA/nvidia-container-toolkit/api/config/v1 0.010sAfter Fix$ go test
PASS
ok github.com/NVIDIA/nvidia-container-toolkit/api/config/v1 0.009s |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes an issue where uncommented default configuration options (such as
nvidia-container-runtime.debug) were being automatically re-commented when runningnvidia-ctk config(without the--setflag), even if the user had explicitly enabled them in the configuration file.Problem
The current implementation of
commentDefaults()relies on avaluesSetmap to track which configuration keys have been explicitly modified. However, when loading an existing configuration file from disk, thevaluesSetmap remained empty.As a result, if a user manually uncommented a default setting without changing its value(e.g.,
nvidia-container-runtime.debug = "/var/log/nvidia-container-runtime.log"), or uncommented with the--setflag, the toolkit would:#comment prefix during theSave()operation, effectively reverting the user's manual configuration.Changes
loadConfigToml()to traverse the TOML tree after successfully reading from a file, populating thevaluesSetmap with all keys present in the file.Testing Performed
nvidia-ctk config --in-placeno longer re-comments uncommented lines in/etc/nvidia-container-runtime/config.toml.nvidia-ctk config defaultstill generates a standard template with the correct comments and default values.Before Fix
After Fix