Commit Graph

17 Commits (b72e61edaa3976490cf2606ba3de8b90fd5d07c4)

Author SHA1 Message Date
Kubernetes Submit Queue 1737a43324
Merge pull request #66876 from juanvallejo/jvallejo/prototype-plugins
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 https://github.com/kubernetes/community/pull/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
2018-08-17 11:58:22 -07:00
Kubernetes Submit Queue d3a0bb6a84
Merge pull request #67137 from juanvallejo/jvallejo/usability-fix-kube-get
Automatic merge from submit-queue (batch tested with PRs 67137, 67372, 67505, 67373, 67357). 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>.

prevent "No resources found" output on forbidden error

**Release note**:
```release-note
NONE
```

This was originally fixed in https://github.com/kubernetes/kubernetes/pull/35115, but made its way back. Added a small test

cc @soltysh
2018-08-16 10:34:11 -07:00
juanvallejo 4bdc636380
add updated plugin mechanism 2018-08-15 15:06:29 -04:00
juanvallejo df0077f362
prevent "No resources found" output on forbidden error 2018-08-15 13:54:23 -04:00
Nikhita Raghunath 3d33301332
kubectl: update message for a no-op patch 2018-08-14 18:42:27 +05:30
Di Xu 0af6faed09 kubectl: recreating resources for immutable fields when force is applied 2018-08-09 22:59:02 +08:00
Kubernetes Submit Queue e322d1485d
Merge pull request #60316 from soltysh/create_job
Automatic merge from submit-queue. 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>.

Full blown kubectl create job

**What this PR does / why we need it**:
This is a followup to https://github.com/kubernetes/kubernetes/pull/60084 which adds full blown `create job` command

/assign @deads2k @juanvallejo 

**Release note**:

```release-note
Add kubectl create job command
```
2018-08-01 13:04:18 -07:00
Maciej Szulik 4ced88b162
Full blown kubectl create job 2018-08-01 15:04:04 +02:00
juanvallejo ad11a1b7a6
update exit code to 0 if patch not needed 2018-07-31 14:41:30 -04:00
Jordan Liggitt 84ceaf1943
ensure rs pod cleanup happens 2018-07-10 15:43:43 -04:00
Kubernetes Submit Queue 24ee75e265
Merge pull request #65880 from juanvallejo/jvallejo/fix-template-printer-rollout-cmds
Automatic merge from submit-queue (batch tested with PRs 64226, 65880). 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>.

wire PrintFlags through rollout commands

Binds PrintFlags to rollout commands.
Adds tests ensuring --template printing is supported by rollout cmds.

Fixes https://github.com/kubernetes/kubernetes/issues/65778

**Release note**:
```release-note
NONE
```

cc @soltysh @deads2k
2018-07-09 12:16:06 -07:00
Benjamin Elder 2583c12268 delete copied comment 2018-07-06 16:26:56 -07:00
Benjamin Elder 0b43710604 switch to glob 2018-07-06 16:25:28 -07:00
Benjamin Elder ca79547e92 fix visibility of testdata for //test/cmd:legacy-script 2018-07-06 16:08:20 -07:00
juanvallejo 2b0b605c80
wire PrintFlags through rollout commands
Binds PrintFlags to rollout commands.
Adds tests ensuring --template printing is supported by rollout cmds.
2018-07-06 17:32:42 -04:00
David Eads aa8110044d straight split of test-cmd 2018-07-05 11:38:26 -04:00
David Eads a6f5dddc4f move test-cmd guts to separate sig-cli maintained directory 2018-07-05 11:38:26 -04:00