-
Notifications
You must be signed in to change notification settings - Fork 98
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
kernelci.cli: implement kci config set
command
#2226
Conversation
Implement a command to set a value in the YAML config file at the provided path where path is a dotted string of a YAML hierarchy e.g. `api.docker-host.url=new-url`. Implement a helper function in `kernelci.config` to interate over YAML files and update a value. Signed-off-by: Jeny Sadadia <jeny.sadadia@collabora.com>
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.
OK I'm going to draw the line before this PR, someone else will have to review it and any future ones I think. I'll make sure the changes that I've been holding back for a month now get to work on top of the current main
branch and submit PRs (probably today).
I tried to use it in following way:
It doesnt look it is changing anything, this value doesn't exist in config, but appears in dump. But worked with:
Also as i understand on change it will remove all comments from config files? |
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'm not sure it's going to work, as Denys pointed out. It's nice to have the feature available, a bit like git config
can set values in the config file and many other tools can do that too. Editing YAML by hand can be cumbersome, especially when the data is large. However, I think it should be instead changing the value of the config object loaded from YAML and then doing a dump to automatically generate the YAML files, rather than editing dictionaries with the raw data. Also this would mostly work with files already generated to avoid undoing any manual formatting. I believe comments can be preserved as the YAML loader should be able to parse and store them somehow but it's not currently taken into account. I would say, this will be easier to implement once the legacy YAML stuff is entirely out of the way so in about one year.
As a side note: a much more useful set
kind of command to implement right now would probably be the one to edit node JSON data I think. That's for manual interaction with the API, e.g. first you get a node then you add some results to it with kci node set result=pass
or something and submit it again.
Since efforts are done i think we can have use cases for this command, i can see it might be used in some cases of automated deployments (especially staging/tests/etc). But i am wondering if there is any other use cases. |
Also it would need to track which file was used to load which config, which gets very complicated with overlays. So, I would personally choose to drop it for now and have a separate tool to edit the YAML automatically if we need this kind of feature in the meantime, just like we have one to update the rootfs URLs. |
Thanks for the reviews @nuclearcat @gctucker @nuclearcat Thanks for testing. I need to investigate why it didn't work when you tried to update |
Another thought I had later on, the command could have an argument with an explicit file name. So then it would load configs only from that file, set a value there and generate the new YAML which could be used to overwrite the same file or dumped on stdout. That way, users would manage some generated files separately from the manually edited ones. The |
I checked with different loader options. I also tested with |
Right, my suggestion is based on the idea that some files are managed by hand and some are auto-generated. When setting a value using |
Closing the PR as per the above discussion. |
Implement a command to set a value in the YAML config file at the provided path where path is a dotted string of a YAML hierarchy e.g.
api.docker-host.url=new-url
. Implement a helper function inkernelci.config
to interate over YAML files and update a value.