Skip to content
This repository has been archived by the owner on Mar 9, 2021. It is now read-only.

Commit

Permalink
add kafka source command group
Browse files Browse the repository at this point in the history
  • Loading branch information
Daisy Guo committed May 26, 2020
1 parent 909a4c3 commit 8ca6e92
Show file tree
Hide file tree
Showing 108 changed files with 24,894 additions and 57 deletions.
2 changes: 2 additions & 0 deletions plugins/source-kafka/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
kn-source*
.DS_Store
171 changes: 132 additions & 39 deletions plugins/source-kafka/README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
## kn-source_kafka
# kn-source-kafka

`kn-source_kafka` is a plugin of Knative Client, which allows you to management
`kn-source-kafka` is a plugin of Knative Client, which allows you to management
of Kafka event source interactively from the command line.

### Description
## Description

`kn-source_kafka` is a plugin of Knative Client. You could create, update,
`kn-source-kafka` is a plugin of Knative Client. You could create, update,
describe and delete Kafka event sources in Knative Eventing. Go to
[Knative Eventing document](https://knative.dev/docs/eventing/samples/kafka/source/)
to understand more about Kafka event sources.

### Build and Install
## Build and Install

You must
[set up your development environment](https://github.com/knative/client/blob/master/docs/DEVELOPMENT.md#prerequisites)
before you build `kn-source_kafka`.
before you build `kn-source-kafka`.

**Building:**

Once you've set up your development environment, let's build `kn-source_kafka`.
Once you've set up your development environment, let's build `kn-source-kafka`.
Run below command under the directory of `client-contrib/plugins/source-kafka`.

```sh
Expand All @@ -27,50 +27,59 @@ $ hack/build.sh

**Installing:**

You will get an excuatable file `kn-source_kafka` under the directory of
You will get an excuatable file `kn-source-kafka` under the directory of
`client-contrib/plugins/source-kafka` after you run the build command. Then
let's install it to become a Knative Client `kn` plugin.

Install a plugin by simply copying the excuatable file `kn-source_kafka` to the
Install a plugin by simply copying the excuatable file `kn-source-kafka` to the
folder of the `kn` plugins directory. You will be able to invoke it by
`kn source_kafka`.

### Usage
## Usage

```
$ kn source_kafka
Manage your Knative Kafka eventing sources
### kafka

Usage:
kafka [command]
Knative eventing Kafka source plugin

Available Commands:
create create NAME
delete delete NAME
describe describe NAME
help Help about any command
update update NAME
#### Synopsis

Flags:
-h, --help help for kafka
Manage your Knative Kafka eventing sources

#### Options

Use "kafka [command] --help" for more information about a command.
```
-h, --help help for kafka
```

#### `kn source_kafka create`
#### SEE ALSO

- [kafka create](#kafka-create) - create NAME
- [kafka delete](#kafka-delete) - delete NAME
- [kafka describe](#kafka-describe) - describe NAME
- [kafka update](#kafka-update) - update NAME

### kafka create

```
$ kn source_kafka create --help
create NAME

Usage:
kafka create NAME [flags]
#### Synopsis

Examples:
#Creates a new Kafka source with mykafkasrc which subscribes a Kafka server 'my-cluster-kafka-bootstrap.kafka.svc:9092' at topic 'test-topic' using the consumer group ID 'test-consumer-group' and sends the event messages to service 'event-display'
create NAME

```
kafka create NAME [flags]
```

#### Examples

```
#Creates a new Kafka source named as 'mykafkasrc' which subscribes a Kafka server 'my-cluster-kafka-bootstrap.kafka.svc:9092' at topic 'test-topic' using the consumer group ID 'test-consumer-group' and sends the event messages to service 'event-display'
kn source_kafka create mykafkasrc --servers my-cluster-kafka-bootstrap.kafka.svc:9092 --topics test-topic --consumergroup test-consumer-group --sink svc:event-display
```

#### Options

Flags:
```
-A, --all-namespaces If present, list the requested object(s) across all namespaces. Namespace in current context is ignored even if specified with --namespace.
--consumergroup string the consumer group ID
-h, --help help for create
Expand All @@ -80,21 +89,105 @@ Flags:
--topics string Topics to consume messages from
```

#### `kn source_kafka delete`
#### SEE ALSO

- [kafka](#kafka) - Knative eventing Kafka source plugin

### kafka delete

delete NAME

#### Synopsis

```
$ kn source_kafka delete --help
delete a Kafka source

Usage:
kafka delete NAME [flags]
```
kafka delete NAME [flags]
```

#### Examples

Examples:
```
#Deletes a Kafka source with name 'mykafkasrc'
kn source_kafka delete mykafkasrc
```

#### Options

Flags:
```
-A, --all-namespaces If present, list the requested object(s) across all namespaces. Namespace in current context is ignored even if specified with --namespace.
-h, --help help for delete
-n, --namespace string Specify the namespace to operate in.
```

#### SEE ALSO

- [kafka](#kafka) - Knative eventing Kafka source plugin

### kafka describe

describe NAME

#### Synopsis

update a Kafka source

```
kafka describe NAME [flags]
```

#### Examples

```
#Describes a Kafka source with NAME
kn source_kafka describe kafka-name
```

#### Options

```
-A, --all-namespaces If present, list the requested object(s) across all namespaces. Namespace in current context is ignored even if specified with --namespace.
-h, --help help for describe
-n, --namespace string Specify the namespace to operate in.
```

#### SEE ALSO

- [kafka](#kafka) - Knative eventing Kafka source plugin

### kafka update

update NAME

#### Synopsis

update a Kafka source

```
kafka update NAME [flags]
```

#### Examples

```
#Updates a Kafka source with NAME
kn source_kafka update kafka-name --servers my-cluster-kafka-bootstrap.kafka.svc:9092 --topics test-topic --consumergroup test-consumer-group --sink svc:event-display
```

#### Options

```
-A, --all-namespaces If present, list the requested object(s) across all namespaces. Namespace in current context is ignored even if specified with --namespace.
-h, --help help for update
-n, --namespace string Specify the namespace to operate in.
-s, --sink string Addressable sink for events
```

#### SEE ALSO

- [kafka](#kafka) - Knative eventing Kafka source plugin

## More information

- [Knative Client](https://github.com/knative/client)
- [How to contribute a plugin](https://github.com/knative/client-contrib#how-to-contribute-a-plugin)
22 changes: 20 additions & 2 deletions plugins/source-kafka/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,27 @@
package main

import (
"github.com/maximilien/kn-source-pkg/pkg/factories"
"fmt"
"os"

"github.com/maximilien/kn-source-pkg/pkg/core"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
_ "k8s.io/client-go/plugin/pkg/client/auth/oidc"
"knative.dev/client-contrib/plugins/source-kafka/pkg/factories"
)

func main() {
factories.NewDefaultKnSourceFactory()
kafkaSourceFactory := factories.NewKafkaSourceFactory()

kafkaCommandFactory := factories.NewKafkaSourceCommandFactory(kafkaSourceFactory)
kafkaFlagsFactory := factories.NewKafkaSourceFlagsFactory(kafkaSourceFactory)
kafkaRunEFactory := factories.NewKafkaSourceRunEFactory(kafkaSourceFactory)

err := core.NewKnSourceCommand(kafkaSourceFactory, kafkaCommandFactory, kafkaFlagsFactory, kafkaRunEFactory).Execute()
if err != nil {
if err.Error() != "subcommand is required" {
fmt.Fprintln(os.Stderr, err)
}
os.Exit(1)
}
}
36 changes: 36 additions & 0 deletions plugins/source-kafka/docs/header.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# kn-source-kafka

`kn-source-kafka` is a plugin of Knative Client, which allows you to management
of Kafka event source interactively from the command line.

## Description

`kn-source-kafka` is a plugin of Knative Client. You could create, update,
describe and delete Kafka event sources in Knative Eventing. Go to
[Knative Eventing document](https://knative.dev/docs/eventing/samples/kafka/source/)
to understand more about Kafka event sources.

## Build and Install

You must
[set up your development environment](https://github.com/knative/client/blob/master/docs/DEVELOPMENT.md#prerequisites)
before you build `kn-source-kafka`.

**Building:**

Once you've set up your development environment, let's build `kn-source-kafka`.
Run below command under the directory of `client-contrib/plugins/source-kafka`.

```sh
$ hack/build.sh
```

**Installing:**

You will get an excuatable file `kn-source-kafka` under the directory of
`client-contrib/plugins/source-kafka` after you run the build command. Then
let's install it to become a Knative Client `kn` plugin.

Install a plugin by simply copying the excuatable file `kn-source-kafka` to the
folder of the `kn` plugins directory. You will be able to invoke it by
`kn source_kafka`.
8 changes: 7 additions & 1 deletion plugins/source-kafka/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@ go 1.13

require (
github.com/maximilien/kn-source-pkg v0.4.0
github.com/spf13/cobra v1.0.0 // indirect
github.com/spf13/cobra v1.0.0
github.com/spf13/pflag v1.0.5
gotest.tools v2.2.0+incompatible
k8s.io/apimachinery v0.17.0
k8s.io/client-go v0.17.0
knative.dev/client v0.13.1-0.20200406212659-8a60d2ebf8e2
knative.dev/eventing-contrib v0.14.0
knative.dev/pkg v0.0.0-20200404181734-92cdec5b3593
knative.dev/test-infra v0.0.0-20200413202711-9cf64fb1b912
)

Expand Down
4 changes: 4 additions & 0 deletions plugins/source-kafka/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7
github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/coreos/pkg v0.0.0-20180108230652-97fdf19511ea/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng4PGlyM=
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
github.com/davecgh/go-spew v0.0.0-20151105211317-5215b55f46b2/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -248,6 +249,7 @@ github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5
github.com/maxbrunsfeld/counterfeiter/v6 v6.2.2/go.mod h1:eD9eIE7cdwcMi9rYluz88Jz2VyhSmden33/aXg4oVIY=
github.com/maximilien/kn-source-pkg v0.4.0 h1:YmSHyu3dfQ3K736fn8J3dSCZRNkm2RJaC/DQ7QnIcsg=
github.com/maximilien/kn-source-pkg v0.4.0/go.mod h1:EDa7rFyEq3i2X02NaP1/pnrg+yVUlWPOS4CCZaZwCx0=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
Expand Down Expand Up @@ -319,9 +321,11 @@ github.com/robfig/cron v1.2.0/go.mod h1:JGuDeoQd7Z6yL4zQhZ3OPEVHB7fL6Ka6skscFHfm
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rubiojr/go-vhd v0.0.0-20160810183302-0bfd3b39853c/go.mod h1:DM5xW0nvfNNm2uytzsvhI3OnX8uzaRAg8UX/CnDqbto=
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/sclevine/spec v1.2.0/go.mod h1:W4J29eT/Kzv7/b9IWLB055Z+qvVC9vt0Arko24q7p+U=
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
Expand Down
Loading

0 comments on commit 8ca6e92

Please sign in to comment.