-
Notifications
You must be signed in to change notification settings - Fork 13
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
feat: add config management package #108
Conversation
docs/src/charmil_config.md
Outdated
|
||
- Uses [Viper](https://github.com/spf13/viper) under the hood. | ||
- Helps in maintaining all available configurations in a single central-local config file. | ||
- Provides the plugin developers with a set of methods to maintain a configuration map and export it to the host CLI. |
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.
Wow. Very cool!
docs/src/charmil_config.md
Outdated
} | ||
``` | ||
|
||
7. Map a plugin name to its config map using the `SetPluginCfg` method by passing the name of the plugin (as you want it in the config file) as the first argument and the config map imported from the plugin, as the second argument. |
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.
Later phase this could be automated by plugin itself
docs/src/charmil_config.md
Outdated
h.MergePluginCfg() | ||
``` | ||
|
||
9. Write current config into the local config file using the `Save` method. |
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.
So this is approach where we migrate one time only config..
I do see it too much of hassle.
Lets put all things in the table:
-
some clis hqve their own config and will work with it using structure - like rhoas cli does
-
then cli can become plugin and have the same form of config but saved to the single file under key along with other plugins
For simplicity we assume that plugin cli was never installed on os and only host is.
What I do not get is - why host needs to interact with plugin and use non typed api (strings). We need only to abstract read and write?
My understanding was that all we need to do is to provide dynamic config location for fetching config. Some code here is going to do it but not getting the other rest.
So config of plugin can be:
- entire file on it's own
- some subpath of json when running in host
Missing anything?
Typed by one hand while feeding newborn. Sorry for typos
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.
Since plugin is inside host we can also import config structures into host.
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.
Can you reply to this?
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.
Okay so I revisited the Rhoas config implementation and I think now I understand what the issues with my current approach are. Will change all the things that you've mentioned.
I've tried to summarize all the current issues with reasons and solutions for the same, through this comment: #108 (comment)
Please have a look and let me know if there is anything to be added/removed :)
@namit-chandwani I think that I totally missunderstood your proposal from discussion. Sorry for that. Good news is that I see some useful code that with minor adjustments will work for us. Bad news is that I feel like you have done much more than that and it might not be needed. This PR is very promissing so no worries. |
Summary:
|
Needs rebase. Is that ready for review? |
examples/host/main.go
Outdated
} | ||
|
||
func main() { | ||
// TODO: Initialize the factory struct here and pass it to the plugins |
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.
So is the idea the plugin will be able to load and save data to and from the config file with a Handler
that is in factory? That we would then populate cfg with our config struct.
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.
Yes, you're absolutely right.
Just that we won't need to pass the Handler
as a whole into the factory. Instead, only including the local config file path in the factory and passing it to the plugins will suffice. WDYT?
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.
Yeah I think your right, just storing the path would make more sense to me.
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.
@jackdelahunt BTW just to update you, according to the latest implementation, we will be including the entire Handler
in the factory (just as you had mentioned earlier).
Will create an issue/PR for the same shortly.
Yes. Both read and save should work with the plugin host scenarios |
Also make sure to update the docs before next review. |
Just making some last-minute changes and updating docs. Will rebase and ping you once done
Yes, doing that right now :) |
Thanks, make sure to take your time and enjoy it. No need to put a lot of pressure on yourself just because we want to review. |
d490ad1
to
053df78
Compare
Forgot to ping you earlier 😅 This is ready for review and the changes discussed in review comments have been made. |
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.
Very good step forward. I left some questions about merging config. Everything else looks ok.
I need to play with this myself more once we merge it
core/config/config.go
Outdated
) | ||
|
||
// Handler defines the fields required to manage config. | ||
type Handler struct { |
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.
Too Generic name
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.
Resolved via commit: 822770b
core/config/config.go
Outdated
// (using the file path linked to the handler). | ||
func (h *Handler) Save() error { | ||
// To store the current contents of the local config file | ||
dst := &map[string]interface{}{} |
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.
Any reason why we do not use structures here?
I do not question the approach but this seems to be overly large comparing to 2 liner that will save root structure
that user will provide.
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.
Resolved via commit: 7f08531
docs/src/charmil_config.md
Outdated
fmt.Println(cfg.Key6) // Prints: val6 | ||
``` | ||
|
||
5. Use the `MergePluginCfg` function to merge the current plugin config into the local config file |
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.
So far all was really good, but I feel that this merge can be done by including structure of the plugin config inside host config. This way we get serialization sorted out of the box. (Requirement: it needs to be json is fine for now)
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.
Resolved via commit: a337275
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.
From what I can see besides the points that have already been raised this is looking really good so far. Good work!
TODO:
|
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 really hate to be this guy comming back and forth on this. I trust you have applied all suggestions. Lets merge it and refine it on main branch
Move todos to issues so build will pass..Or better afdress them |
@wtrocki This PR is ready to merge now. |
Closes #69
Based on discussion: #100
Description
Added a config package that offers a convenient mechanism for both host and plugin developers to manage configurations in their CLIs.
Type of change
Checklist