-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(channel): Manage knative eventing channels (#967)
* feat(channel): Manage knative eventing channels - Support specifying the type of channel to create using --type. - Default is to use messaging layer configuration for channels - Channel type aliases via kn config and alias for InMemoryChannel - User can now configure channel type aliases in kn config and specify alias to GVK mappings for easy reference on CLI and refer with `--type` flag - User can also use inbuilt alias 'imc' for InMemoryChannel * Let channel reconcile, sleep for 5 secs after creation * Add imcv1 and imcv1beta1 aliases * Rename imcv1 alias to imc
- Loading branch information
1 parent
a01861b
commit 5ed353d
Showing
42 changed files
with
2,523 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
## kn channel create | ||
|
||
Create an event channel | ||
|
||
### Synopsis | ||
|
||
Create an event channel | ||
|
||
``` | ||
kn channel create NAME | ||
``` | ||
|
||
### Examples | ||
|
||
``` | ||
# Create a channel 'pipe' with default setting for channel configuration | ||
kn channel create pipe | ||
# Create a channel 'imc1' of type InMemoryChannel using inbuilt alias 'imc' | ||
kn channel create imc1 --type imc | ||
# same as above without using inbuilt alias but providing explicit GVK | ||
kn channel create imc1 --type messaging.knative.dev:v1beta1:InMemoryChannel | ||
# Create a channel 'k1' of type KafkaChannel | ||
kn channel create k1 --type messaging.knative.dev:v1alpha1:KafkaChannel | ||
``` | ||
|
||
### Options | ||
|
||
``` | ||
-h, --help help for create | ||
-n, --namespace string Specify the namespace to operate in. | ||
--type string Override channel type to create, in the format '--type Group:Version:Kind'. If flag is not specified, it uses default messaging layer settings for channel type, cluster wide or specific namespace. You can configure aliases for channel types in kn config and refer the aliases with this flag. You can also refer inbuilt channel type InMemoryChannel using an alias 'imc' like '--type imc'. Examples: '--type messaging.knative.dev:v1alpha1:KafkaChannel' for specifying explicit Group:Version:Kind. | ||
``` | ||
|
||
### 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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// 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 im | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package test | ||
|
||
import ( | ||
"time" | ||
|
||
"gotest.tools/assert" | ||
|
||
"knative.dev/client/pkg/util" | ||
) | ||
|
||
func ChannelCreate(r *KnRunResultCollector, cname string, args ...string) { | ||
cmd := []string{"channel", "create", cname} | ||
cmd = append(cmd, args...) | ||
out := r.KnTest().Kn().Run(cmd...) | ||
r.AssertNoError(out) | ||
assert.Check(r.T(), util.ContainsAllIgnoreCase(out.Stdout, "channel", cname, "created")) | ||
// let channel reconcile TODO: fix the wait for channel to become ready | ||
time.Sleep(5 * time.Second) | ||
} | ||
|
||
func ChannelList(r *KnRunResultCollector, args ...string) string { | ||
cmd := []string{"channel", "list"} | ||
cmd = append(cmd, args...) | ||
out := r.KnTest().Kn().Run(cmd...) | ||
r.AssertNoError(out) | ||
return out.Stdout | ||
} | ||
|
||
func ChannelDescribe(r *KnRunResultCollector, cname string, args ...string) string { | ||
cmd := []string{"channel", "describe", cname} | ||
cmd = append(cmd, args...) | ||
out := r.KnTest().Kn().Run(cmd...) | ||
r.AssertNoError(out) | ||
return out.Stdout | ||
} | ||
|
||
func ChannelDelete(r *KnRunResultCollector, cname string) { | ||
out := r.KnTest().Kn().Run("channel", "delete", cname) | ||
r.AssertNoError(out) | ||
assert.Check(r.T(), util.ContainsAllIgnoreCase(out.Stdout, "channel", cname, "deleted")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.