Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Update the kubectl plugin mechanism #66876
Replace the existing plugin mechanism with the design proposed in kubernetes/community#2437.
Under the new design, there is no plugin installation or loading required to use plugins.
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
#!/bin/bash # optional argument handling if [[ "$1" == "version" ]] then echo "1.0.0" exit 0 fi # optional argument handling if [[ "$1" == "config" ]] then echo $KUBECONFIG exit 0 fi echo "I am a plugin named kubectl-foo"
Using a plugin
To use a plugin, simply make it executable:
sudo chmod +x ./kubectl-foo
and place it anywhere in your PATH:
sudo mv ./kubectl-foo /usr/local/bin
You may now invoke your plugin as a
$ kubectl foo I am a plugin named kubectl-foo
All args and flags are passed as-is to the executable:
$ kubectl foo version 1.0.0
All environment variables are also passed as-is to the executable:
$ export KUBECONFIG=~/.kube/config $ kubectl foo config /home/<user>/.kube/config $ KUBECONFIG=/etc/kube/config kubectl foo config /etc/kube/config
Additionally, the first argument that is passed to a plugin will always be the full path to the location where it was invoked (
Seeing as how the
Example usage of this new subcommand is included below:
$ kubectl plugin list The following kubectl-compatible plugins are available: test/fixtures/pkg/kubectl/plugins/kubectl-foo plugins/kubectl-foo - warning: plugins/kubectl-foo is overshadowed by a similarly named plugin: test/fixtures/pkg/kubectl/plugins/kubectl-foo plugins/kubectl-invalid - warning: plugins/kubectl-invalid identified as a kubectl plugin, but it is not executable plugins/kubectl-bar error: 2 plugin warnings were found
changed the title from
Add updated plugin mechanism
Update the kubectl plugin mechanism
Aug 2, 2018
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.
[APPROVALNOTIFIER] This PR is APPROVED
Approval requirements bypassed by manually added approval.
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