Renames service 'get' to 'list' (#179)

* Renames service 'get' to 'list'

 As per title.

* Renames get references to list in e2e tests

* Replaces get to list in docs
This commit is contained in:
Navid Shaikh 2019-06-14 02:26:43 +05:30 committed by Knative Prow Robot
parent e010ca816d
commit d25ea5f1e7
12 changed files with 59 additions and 51 deletions

View File

@ -41,7 +41,7 @@ See the [generated documentation.](cmd/kn.md)
A Knative service is the embodiment of a serverless workload. Generally in the form of a collection of containers running in a group of pods in the underlying Kubernetes cluster. Each Knative service associates with a collection of revisions which represents the evolution of that service.
With the Kn CLI a user can list/[`get`](cmd/kn_service_get.md), [`create`](cmd/kn_service_create.md), [`delete`](cmd/kn_service_delete.md), and [`update`](cmd/kn_service_update.md) Knative services. The [detail reference](cmd/kn_service.md) of each sub-command under the [`service` command](cmd/kn_service.md) shows the options and flags for this group of commands.
With the Kn CLI a user can [`list`](cmd/kn_service_list.md), [`create`](cmd/kn_service_create.md), [`delete`](cmd/kn_service_delete.md), and [`update`](cmd/kn_service_update.md) Knative services. The [detail reference](cmd/kn_service.md) of each sub-command under the [`service` command](cmd/kn_service.md) shows the options and flags for this group of commands.
Examples:
@ -56,10 +56,10 @@ You are able to also specify the requests and limits of both CPU and memory when
```bash
# List existing services in the 'default' namespace of your cluster
kn service get
kn service list
```
You can also list services from all namespaces or specific namespace using flags: `--all-namespaces` and `--namespace mynamespace`. See [`service get` command](cmd/kn_service_get.md) reference for additional details.
You can also list services from all namespaces or specific namespace using flags: `--all-namespaces` and `--namespace mynamespace`. See [`service list` command](cmd/kn_service_list.md) reference for additional details.
### Revision Management

View File

@ -24,6 +24,6 @@ Service command group
* [kn service create](kn_service_create.md) - Create a service.
* [kn service delete](kn_service_delete.md) - Delete a service.
* [kn service describe](kn_service_describe.md) - Describe available services.
* [kn service get](kn_service_get.md) - Get available services.
* [kn service list](kn_service_list.md) - List available services.
* [kn service update](kn_service_update.md) - Update a service.

View File

@ -1,13 +1,13 @@
## kn service get
## kn service list
Get available services.
List available services.
### Synopsis
Get available services.
List available services.
```
kn service get [flags]
kn service list [flags]
```
### Options
@ -15,7 +15,7 @@ kn service get [flags]
```
--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 get
-h, --help help for list
-n, --namespace string List the requested object(s) in given namespace.
-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].

View File

@ -13,10 +13,10 @@ kn service create hello --image gcr.io/knative-samples/helloworld-go --env TARGE
Service 'hello' successfully created in namespace 'default'.
```
* **Get service**
* **List service**
```bash
kn service get hello
kn service list hello
NAME DOMAIN GENERATION AGE CONDITIONS READY REASON
hello hello.default.example.com 1 3m5s 3 OK / 3 True
```
@ -98,9 +98,9 @@ kn service delete hello
Service 'hello' successfully deleted in namespace 'default'.
```
You can then verify that the 'hello' service is deleted by trying to `get` it again.
You can then verify that the 'hello' service is deleted by trying to `list` it again.
```bash
kn service get hello
kn service list hello
No resources found.
```

3
go.mod
View File

@ -31,6 +31,9 @@ require (
github.com/spf13/pflag v1.0.3
github.com/spf13/viper v1.3.1 // indirect
github.com/stretchr/objx v0.2.0 // indirect
go.uber.org/atomic v1.4.0 // indirect
go.uber.org/multierr v1.1.0 // indirect
go.uber.org/zap v1.10.0 // indirect
golang.org/x/net v0.0.0-20190514140710-3ec191127204 // indirect
golang.org/x/oauth2 v0.0.0-20190517181255-950ef44c6e07 // indirect
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 // indirect

5
go.sum
View File

@ -242,6 +242,7 @@ github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoH
github.com/stretchr/testify v0.0.0-20151208002404-e3a8ff8ce365/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
@ -252,10 +253,14 @@ go.opencensus.io v0.21.0 h1:mU6zScU4U1YAFPHEHYk+3JC4SY7JxgkqS10ZOSyksNg=
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
go.uber.org/atomic v1.3.2 h1:2Oa65PReHzfn29GpvgsYwloV9AVFHPDk8tYxt2c2tr4=
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.4.0 h1:cxzIVoETapQEqDhQu3QfnvXAV4AlzcvUCxkVUFw3+EU=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/multierr v1.1.0 h1:HoEmRHQPVSqub6w2z2d2EOVs2fjyFRGyofhKuyDq0QI=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/zap v1.9.1 h1:XCJQEf3W6eZaVwhRBof6ImoYGJSITeKWsyeh3HFu/5o=
go.uber.org/zap v1.9.1/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
go.uber.org/zap v1.10.0 h1:ORx85nbTijNz8ljznvCMR1ZBIPKFn3jQrag10X2AsuM=
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9 h1:mKdxBk7AujPs8kU4m80U72y/zjbZ3UcXC7dClwKbUI0=
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=

View File

@ -22,8 +22,8 @@ import (
"k8s.io/apimachinery/pkg/runtime"
)
// ServiceGetHandlers adds print handlers for service get command
func ServiceGetHandlers(h hprinters.PrintHandler) {
// ServiceListHandlers adds print handlers for service list command
func ServiceListHandlers(h hprinters.PrintHandler) {
kServiceColumnDefinitions := []metav1beta1.TableColumnDefinition{
{Name: "Name", Type: "string", Description: "Name of the knative service."},
{Name: "Domain", Type: "string", Description: "Domain name of the knative service."},

View File

@ -24,7 +24,7 @@ func NewServiceCommand(p *commands.KnParams) *cobra.Command {
Use: "service",
Short: "Service command group",
}
serviceCmd.AddCommand(NewServiceGetCommand(p))
serviceCmd.AddCommand(NewServiceListCommand(p))
serviceCmd.AddCommand(NewServiceDescribeCommand(p))
serviceCmd.AddCommand(NewServiceCreateCommand(p))
serviceCmd.AddCommand(NewServiceDeleteCommand(p))

View File

@ -23,13 +23,13 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
)
// NewServiceGetCommand represents 'kn service get' command
func NewServiceGetCommand(p *commands.KnParams) *cobra.Command {
serviceGetFlags := NewServiceGetFlags()
// NewServiceListCommand represents 'kn service list' command
func NewServiceListCommand(p *commands.KnParams) *cobra.Command {
serviceListFlags := NewServiceListFlags()
serviceGetCommand := &cobra.Command{
Use: "get",
Short: "Get available services.",
serviceListCommand := &cobra.Command{
Use: "list",
Short: "List available services.",
RunE: func(cmd *cobra.Command, args []string) error {
client, err := p.ServingFactory()
if err != nil {
@ -52,7 +52,7 @@ func NewServiceGetCommand(p *commands.KnParams) *cobra.Command {
Version: "v1alpha1",
Kind: "Service"})
printer, err := serviceGetFlags.ToPrinter()
printer, err := serviceListFlags.ToPrinter()
if err != nil {
return err
}
@ -64,7 +64,7 @@ func NewServiceGetCommand(p *commands.KnParams) *cobra.Command {
return nil
},
}
commands.AddNamespaceFlags(serviceGetCommand.Flags(), true)
serviceGetFlags.AddFlags(serviceGetCommand)
return serviceGetCommand
commands.AddNamespaceFlags(serviceListCommand.Flags(), true)
serviceListFlags.AddFlags(serviceListCommand)
return serviceListCommand
}

View File

@ -21,23 +21,23 @@ import (
"k8s.io/cli-runtime/pkg/genericclioptions"
)
// ServiceGetFlags composes common printer flag structs
// used in the Get command.
type ServiceGetFlags struct {
// ServiceListFlags composes common printer flag structs
// used in the 'kn service list' command.
type ServiceListFlags struct {
GenericPrintFlags *genericclioptions.PrintFlags
HumanReadableFlags *commands.HumanPrintFlags
}
// AllowedFormats is the list of formats in which data can be displayed
func (f *ServiceGetFlags) AllowedFormats() []string {
func (f *ServiceListFlags) AllowedFormats() []string {
formats := f.GenericPrintFlags.AllowedFormats()
formats = append(formats, f.HumanReadableFlags.AllowedFormats()...)
return formats
}
// ToPrinter attempts to find a composed set of ServiceGetFlags suitable for
// ToPrinter attempts to find a composed set of ServiceListFlags suitable for
// returning a printer based on current flag values.
func (f *ServiceGetFlags) ToPrinter() (hprinters.ResourcePrinter, error) {
func (f *ServiceListFlags) ToPrinter() (hprinters.ResourcePrinter, error) {
// if there are flags specified for generic printing
if f.GenericPrintFlags.OutputFlagSpecified() {
p, err := f.GenericPrintFlags.ToPrinter()
@ -47,7 +47,7 @@ func (f *ServiceGetFlags) ToPrinter() (hprinters.ResourcePrinter, error) {
return p, nil
}
// if no flags specified, use the table printing
p, err := f.HumanReadableFlags.ToPrinter(ServiceGetHandlers)
p, err := f.HumanReadableFlags.ToPrinter(ServiceListHandlers)
if err != nil {
return nil, err
}
@ -56,15 +56,15 @@ func (f *ServiceGetFlags) ToPrinter() (hprinters.ResourcePrinter, error) {
// AddFlags receives a *cobra.Command reference and binds
// flags related to humanreadable and template printing.
func (f *ServiceGetFlags) AddFlags(cmd *cobra.Command) {
func (f *ServiceListFlags) AddFlags(cmd *cobra.Command) {
f.GenericPrintFlags.AddFlags(cmd)
f.HumanReadableFlags.AddFlags(cmd)
}
// NewGetPrintFlags returns flags associated with humanreadable,
// NewServiceListFlags returns flags associated with humanreadable,
// template, and "name" printing, with default values set.
func NewServiceGetFlags() *ServiceGetFlags {
return &ServiceGetFlags{
func NewServiceListFlags() *ServiceListFlags {
return &ServiceListFlags{
GenericPrintFlags: genericclioptions.NewPrintFlags(""),
HumanReadableFlags: commands.NewHumanPrintFlags(),
}

View File

@ -26,7 +26,7 @@ import (
client_testing "k8s.io/client-go/testing"
)
func fakeServiceGet(args []string, response *v1alpha1.ServiceList) (action client_testing.Action, output []string, err error) {
func fakeServiceList(args []string, response *v1alpha1.ServiceList) (action client_testing.Action, output []string, err error) {
knParams := &commands.KnParams{}
cmd, fakeServing, buf := commands.CreateTestKnCommand(NewServiceCommand(knParams), knParams)
fakeServing.AddReactor("*", "*",
@ -43,8 +43,8 @@ func fakeServiceGet(args []string, response *v1alpha1.ServiceList) (action clien
return
}
func TestGetEmpty(t *testing.T) {
action, output, err := fakeServiceGet([]string{"service", "get"}, &v1alpha1.ServiceList{})
func TestListEmpty(t *testing.T) {
action, output, err := fakeServiceList([]string{"service", "list"}, &v1alpha1.ServiceList{})
if err != nil {
t.Error(err)
return
@ -58,11 +58,11 @@ func TestGetEmpty(t *testing.T) {
}
}
func TestServiceGetDefaultOutput(t *testing.T) {
func TestServiceListDefaultOutput(t *testing.T) {
service1 := createMockServiceWithParams("foo", "foo.default.example.com", 1)
service2 := createMockServiceWithParams("bar", "bar.default.example.com", 2)
serviceList := &v1alpha1.ServiceList{Items: []v1alpha1.Service{*service1, *service2}}
action, output, err := fakeServiceGet([]string{"service", "get"}, serviceList)
action, output, err := fakeServiceList([]string{"service", "list"}, serviceList)
if err != nil {
t.Fatal(err)
}

View File

@ -46,20 +46,20 @@ func TestBasicWorkflow(t *testing.T) {
teardown := Setup(t)
defer teardown(t)
testServiceGetEmpty(t, k)
testServiceListEmpty(t, k)
testServiceCreate(t, k, "hello")
testServiceGet(t, k, "hello")
testServiceList(t, k, "hello")
testServiceDescribe(t, k, "hello")
testServiceDelete(t, k, "hello")
testServiceGetEmpty(t, k)
testServiceListEmpty(t, k)
}
// Private test functions
func testServiceGetEmpty(t *testing.T, k kn) {
out, err := k.RunWithOpts([]string{"service", "get"}, runOpts{NoNamespace: false})
func testServiceListEmpty(t *testing.T, k kn) {
out, err := k.RunWithOpts([]string{"service", "list"}, runOpts{NoNamespace: false})
if err != nil {
t.Fatalf(fmt.Sprintf("Error executing 'kn service get' command. Error: %s", err.Error()))
t.Fatalf(fmt.Sprintf("Error executing 'kn service list' command. Error: %s", err.Error()))
}
if !strings.Contains(out, "No resources found.") {
@ -80,10 +80,10 @@ func testServiceCreate(t *testing.T, k kn, serviceName string) {
}
}
func testServiceGet(t *testing.T, k kn, serviceName string) {
out, err := k.RunWithOpts([]string{"service", "get", serviceName}, runOpts{NoNamespace: false})
func testServiceList(t *testing.T, k kn, serviceName string) {
out, err := k.RunWithOpts([]string{"service", "list", serviceName}, runOpts{NoNamespace: false})
if err != nil {
t.Fatalf(fmt.Sprintf("Error executing 'kn service get %s' command. Error: %s", serviceName, err.Error()))
t.Fatalf(fmt.Sprintf("Error executing 'kn service list %s' command. Error: %s", serviceName, err.Error()))
}
expectedOutput := fmt.Sprintf("%s", serviceName)