Update the kubectl plugin mechanism#66876
Conversation
65668ec to
940411e
Compare
0dbf007 to
e88d0a4
Compare
e4be68a to
f22bb98
Compare
soltysh
left a comment
There was a problem hiding this comment.
Two nits, mostly looks good. Please squash your changes into single commit (or fix the current commits), since the current split is hard to justify and read. Also fix that remaining tests.
/approve
pkg/kubectl/cmd/cmd.go
Outdated
There was a problem hiding this comment.
Return error in this method and have that os.Exit(1) call in NewDefaultKubectlCommand, otherwise you're hiding this.
pkg/kubectl/cmd/plugin.go
Outdated
There was a problem hiding this comment.
Shouldn't you be also checking if the command is executable?
There was a problem hiding this comment.
Thanks, added this as part of the "Verify" method
|
I'm manually adding approve label, since the docs update is related with cli changes. |
f22bb98 to
97342cf
Compare
|
/retest |
1 similar comment
|
/retest |
97342cf to
2eaad05
Compare
2eaad05 to
4bdc636
Compare
|
@soltysh thanks, review comments addressed |
|
/test pull-kubernetes-e2e-gce |
soltysh
left a comment
There was a problem hiding this comment.
The code looks good, the proposal has merged as well.
/lgtm
|
[APPROVALNOTIFIER] This PR is APPROVED Approval requirements bypassed by manually added approval. This pull-request has been approved by: juanvallejo, soltysh The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
Automatic merge from submit-queue (batch tested with PRs 67062, 67169, 67539, 67504, 66876). If you want to cherry-pick this change to another branch, please follow the instructions here. |
Release note:
Replace the existing plugin mechanism with the design proposed in kubernetes/community#2437.
The full implementation of the plugin mechanism itself is entirely contained within the first commit.Walkthrough
Under the new design, there is no plugin installation or loading required to use plugins.
A plugin is simply any executable file on a user's PATH whose name begins with
kubectl-.kubectlbinary. All environment variablesaccessible by
kubectlbecome accessible by the plugin.foo, would simply be namedkubectl-foo.Creating a plugin
Below is an example plugin, that we will use for this walkthrough. Plugins may be written in any language, and handle arguments and flags in any way, optionally (as a convention) providing a way to retrieve their version via a
versionsubcommand.Using a plugin
To use a plugin, simply make it executable:
and place it anywhere in your PATH:
You may now invoke your plugin as a
kubectlcommand:All args and flags are passed as-is to the executable:
All environment variables are also passed as-is to the executable:
Additionally, the first argument that is passed to a plugin will always be the full path to the location where it was invoked (
$0would equal/usr/local/bin/kubectl-fooin our example above).Plugin discoverability
Seeing as how the
kubectl plugincommand is left as a no-op with this PR (perhaps it could serve as an entrypoint towards additional plugin functionality in the future), a small subcommand has been included that lists all available plugin executables on a user's PATH, along with any warnings it finds.Example usage of this new subcommand is included below:
cc @kubernetes/kubectl-maintainers @kubernetes/sig-cli-pr-reviews @soltysh @seans3 @mengqiy