Skip to content
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

Add kubectl plugin mechanism KEP #2437

Merged
merged 2 commits into from
Aug 16, 2018

Conversation

juanvallejo
Copy link
Contributor

cc @soltysh @seans3

Adds proposal describing an updated, git-style plugin mechanism.

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. sig/architecture Categorizes an issue or PR as relevant to SIG Architecture. labels Jul 30, 2018
@juanvallejo
Copy link
Contributor Author

cc @kubernetes/sig-cli-maintainers @kubernetes/sig-cli-feature-requests

@k8s-ci-robot k8s-ci-robot added sig/cli Categorizes an issue or PR as relevant to SIG CLI. kind/feature Categorizes issue or PR as related to a new feature. labels Jul 31, 2018
@mikedanese
Copy link
Member

Can we add kubectl to the title? Kubernetes has a lot of different types of plugins.

@juanvallejo juanvallejo changed the title Add updated plugin mechanism KEP Add kubectl plugin mechanism KEP Aug 2, 2018
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 2, 2018
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 8, 2018
@philips
Copy link
Contributor

philips commented Aug 8, 2018

Can you add some color on why plugins are useful? I get the technical details but I don't know what the goal is. Thanks!

@juanvallejo
Copy link
Contributor Author

@philips

Can you add some color on why plugins are useful? I get the technical details but I don't know what the goal is. Thanks!

Sure, will update KEP to expand more on this

@juanvallejo
Copy link
Contributor Author

Updated Motivation section to expand on the reasoning for having plugins.

@philips
Copy link
Contributor

philips commented Aug 9, 2018

@juanvallejo thanks, looks good.

Copy link
Contributor

@soltysh soltysh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 15, 2018
@soltysh
Copy link
Contributor

soltysh commented Aug 15, 2018

This topic was discussed for almost past 6 months during various SIG-CLI meetings. The KEP itself was posted few weeks ago and was broadcast to kubernetes-dev and sig-cli ML. During today's SIG-CLI there were no objections so I'm approving this PR as is.

@philips
Copy link
Contributor

philips commented Aug 15, 2018 via email

@soltysh
Copy link
Contributor

soltysh commented Aug 16, 2018

/approve

@soltysh
Copy link
Contributor

soltysh commented Aug 16, 2018

@cblecker mind approving the KEP number bump for this one?

@cblecker
Copy link
Member

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cblecker, 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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 16, 2018
@k8s-ci-robot k8s-ci-robot merged commit bf64c8b into kubernetes:master Aug 16, 2018
@juanvallejo juanvallejo deleted the jvallejo/add-plugins-kep branch August 16, 2018 20:29
k8s-github-robot pushed a commit to kubernetes/kubernetes that referenced this pull request Aug 17, 2018
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 <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Update the kubectl plugin mechanism

**Release note**:
```release-note
The plugin mechanism functionality to closely follow the git plugin design
```

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-`.
- Plugins receive the inherited environment from the `kubectl` binary. All environment variables
accessible by `kubectl` become accessible by the plugin.
- Plugins decide which command path they wish to implement based on their name. For example, a plugin wanting to provide a new command `foo`, would simply be named `kubectl-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.

```bash
#!/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:

```bash
sudo chmod +x ./kubectl-foo
```

and place it anywhere in your PATH:

```bash
sudo mv ./kubectl-foo /usr/local/bin
```

You may now invoke your plugin as a `kubectl` command:

```bash
$ kubectl foo
I am a plugin named kubectl-foo
```

All args and flags are passed as-is to the executable:

```bash
$ kubectl foo version
1.0.0
```

All environment variables are also passed as-is to the executable:

```bash
$ 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 (`$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:

```bash
$ 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
```

cc @kubernetes/kubectl-maintainers @kubernetes/sig-cli-pr-reviews @soltysh @seans3 @mengqiy
@carolynvs
Copy link
Contributor

I haven't been following the dev list closely enough lately, but I just resurfaced and saw this 🎁. Exciting to see us moving forward with plugins!

@soltysh
Copy link
Contributor

soltysh commented Aug 28, 2018

Yes! And thank you for your patience Carolyn :)

calebamiles pushed a commit to calebamiles/community that referenced this pull request Sep 5, 2018
…ins-kep

Add kubectl plugin mechanism KEP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. sig/architecture Categorizes an issue or PR as relevant to SIG Architecture. sig/cli Categorizes an issue or PR as relevant to SIG CLI. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants