-
Notifications
You must be signed in to change notification settings - Fork 39.9k
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
Update the kubectl plugin mechanism #66876
Update the kubectl plugin mechanism #66876
Conversation
65668ec
to
940411e
Compare
0dbf007
to
e88d0a4
Compare
e4be68a
to
f22bb98
Compare
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.
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
return cmd | ||
} | ||
|
||
func handleEndpointExtensions(cmdArgs []string) { |
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.
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
plugins.XDGDataDirsPluginLoader(), | ||
plugins.UserDirPluginLoader(), | ||
|
||
if cmd, _, err := v.root.Find(cmdPath); err == nil { |
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.
Shouldn't you be also checking if the command is executable?
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.
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 |
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.
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
Needs 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-
.kubectl
binary. All environment variablesaccessible by
kubectl
become 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
version
subcommand.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
kubectl
command: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 (
$0
would equal/usr/local/bin/kubectl-foo
in our example above).Plugin discoverability
Seeing as how the
kubectl plugin
command 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