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

Add streaming gateway list and status commands #202

Merged
merged 1 commit into from
Jan 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/riff_streaming.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Functions can accept several input and/or output streams.
### SEE ALSO

* [riff](riff.md) - riff is for functions
* [riff streaming gateway](riff_streaming_gateway.md) - (experimental) stream gateway
* [riff streaming inmemory-gateway](riff_streaming_inmemory-gateway.md) - (experimental) in-memory stream gateway
* [riff streaming kafka-gateway](riff_streaming_kafka-gateway.md) - (experimental) kafka stream gateway
* [riff streaming processor](riff_streaming_processor.md) - (experimental) processors apply functions to messages on streams
Expand Down
34 changes: 34 additions & 0 deletions docs/riff_streaming_gateway.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
id: riff-streaming-gateway
title: "riff streaming gateway"
---
## riff streaming gateway

(experimental) stream gateway

### Synopsis

The gateway represents an abstract backing for streams. This resource is
typically controlled by a specific gateway implication. It may be observed, but
not directly managed.

### Options

```
-h, --help help for gateway
```

### Options inherited from parent commands

```
--config file config file (default is $HOME/.riff.yaml)
--kubeconfig file kubectl config file (default is $HOME/.kube/config)
--no-color disable color output in terminals
```

### SEE ALSO

* [riff streaming](riff_streaming.md) - (experimental) streaming runtime for riff functions
* [riff streaming gateway list](riff_streaming_gateway_list.md) - table listing of gateways
* [riff streaming gateway status](riff_streaming_gateway_status.md) - show gateway status

47 changes: 47 additions & 0 deletions docs/riff_streaming_gateway_list.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
id: riff-streaming-gateway-list
title: "riff streaming gateway list"
---
## riff streaming gateway list

table listing of gateways

### Synopsis

List gateways in a namespace or across all namespaces.

For detail regarding the status of a single gateway, run:

riff streaming gateway status <gateway-name>

```
riff streaming gateway list [flags]
```

### Examples

```
riff streaming gateway list
riff streaming gateway list --all-namespaces
```

### Options

```
--all-namespaces use all kubernetes namespaces
-h, --help help for list
-n, --namespace name kubernetes namespace (defaulted from kube config)
```

### Options inherited from parent commands

```
--config file config file (default is $HOME/.riff.yaml)
--kubeconfig file kubectl config file (default is $HOME/.kube/config)
--no-color disable color output in terminals
```

### SEE ALSO

* [riff streaming gateway](riff_streaming_gateway.md) - (experimental) stream gateway

46 changes: 46 additions & 0 deletions docs/riff_streaming_gateway_status.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
id: riff-streaming-gateway-status
title: "riff streaming gateway status"
---
## riff streaming gateway status

show gateway status

### Synopsis

Display status details for a gateway.

The Ready condition is shown which should include a reason code and a
descriptive message when the status is not "True". The status for the condition
may be: "True", "False" or "Unknown". An "Unknown" status is common while the
gateway rollout is being processed.

```
riff streaming gateway status <name> [flags]
```

### Examples

```
riff streamming gateway status my-gateway
```

### Options

```
-h, --help help for status
-n, --namespace name kubernetes namespace (defaulted from kube config)
```

### Options inherited from parent commands

```
--config file config file (default is $HOME/.riff.yaml)
--kubeconfig file kubectl config file (default is $HOME/.kube/config)
--no-color disable color output in terminals
```

### SEE ALSO

* [riff streaming gateway](riff_streaming_gateway.md) - (experimental) stream gateway

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/ghodss/yaml v1.0.0
github.com/google/go-cmp v0.4.0
github.com/mitchellh/go-homedir v1.1.0
github.com/projectriff/system v0.0.0-20200117214235-79653e435821
github.com/projectriff/system v0.0.0-20200130194255-5da2491e3c52
github.com/spf13/cobra v0.0.5
github.com/spf13/viper v1.6.2
github.com/stretchr/testify v1.4.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,8 @@ github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pquerna/cachecontrol v0.0.0-20171018203845-0dec1b30a021/go.mod h1:prYjPmNq4d1NPVmpShWobRqXY3q7Vp+80DqgxxUrUIA=
github.com/projectriff/system v0.0.0-20200117214235-79653e435821 h1:qFLJvCzTBwBr8/jsi7WGrn0y+JC8ug5OrZghexKDGJE=
github.com/projectriff/system v0.0.0-20200117214235-79653e435821/go.mod h1:Wsa2kyU4T7nTwFTeSViYvdgLW28KzYODJoIDkA2K2SE=
github.com/projectriff/system v0.0.0-20200130194255-5da2491e3c52 h1:KM+wM5qAQ+xb/q33uZkX7Forf/S3Ke8ZMYNR9JQvGN4=
github.com/projectriff/system v0.0.0-20200130194255-5da2491e3c52/go.mod h1:J22l1MKakcyHICbD2I0vfsnso9BURVokSdc4tGDW2OM=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v0.9.2/go.mod h1:OsXs2jCmiKlQ1lTBmv21f2mNfw4xf/QclQDMrYNZzcM=
github.com/prometheus/client_golang v0.9.3 h1:9iH4JKXLzFbOAdtqv/a+j8aewx2Y8lAjAydhbaScPF8=
Expand Down
42 changes: 42 additions & 0 deletions pkg/streaming/commands/gateway.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2020 the original author or 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
*
* https://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 commands

