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 (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ying Chun Guo authored Jun 26, 2020
1 parent 969cebc commit 49864fb
Show file tree
Hide file tree
Showing 228 changed files with 28,757 additions and 2,383 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-kafka
.DS_Store
151 changes: 106 additions & 45 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
of Kafka event source interactively from the command line.
`kn-source-kafka` is a plugin of Knative Client, for 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,
describe and delete Kafka event sources in Knative Eventing. Go to
`kn-source-kafka` is a plugin of Knative Client. You can create, describe and
delete Kafka event sources. 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,58 @@ $ hack/build.sh

**Installing:**

You will get an excuatable file `kn-source_kafka` under the directory of
You will get an executable 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`.
Install the plugin by simply copying the executable 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

Use "kafka [command] --help" for more information about a command.
#### Options

```
-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 create

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

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

create NAME

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

#### Examples

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'
kn source_kafka create mykafkasrc --servers my-cluster-kafka-bootstrap.kafka.svc:9092 --topics test-topic --consumergroup test-consumer-group --sink svc:event-display
```
#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
```

Flags:
#### 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.
--consumergroup string the consumer group ID
-h, --help help for create
Expand All @@ -80,21 +88,74 @@ 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
kn source kafka delete mykafkasrc
```

Flags:
#### 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 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

## 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, for management of Kafka event
source interactively from the command line.

## Description

`kn-source-kafka` is a plugin of Knative Client. You can create, describe and
delete Kafka event sources. 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 executable 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 the plugin by simply copying the executable file `kn-source-kafka` to
the folder of the `kn` plugins directory. You will be able to invoke it by
`kn source kafka`.
10 changes: 8 additions & 2 deletions plugins/source-kafka/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@ module knative.dev/client-contrib/plugins/source-kafka
go 1.14

require (
github.com/maximilien/kn-source-pkg v0.4.0
github.com/spf13/cobra v1.0.0 // indirect
github.com/maximilien/kn-source-pkg v0.4.8-0.20200604003102-1caadf074019
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.4
k8s.io/client-go v0.17.4
knative.dev/client v0.14.0
knative.dev/eventing-contrib v0.14.0
knative.dev/pkg v0.0.0-20200414233146-0eed424fa4ee
knative.dev/test-infra v0.0.0-20200413202711-9cf64fb1b912
)

Expand Down
Loading

0 comments on commit 49864fb

Please sign in to comment.