Skip to content

Commit

Permalink
feat(channel): Manage knative eventing channels
Browse files Browse the repository at this point in the history
- Use the default configured channel type
  • Loading branch information
navidshaikh committed Aug 3, 2020
1 parent 582e48c commit c31e76a
Show file tree
Hide file tree
Showing 24 changed files with 1,625 additions and 7 deletions.
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 @@ kn is the command line interface for managing Knative Serving and Eventing resou
### SEE ALSO

* [kn broker](kn_broker.md) - Manage message broker
* [kn channel](kn_channel.md) - Manage event channels
* [kn completion](kn_completion.md) - Output shell completion code
* [kn options](kn_options.md) - Print the list of flags inherited by all commands
* [kn plugin](kn_plugin.md) - Manage kn plugins
Expand Down
34 changes: 34 additions & 0 deletions docs/cmd/kn_channel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
## kn channel

Manage event channels

### Synopsis

Manage event channels

```
kn channel COMMAND
```

### Options

```
-h, --help help for channel
```

### Options inherited from parent commands

```
--config string kn configuration file (default: ~/.config/kn/config.yaml)
--kubeconfig string kubectl configuration file (default: ~/.kube/config)
--log-http log http traffic
```

### SEE ALSO

* [kn](kn.md) - kn manages Knative Serving and Eventing resources
* [kn channel create](kn_channel_create.md) - Create an event channel
* [kn channel delete](kn_channel_delete.md) - Delete a channel
* [kn channel describe](kn_channel_describe.md) - Show details of a channel
* [kn channel list](kn_channel_list.md) - List channels

39 changes: 39 additions & 0 deletions docs/cmd/kn_channel_create.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
## kn channel create

Create an event channel

### Synopsis

Create an event channel

```
kn channel create NAME
```

### Examples

```
# Create a channel 'pipe' in namespace 'flow'
kn channel create pipe -n flow
```

### Options

```
-h, --help help for create
-n, --namespace string Specify the namespace to operate in.
```

### Options inherited from parent commands

```
--config string kn configuration file (default: ~/.config/kn/config.yaml)
--kubeconfig string kubectl configuration file (default: ~/.kube/config)
--log-http log http traffic
```

### SEE ALSO

* [kn channel](kn_channel.md) - Manage event channels

39 changes: 39 additions & 0 deletions docs/cmd/kn_channel_delete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
## kn channel delete

Delete a channel

### Synopsis

Delete a channel

```
kn channel delete NAME
```

### Examples

```
# Delete a channel 'pipe'
kn channel delete pipe
```

### Options

```
-h, --help help for delete
-n, --namespace string Specify the namespace to operate in.
```

### Options inherited from parent commands

```
--config string kn configuration file (default: ~/.config/kn/config.yaml)
--kubeconfig string kubectl configuration file (default: ~/.kube/config)
--log-http log http traffic
```

### SEE ALSO

* [kn channel](kn_channel.md) - Manage event channels

43 changes: 43 additions & 0 deletions docs/cmd/kn_channel_describe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
## kn channel describe

Show details of a channel

### Synopsis

Show details of a channel

```
kn channel describe NAME
```

### Examples

```
# Describe a channel 'pipe'
kn channel describe pipe
```

### Options

```
--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 describe
-n, --namespace string Specify the namespace to operate in.
-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].
-v, --verbose More output.
```

### Options inherited from parent commands

```
--config string kn configuration file (default: ~/.config/kn/config.yaml)
--kubeconfig string kubectl configuration file (default: ~/.kube/config)
--log-http log http traffic
```

### SEE ALSO

* [kn channel](kn_channel.md) - Manage event channels

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

List channels

### Synopsis

List channels

```
kn channel list
```

### Examples

```
# List all channels
kn channel list
# List channels in YAML format
kn channel ping list -o yaml
```