import (
"context"
"strings"

"github.com/projectriff/cli/pkg/cli"
"github.com/spf13/cobra"
)

func NewGatewayCommand(ctx context.Context, c *cli.Config) *cobra.Command {
cmd := &cobra.Command{
Use: "gateway",
Short: "(experimental) stream gateway",
Long: strings.TrimSpace(`
The gateway represents an abstract backing for streams. This resource is
typically controlled by a specific gateway implication. It may be observed, but
not directly managed.
`),
}

cmd.AddCommand(NewGatewayListCommand(ctx, c))
cmd.AddCommand(NewGatewayStatusCommand(ctx, c))

return cmd
}
136 changes: 136 additions & 0 deletions pkg/streaming/commands/gateway_list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/*
* Copyright 2020 the original author or 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
*
* https://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 commands

import (
"context"
"fmt"
"strings"
"time"

"github.com/projectriff/cli/pkg/cli"
"github.com/projectriff/cli/pkg/cli/options"
"github.com/projectriff/cli/pkg/cli/printers"
streamv1alpha1 "github.com/projectriff/system/pkg/apis/streaming/v1alpha1"
"github.com/spf13/cobra"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
metav1beta1 "k8s.io/apimachinery/pkg/apis/meta/v1beta1"
"k8s.io/apimachinery/pkg/runtime"
)

type GatewayListOptions struct {
options.ListOptions
}

var (
_ cli.Validatable = (*GatewayListOptions)(nil)
_ cli.Executable = (*GatewayListOptions)(nil)
)

func (opts *GatewayListOptions) Validate(ctx context.Context) cli.FieldErrors {
errs := cli.FieldErrors{}

errs = errs.Also(opts.ListOptions.Validate(ctx))

return errs
}

func (opts *GatewayListOptions) Exec(ctx context.Context, c *cli.Config) error {
gateways, err := c.StreamingRuntime().Gateways(opts.Namespace).List(metav1.ListOptions{})
if err != nil {
return err
}

if len(gateways.Items) == 0 {
c.Infof("No gateways found.\n")
return nil
}

tablePrinter := printers.NewTablePrinter(printers.PrintOptions{
WithNamespace: opts.AllNamespaces,
}).With(func(h printers.PrintHandler) {
columns := opts.printColumns()
h.TableHandler(columns, opts.printList)
h.TableHandler(columns, opts.print)
})

gateways = gateways.DeepCopy()
cli.SortByNamespaceAndName(gateways.Items)

return tablePrinter.PrintObj(gateways, c.Stdout)
}

func NewGatewayListCommand(ctx context.Context, c *cli.Config) *cobra.Command {
opts := &GatewayListOptions{}

cmd := &cobra.Command{
Use: "list",
Short: "table listing of gateways",
Long: strings.TrimSpace(`
List gateways in a namespace or across all namespaces.

For detail regarding the status of a single gateway, run:

` + c.Name + ` streaming gateway status <gateway-name>
`),
Example: strings.Join([]string{
fmt.Sprintf("%s streaming gateway list", c.Name),
fmt.Sprintf("%s streaming gateway list %s", c.Name, cli.AllNamespacesFlagName),
}, "\n"),
PreRunE: cli.ValidateOptions(ctx, opts),
RunE: cli.ExecOptions(ctx, c, opts),
}

cli.AllNamespacesFlag(cmd, c, &opts.Namespace, &opts.AllNamespaces)

return cmd
}

func (opts *GatewayListOptions) printList(gateways *streamv1alpha1.GatewayList, printOpts printers.PrintOptions) ([]metav1beta1.TableRow, error) {
rows := make([]metav1beta1.TableRow, 0, len(gateways.Items))
for i := range gateways.Items {
r, err := opts.print(&gateways.Items[i], printOpts)
if err != nil {
return nil, err
}
rows = append(rows, r...)
}
return rows, nil
}

func (opts *GatewayListOptions) print(gateway *streamv1alpha1.Gateway, _ printers.PrintOptions) ([]metav1beta1.TableRow, error) {
now := time.Now()
row := metav1beta1.TableRow{
Object: runtime.RawExtension{Object: gateway},
}
row.Cells = append(row.Cells,
gateway.Name,
cli.FormatEmptyString(gateway.Labels[streamv1alpha1.GatewayTypeLabelKey]),
cli.FormatConditionStatus(gateway.Status.GetCondition(streamv1alpha1.GatewayConditionReady)),
cli.FormatTimestampSince(gateway.CreationTimestamp, now),
)
return []metav1beta1.TableRow{row}, nil
}

func (opts *GatewayListOptions) printColumns() []metav1beta1.TableColumnDefinition {
return []metav1beta1.TableColumnDefinition{
{Name: "Name", Type: "string"},
{Name: "Type", Type: "string"},
{Name: "Status", Type: "string"},
{Name: "Age", Type: "string"},
}
}
Loading