-
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
- Use the default configured channel type
- Loading branch information
1 parent
582e48c
commit 524274e
Showing
25 changed files
with
1,792 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
## 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 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,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 | ||
|
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
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,66 @@ | ||
// 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" | ||
) | ||
|
||
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 | ||
} |
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,62 @@ | ||
// 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" | ||
) | ||
|
||
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 | ||
} |
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 implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package channel | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
"knative.dev/client/pkg/kn/commands" | ||
) | ||
|
||
// NewChannelDeleteCommand is for deleting a Channel | ||
func NewChannelDeleteCommand(p *commands.KnParams) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "delete NAME", | ||
Short: "Delete a channel", | ||
Example: ` | ||
# Delete a channel 'pipe' | ||
kn channel delete pipe`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
if len(args) != 1 { | ||
return errors.New("'kn channel delete' requires the name of the channel as single argument") | ||
} | ||
name := args[0] | ||
|
||
channelClient, err := newChannelClient(p, cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = channelClient.DeleteChannel(name) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Fprintf(cmd.OutOrStdout(), "Channel '%s' deleted in namespace '%s'.\n", name, channelClient.Namespace()) | ||
return nil | ||
}, | ||
} | ||
commands.AddNamespaceFlags(cmd.Flags(), false) | ||
return cmd | ||
} |
Oops, something went wrong.