Skip to content

Commit

Permalink
[WIP] Kn plugins implementation
Browse files Browse the repository at this point in the history
Implements Kn plugins re-using some code from kubectl plugins.
This is WIP to allow concrete discussions and testing and
hopefully also allow sub tasks to be created and worked on
in parallel.

This version contains the following:

1. wraps the main root Kn command to support plugin
2. plugins are any executable in PATH with name kn-*
3. 'kn plugins list' to list found kn plugins
4. skips any kn plugins found with name that match core
   commands, e.g., kn-service would be ignored
5. execute any valid kn plugins found

And is missing:

1. unit and integration tests
2. plugin install command
3. plugin repository command
4. plugin / Knative server version negotiation
5. anything else we agree on in plugin req doc

Adds a Golang version of e2e Basic workflow that can execute locally (#121)

1. creates a namespace 'kne2etests' (default name, change with env KN_E2E_NAMESPACE)
2. executes kn commands as per Basic workflow doc in said namespace
3. verifies each command's output
4. deletes the 'kne2etests' namespace

Fix typo in README.md (#181)

Renames service 'get' to 'list' (#179)

* Renames service 'get' to 'list'

 As per title.

* Renames get references to list in e2e tests

* Replaces get to list in docs

Renames revision 'get' to 'list' (#180)

* Renames revision 'get' to 'list'

 As per title.

* Renames revision get references to revision list in docs

feat(build.sh) - Add mandatory license check (#187)

We could decide to make that optional, too, if this is coming into the way.

Chore: Fix typos in docs (#178)

fix(service update): Print success message after successful update (#169)

* fix(service update): Print success message after successful update

* chore(service update): Improve test, revert unneeded changes

[WIP] Kn plugins implementation

Implements Kn plugins re-using some code from kubectl plugins.
This is WIP to allow concrete discussions and testing and
hopefully also allow sub tasks to be created and worked on
in parallel.

This version contains the following:

1. wraps the main root Kn command to support plugin
2. plugins are any executable in PATH with name kn-*
3. 'kn plugins list' to list found kn plugins
4. skips any kn plugins found with name that match core
   commands, e.g., kn-service would be ignored
5. execute any valid kn plugins found
6. started adding UTs for plugin commands and files
7. rebased with latest HEAD

And is missing:

1. integration tests
2. plugin install command
3. plugin repository command
4. plugin / Knative server version negotiation
5. anything else we agree on in plugin req doc
  • Loading branch information
maximilien committed Jun 17, 2019
1 parent 0d94947 commit 536af45
Show file tree
Hide file tree
Showing 223 changed files with 184,498 additions and 110 deletions.
10 changes: 5 additions & 5 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Development

This doc explains how to setup a development environment so you can get started
This doc explains how to set up a development environment so you can get started
[contributing](https://www.knative.dev/contributing/) to `Knative Client`.
Also take a look at:

Expand All @@ -16,7 +16,7 @@ Before submitting a PR, see also [contribution guide](https://www.knative.dev/co

### Sign up for GitHub

Start by creating [a GitHub account](https://github.com/join), then setup
Start by creating [a GitHub account](https://github.com/join), then set up
[GitHub access via SSH](https://help.github.com/articles/connecting-to-github-with-ssh/).

### Install requirements
Expand All @@ -31,7 +31,7 @@ You must install these tools:

### Create a cluster

1. [Set up a Knative](https://www.knative.dev/docs/install/), You can also setup using limited install guides like [Minikube](https://knative.dev/docs/install/knative-with-minikube/) or [Minishift](https://knative.dev/docs/install/knative-with-minishift/).
1. [Set up a Knative](https://www.knative.dev/docs/install/), You can also set up using limited install guides like [Minikube](https://knative.dev/docs/install/knative-with-minikube/) or [Minishift](https://knative.dev/docs/install/knative-with-minishift/).

### Checkout your fork

Expand All @@ -55,7 +55,7 @@ described below.

## Building Knative Client

Once you've [setup your development environment](#prerequisites), let's build
Once you've [set up your development environment](#prerequisites), let's build
`Knative Client`.

**Dependencies:**
Expand All @@ -79,7 +79,7 @@ You can link that script into a directory within your search `$PATH`. This allow

See `build.sh --help` for a full list of options and usage examples.

At the end, the build results in `kn` binary in your current directory, which can be directly executed.
In the end, the build results in `kn` binary in your current directory, which can be directly executed.

**Notes:**

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Goals:

# Docs

Start with the [user's guide](docs/README.md) and from there you can can read about common use cases, get detail docs on each command, and even how to extend the `kn` CLI. Links below for easy access.
Start with the [user's guide](docs/README.md) and from there you can read about common use cases, get detail docs on each command, and even how to extend the `kn` CLI. Links below for easy access.

* [User's guide](docs/README.md)
* [Basic workflows](docs/workflows.md) (use cases)
Expand Down
2 changes: 1 addition & 1 deletion cmd/kn/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func init() {
}

func main() {
err := core.NewKnCommand().Execute()
err := core.NewDefaultKnCommand().Execute()
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
Expand Down
16 changes: 8 additions & 8 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# kn

`kn` is the Knative command line interface (CLI).
`kn` is the Knative command line interface (CLI).

## Getting Started

### Installing `kn`

You can grab the latest nightly binary executable for:
* [Max OS X](https://storage.cloud.google.com/knative-nightly/client/latest/kn-darwin-amd64)
* [Linix AMD 64](https://storage.googleapis.com/knative-nightly/client/latest/kn-linux-amd64)
* [Linux AMD 64](https://storage.googleapis.com/knative-nightly/client/latest/kn-linux-amd64)
* [Windows AMD 64](https://storage.googleapis.com/knative-nightly/client/latest/kn-windows-amd64.exe)

Put it on your system path, and make sure it's executable.
Expand Down Expand Up @@ -41,7 +41,7 @@ See the [generated documentation.](cmd/kn.md)

A Knative service is the embodiment of a serverless workload. Generally in the form of a collection of containers running in a group of pods in the underlying Kubernetes cluster. Each Knative service associates with a collection of revisions which represents the evolution of that service.

With the Kn CLI a user can list/[`get`](cmd/kn_service_get.md), [`create`](cmd/kn_service_create.md), [`delete`](cmd/kn_service_delete.md), and [`update`](cmd/kn_service_update.md) Knative services. The [detail reference](cmd/kn_service.md) of each sub-command under the [`service` command](cmd/kn_service.md) shows the options and flags for this group of commands.
With the Kn CLI a user can [`list`](cmd/kn_service_list.md), [`create`](cmd/kn_service_create.md), [`delete`](cmd/kn_service_delete.md), and [`update`](cmd/kn_service_update.md) Knative services. The [detail reference](cmd/kn_service.md) of each sub-command under the [`service` command](cmd/kn_service.md) shows the options and flags for this group of commands.

Examples:

Expand All @@ -56,23 +56,23 @@ You are able to also specify the requests and limits of both CPU and memory when
```bash
# List existing services in the 'default' namespace of your cluster

kn service get
kn service list
```

You can also list services from all namespaces or specific namespace using flags: `--all-namespaces` and `--namespace mynamespace`. See [`service get` command](cmd/kn_service_get.md) reference for additional details.
You can also list services from all namespaces or specific namespace using flags: `--all-namespaces` and `--namespace mynamespace`. See [`service list` command](cmd/kn_service_list.md) reference for additional details.

### Revision Management

A Knative revision is a "snapshot" of the specification of a service. For instance, when a Knative service is created with environment variable `FOO=bar` a revision is added to the service. When later the environment variable is changed to `baz` or additional variables are added, a new revision is created. When the image the service is running is changed to a new digest, a new revision is created.
A Knative revision is a "snapshot" of the specification of a service. For instance, when a Knative service is created with environment variable `FOO=bar` a revision is added to the service. When later the environment variable is changed to `baz` or additional variables are added, a new revision is created. When the image the service is running is changed to a new digest, a new revision is created.

With the [`revision` command group](cmd/kn_revision.md) you can list/[get](cmd/kn_revision_get.md) and [describe](cmd/kn_revision_describe.md) the current revisions on a service.
With the [`revision` command group](cmd/kn_revision.md) you can [list](cmd/kn_revision_list.md) and [describe](cmd/kn_revision_describe.md) the current revisions on a service.

Examples:

```bash
# Listing a service's revision

kn revision get --service srvc # CHECK this since current command does not have --service flag
kn revision list --service srvc # CHECK this since current command does not have --service flag
```

### Utilities
Expand Down
1 change: 1 addition & 0 deletions docs/cmd/kn.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Eventing: Manage event subscriptions and channels. Connect up event sources.
### SEE ALSO

* [kn completion](kn_completion.md) - Output shell completion code (default Bash)
* [kn plugin](kn_plugin.md) - Plugin command group
* [kn revision](kn_revision.md) - Revision command group
* [kn service](kn_service.md) - Service command group
* [kn version](kn_version.md) - Prints the client version
Expand Down
28 changes: 28 additions & 0 deletions docs/cmd/kn_plugin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
## kn plugin

Plugin command group

### Synopsis

Provides utilities for interacting with plugins.

Plugins provide extended functionality that is not part of the major command-line distribution.
Please refer to the documentation and examples for more information about how write your own plugins.

### Options

```
-h, --help help for plugin
```

### Options inherited from parent commands

```
--kubeconfig string kubectl config file (default is $HOME/.kube/config)
```

### SEE ALSO

* [kn](kn.md) - Knative client
* [kn plugin list](kn_plugin_list.md) - list all visible plugin executables on a user's PATH

34 changes: 34 additions & 0 deletions docs/cmd/kn_plugin_list.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
## kn plugin list

list all visible plugin executables on a user's PATH

### Synopsis

List all available plugin files on a user's PATH.

Available plugin files are those that are:
- executable
- anywhere on the user's PATH
- begin with "kn-

```
kn plugin list [flags]
```

### Options

```
-h, --help help for list
--name-only If true, display only the binary name of each plugin, rather than its full path
```

### Options inherited from parent commands

```
--kubeconfig string kubectl config file (default is $HOME/.kube/config)
```

### SEE ALSO

* [kn plugin](kn_plugin.md) - Plugin command group

2 changes: 1 addition & 1 deletion docs/cmd/kn_revision.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ Revision command group

* [kn](kn.md) - Knative client
* [kn revision describe](kn_revision_describe.md) - Describe revisions.
* [kn revision get](kn_revision_get.md) - Get available revisions.
* [kn revision list](kn_revision_list.md) - List available revisions.

10 changes: 5 additions & 5 deletions docs/cmd/kn_revision_get.md → docs/cmd/kn_revision_list.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
## kn revision get
## kn revision list

Get available revisions.
List available revisions.

### Synopsis

Get available revisions.
List available revisions.

```
kn revision get [flags]
kn revision list [flags]
```

### Options

```
--all-namespaces If present, list the requested object(s) across all namespaces. Namespace in current context is ignored even if specified with --namespace.
--allow-missing-template-keys If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats. (default true)
-h, --help help for get
-h, --help help for list
-n, --namespace string List the requested object(s) in given namespace.
-o, --output string Output format. One of: json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file.
--template string Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview].
Expand Down
2 changes: 1 addition & 1 deletion docs/cmd/kn_service.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ Service command group
* [kn service create](kn_service_create.md) - Create a service.
* [kn service delete](kn_service_delete.md) - Delete a service.
* [kn service describe](kn_service_describe.md) - Describe available services.
* [kn service get](kn_service_get.md) - Get available services.
* [kn service list](kn_service_list.md) - List available services.
* [kn service update](kn_service_update.md) - Update a service.

10 changes: 5 additions & 5 deletions docs/cmd/kn_service_get.md → docs/cmd/kn_service_list.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
## kn service get
## kn service list

Get available services.
List available services.

### Synopsis

Get available services.
List available services.

```
kn service get [flags]
kn service list [flags]
```

### Options

```
--all-namespaces If present, list the requested object(s) across all namespaces. Namespace in current context is ignored even if specified with --namespace.
--allow-missing-template-keys If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats. (default true)
-h, --help help for get
-h, --help help for list
-n, --namespace string List the requested object(s) in given namespace.
-o, --output string Output format. One of: json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file.
--template string Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview].
Expand Down
8 changes: 4 additions & 4 deletions docs/workflows.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ kn service create hello --image gcr.io/knative-samples/helloworld-go --env TARGE
Service 'hello' successfully created in namespace 'default'.
```

* **Get service**
* **List service**

```bash
kn service get hello
kn service list hello
NAME DOMAIN GENERATION AGE CONDITIONS READY REASON
hello hello.default.example.com 1 3m5s 3 OK / 3 True
```
Expand Down Expand Up @@ -98,9 +98,9 @@ kn service delete hello
Service 'hello' successfully deleted in namespace 'default'.
```

You can then verify that the 'hello' service is deleted by trying to `get` it again.
You can then verify that the 'hello' service is deleted by trying to `list` it again.

```bash
kn service get hello
kn service list hello
No resources found.
```
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,16 @@ require (
github.com/mattbaird/jsonpatch v0.0.0-20171005235357-81af80346b1a // indirect
github.com/mitchellh/go-homedir v1.1.0
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/onsi/ginkgo v0.0.0-20170829012221-11459a886d9c
github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/spf13/cobra v0.0.3
github.com/spf13/pflag v1.0.3
github.com/spf13/viper v1.3.1 // indirect
github.com/stretchr/objx v0.2.0 // indirect
go.uber.org/atomic v1.4.0 // indirect
go.uber.org/multierr v1.1.0 // indirect
go.uber.org/zap v1.10.0 // indirect
golang.org/x/net v0.0.0-20190514140710-3ec191127204 // indirect
golang.org/x/oauth2 v0.0.0-20190517181255-950ef44c6e07 // indirect
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 // indirect
Expand Down
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoH
github.com/stretchr/testify v0.0.0-20151208002404-e3a8ff8ce365/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
Expand All @@ -252,10 +253,14 @@ go.opencensus.io v0.21.0 h1:mU6zScU4U1YAFPHEHYk+3JC4SY7JxgkqS10ZOSyksNg=
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
go.uber.org/atomic v1.3.2 h1:2Oa65PReHzfn29GpvgsYwloV9AVFHPDk8tYxt2c2tr4=
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.4.0 h1:cxzIVoETapQEqDhQu3QfnvXAV4AlzcvUCxkVUFw3+EU=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/multierr v1.1.0 h1:HoEmRHQPVSqub6w2z2d2EOVs2fjyFRGyofhKuyDq0QI=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/zap v1.9.1 h1:XCJQEf3W6eZaVwhRBof6ImoYGJSITeKWsyeh3HFu/5o=
go.uber.org/zap v1.9.1/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
go.uber.org/zap v1.10.0 h1:ORx85nbTijNz8ljznvCMR1ZBIPKFn3jQrag10X2AsuM=
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9 h1:mKdxBk7AujPs8kU4m80U72y/zjbZ3UcXC7dClwKbUI0=
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
Expand Down
14 changes: 14 additions & 0 deletions hack/build-flags.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2019 The Knative Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

function build_flags() {
local base="${1}"
local now="$(date -u '+%Y-%m-%d %H:%M:%S')"
Expand Down
32 changes: 31 additions & 1 deletion hack/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ run() {
# Format source code
go_fmt

# Generate docs
# Check for license headers
check_license

# Auto generate cli docs
generate_docs
fi

Expand Down Expand Up @@ -98,6 +101,33 @@ go_test() {
rm $test_output
}

check_license() {
echo "⚖️ License"
local required_keywords=("Authors" "Apache License" "LICENSE-2.0")
local extensions_to_check=("sh" "go" "yaml" "yml" "json")

local check_output=$(mktemp /tmp/kn-client-licence-check.XXXXXX)
for ext in "${extensions_to_check[@]}"; do
find . -name "*.$ext" -a \! -path "./vendor/*" -a \! -path "./.*" -print0 |
while IFS= read -r -d '' path; do
for rword in "${required_keywords[@]}"; do
if ! grep -q "$rword" "$path"; then
echo " $path" >> $check_output
fi
done
done
done
if [ -s $check_output ]; then
echo "🔥 No license header found in:"
cat $check_output | sort | uniq
echo "🔥 Please fix and retry."
rm $check_output
exit 1
fi
rm $check_output
}


update_deps() {
echo "🕸️ Update"
go mod vendor
Expand Down
Loading

0 comments on commit 536af45

Please sign in to comment.