### 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.
--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 list
-n, --namespace string Specify the namespace to operate in.
--no-headers When using the default output format, don't print headers (default: print headers).
-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].
```

### Options inherited from parent commands

```
--config string kn configuration file (default: ~/.config/kn/config.yaml)
--kubeconfig string kubectl configuration file (default: ~/.kube/config)
--log-http log http traffic
```

### SEE ALSO

* [kn channel](kn_channel.md) - Manage event channels

4 changes: 4 additions & 0 deletions pkg/errors/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ func isEmptyConfigError(err error) bool {
//Retrieves a custom error struct based on the original error APIStatus struct
//Returns the original error struct in case it can't identify the kind of APIStatus error
func GetError(err error) error {
if err == nil {
return nil
}

switch {
case isEmptyConfigError(err):
return newNoKubeConfig(err.Error())
Expand Down
67 changes: 67 additions & 0 deletions pkg/kn/commands/channel/channel.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright © 2020 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.

package channel

import (
"github.com/spf13/cobra"

"k8s.io/client-go/tools/clientcmd"
clientv1beta1 "knative.dev/eventing/pkg/client/clientset/versioned/typed/messaging/v1beta1"

"knative.dev/client/pkg/kn/commands"
messagingv1beta1 "knative.dev/client/pkg/messaging/v1beta1"
)

// NewChannelCommand to manage event channels
func NewChannelCommand(p *commands.KnParams) *cobra.Command {
channelCmd := &cobra.Command{
Use: "channel COMMAND",
Short: "Manage event channels",
}
channelCmd.AddCommand(NewChannelCreateCommand(p))
channelCmd.AddCommand(NewChannelListCommand(p))
channelCmd.AddCommand(NewChannelDeleteCommand(p))
channelCmd.AddCommand(NewChannelDescribeCommand(p))
return channelCmd
}

var channelClientFactory func(config clientcmd.ClientConfig, namespace string) (messagingv1beta1.KnChannelsClient, error)

func newChannelClient(p *commands.KnParams, cmd *cobra.Command) (messagingv1beta1.KnChannelsClient, error) {
namespace, err := p.GetNamespace(cmd)
if err != nil {
return nil, err
}

if channelClientFactory != nil {
config, err := p.GetClientConfig()
if err != nil {
return nil, err
}
return channelClientFactory(config, namespace)
}

clientConfig, err := p.RestConfig()
if err != nil {
return nil, err
}

client, err := clientv1beta1.NewForConfig(clientConfig)
if err != nil {
return nil, err
}

return messagingv1beta1.NewKnMessagingClient(client, namespace).ChannelsClient(), nil
}
63 changes: 63 additions & 0 deletions pkg/kn/commands/channel/create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright © 2020 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.

package channel

import (
"errors"
"fmt"

"github.com/spf13/cobra"

knerrors "knative.dev/client/pkg/errors"
"knative.dev/client/pkg/kn/commands"
knmessagingv1beta1 "knative.dev/client/pkg/messaging/v1beta1"
)

// NewChannelCreateCommand to create event channels
func NewChannelCreateCommand(p *commands.KnParams) *cobra.Command {
cmd := &cobra.Command{
Use: "create NAME",
Short: "Create an event channel",
Example: `
# Create a channel 'pipe' in namespace 'flow'
kn channel create pipe -n flow`,
RunE: func(cmd *cobra.Command, args []string) (err error) {
if len(args) != 1 {
return errors.New("'kn channel create' requires the channel name given as single argument")
}
name := args[0]

namespace, err := p.GetNamespace(cmd)
if err != nil {
return err
}

client, err := newChannelClient(p, cmd)
if err != nil {
return err
}

err = client.CreateChannel(knmessagingv1beta1.NewChannelBuilder(name).Build())
if err != nil {
return knerrors.GetError(err)
}

fmt.Fprintf(cmd.OutOrStdout(), "Channel '%s' created in namespace '%s'.\n", name, namespace)
return nil
},
}
commands.AddNamespaceFlags(cmd.Flags(), false)
return cmd
}
Loading

0 comments on commit c31e76a

Please sign in to comment.