This repository has been archived by the owner on Mar 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add streaming gateway list and status commands (#202)
The gateway resource is typically controlled and should not be managed, but we can observe it. Resolves #201
- Loading branch information
Showing
15 changed files
with
755 additions
and
6 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,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 | ||
|
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 @@ | ||
--- | ||
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 | ||
|
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,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 | ||
|
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,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 | ||
} |
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,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"}, | ||
} | ||
} |
Oops, something went wrong.