-
Notifications
You must be signed in to change notification settings - Fork 263
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
Refactor main flow and introduce explicit plugin and config handling #877
Conversation
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: rhuss The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
The main flow of execution has been changed as described in the developer guide: FlowThe journey starts at main.go which is the entry point when you call
Only the code in the Let's talk now about the three phases separately. BootstrapThe bootstrap performed by config.BootstrapConfig() extracts all the options relevant for config file detection and plugin configuration. Viper loads the configuration file (if any) form this location, and the Plugin LookupIn the next step, a ExecutionIf However, before If ConfigurationFor any command that is executed by
The main flow calls out to All other configuration that is stored in the configuration is also available after the bootstrap. |
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.
Produced via:
gofmt -s -w $(find -path './vendor' -prune -o -path './third_party' -prune -o -type f -name '*.go' -print)
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.
Produced via:
gofmt -s -w $(find -path './vendor' -prune -o -path './third_party' -prune -o -type f -name '*.go' -print)
All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the ℹ️ Googlers: Go here for more info. |
@mattmoor Could you please |
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.
Produced via:
gofmt -s -w $(find -path './vendor' -prune -o -path './third_party' -prune -o -type f -name '*.go' -print)
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.
Produced via:
gofmt -s -w $(find -path './vendor' -prune -o -path './third_party' -prune -o -type f -name '*.go' -print)
|
@itsmurugappan here's an update which should bring back the fix for unknown subcommand checks. |
Verified it. Works as before |
All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the ℹ️ Googlers: Go here for more info. |
* The plugin handling has been moved out of the `KnDefaultCommand` constructor where it was executed as a side-effect. The original code from `kubectl` suffers from the same issue that plugin handling is not a top-level concern but was very likely introduced as an after-thought. Instead, the plugin handling is done now by a `PluginManager` which is explicitly called in `main()`. * Configuration and bootstrap option handling is centralized in the package `option`. After the bootstrap happened, the content of the configuration file, as well as any other global configuration, can be obtained from methods on `config.GlobalConfig`. Also, all flag handling is delegated to cobra so that no own parsing is needed. * Many of the logic in `pkg/kn/commands/plugin` for plugin management has been moved up to `pkg/kn/plugin` as this code is not only relevant for `plugin list` but also for the bootstrap process.
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
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.
Nice!
Liked the improved code readability and re-grouping, the imports are clean too! Thank you!
I've suggested a few nits mostly around wording of panic error messages,
and commented at a few places where the links are missing (we can fill in the links in a subsequent PR once merged)
Co-authored-by: Navid Shaikh <[email protected]>
Co-authored-by: Navid Shaikh <[email protected]>
Co-authored-by: Navid Shaikh <[email protected]>
Co-authored-by: Navid Shaikh <[email protected]>
The following is the coverage report on the affected files.
|
Thanks a lot for the reviews so far, it looks like we are on the right track. In order to remove some review pressure, let's go for a lazy consensus approach: This PR doesn't add any new major feature but makes maintenance easier (see also intro). Adjustments can happen later, too, so the suggestion is that if there are no objections until the end of the week, the PR gets merged.
If no objections stated here, this is assumed to be a consensus so that the PR gets merged on Friday in this case. |
Per our chat conversation it's good to go now... |
David meets all criteria for an approver: - [x] Reviewer for at least 3 months - [x] Primary reviewer for at least 10 substantial PRs to the codebase, e.g. * knative#1246 * knative#1194 * knative#738 * knative#832 * knative#1016 * knative#877 * knative#667 * knative#697 * knative#1212 * knative#835 - [x] Reviewed at least 30 PRs to the codebase ([38 assigned PRs](https://github.com/knative/client/pulls?q=type%3Apr+assignee%3Adsimansk+)) - [x] Nominated by a WG lead (rhuss) Congrats David ! Thanks a lot for your awesome work & contributions.
David meets all criteria for an approver: - [x] Reviewer for at least 3 months - [x] Primary reviewer for at least 10 substantial PRs to the codebase, e.g. * knative#1246 * knative#1194 * knative#738 * knative#832 * knative#1016 * knative#877 * knative#667 * knative#697 * knative#1212 * knative#835 - [x] Reviewed at least 30 PRs to the codebase ([38 assigned PRs](https://github.com/knative/client/pulls?q=type%3Apr+assignee%3Adsimansk+)) - [x] Nominated by a WG lead (rhuss) Congrats David ! Thanks a lot for your awesome work & contributions.
David meets all criteria for an approver: - [x] Reviewer for at least 3 months - [x] Primary reviewer for at least 10 substantial PRs to the codebase, e.g. * #1246 * #1194 * #738 * #832 * #1016 * #877 * #667 * #697 * #1212 * #835 - [x] Reviewed at least 30 PRs to the codebase ([38 assigned PRs](https://github.com/knative/client/pulls?q=type%3Apr+assignee%3Adsimansk+)) - [x] Nominated by a WG lead (rhuss) Congrats David ! Thanks a lot for your awesome work & contributions.
This PR is a significant refactoring of the main flow of how commands and plugins are processed. I'm aware such big changes should not be introduced lightly and only for good reasons. While working to implement #579 and to give some guidance for how to improve the plugin error message flow (cc: @dsimansky), I stumbled upon the following issues (and more):
NewKnDefaultCommand()
. This code is more or less taken over literally fromkubectl
, but it definitely has it has issues in understandability and maintainability. Plugin error handling is tough here (i.e. how to return the error)--plugins-dir
and--lookup-plugins
are parsed manually (without cobra support), and it was buggy (i.e. doesn't honour both--plugin-dir=/my/dir
and--plugin-dir /my/dir
).kn/commands/plugins
package but should be more top-level as it is used there also to verify the pluginTo fix this and to generally enhance the main flow, the following significant changes have been introduced in this PR:
KnDefaultCommand
constructor where it was executed as a side-effect. The original code fromkubectl
suffers from the same issue that plugin handling is not a top-level concern but was very likely introduced as an after-thought. Instead, the plugin handling is done now by aPluginManager
which is explicitly called inmain()
.option
. After the bootstrap happened, the content of the configuration file, as well as any other global configuration, can be obtained from methods onconfig.GlobalConfig
. Also, all flag handling is delegated to cobra so that no own parsing is needed.pkg/kn/commands/plugin
for plugin management has been moved up topkg/kn/plugin
as this code is not only relevant forplugin list
but also for the bootstrap process.This PR will also help to make the implementation of the following feature requests easier:
kn
functionality for plugins and specialized Knative clients #763 - Extract commonkn
functionality for plugins and specialized Knative clientskn --help
#266 - Consider adding plugin cmds tokn --help
-q
quiet option in kn plugins once #182 is done #258 - Support-q
quiet option in kn pluginsAlso, some minor refactoring for the tests is included to remove some nesting in the tests and make it easier to understand and maintain (of course this depends on the POV so happy on any feedback, positive or negative).
Two user-facing changes are suggested as part of this PR:
--plugins-dir
and--lookup-plugins
are still supported but marked as hidden. IMO these should eventually be removed. I question their value as global options because they are much better fit for the configuration file as these are permanent decisions that don't change from CLI call to CLI call and also to reduce the global option churn. However, this is, of course, open to discussion.I recommend starting a review in main.go and follow the flow for config parsing and plugin handling. Also, I added a more detailed explanation of the flow in a separate document
developer-guide.md
as part of this PR. I extract the relevant section describing the outcome of the refactoring in the next comment.Yes, it's a big PR but I think it makes
kn
better. As the PR touches the core of kn, I would highly appreciate if it could be reviewed and potentially merged asap to avoid blocking other contributions.