From e40766ba78a18ebc8dc2d96f3aef43c1afac4bc5 Mon Sep 17 00:00:00 2001 From: Navid Shaikh Date: Wed, 12 Jun 2019 16:34:14 +0530 Subject: [PATCH 1/3] Renames service 'get' to 'list' As per title. --- docs/cmd/kn_service.md | 2 +- .../{kn_service_get.md => kn_service_list.md} | 10 ++++----- go.mod | 3 +++ go.sum | 5 +++++ .../commands/service/human_readable_flags.go | 4 ++-- pkg/kn/commands/service/service.go | 2 +- .../{service_get.go => service_list.go} | 20 ++++++++--------- ...ice_get_flags.go => service_list_flags.go} | 22 +++++++++---------- ...rvice_get_test.go => service_list_test.go} | 10 ++++----- 9 files changed, 43 insertions(+), 35 deletions(-) rename docs/cmd/{kn_service_get.md => kn_service_list.md} (88%) rename pkg/kn/commands/service/{service_get.go => service_list.go} (77%) rename pkg/kn/commands/service/{service_get_flags.go => service_list_flags.go} (75%) rename pkg/kn/commands/service/{service_get_test.go => service_list_test.go} (88%) diff --git a/docs/cmd/kn_service.md b/docs/cmd/kn_service.md index 3483c064e5..2823e3ae3b 100644 --- a/docs/cmd/kn_service.md +++ b/docs/cmd/kn_service.md @@ -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. diff --git a/docs/cmd/kn_service_get.md b/docs/cmd/kn_service_list.md similarity index 88% rename from docs/cmd/kn_service_get.md rename to docs/cmd/kn_service_list.md index 20ece2d8da..a8148342b1 100644 --- a/docs/cmd/kn_service_get.md +++ b/docs/cmd/kn_service_list.md @@ -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]. diff --git a/go.mod b/go.mod index 0f54ce703f..304defc756 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 7e75308691..6b6b4ab24d 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/pkg/kn/commands/service/human_readable_flags.go b/pkg/kn/commands/service/human_readable_flags.go index 46a04358a9..e6ed6b9731 100644 --- a/pkg/kn/commands/service/human_readable_flags.go +++ b/pkg/kn/commands/service/human_readable_flags.go @@ -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."}, diff --git a/pkg/kn/commands/service/service.go b/pkg/kn/commands/service/service.go index f6caac007d..7a4ff8ef2a 100644 --- a/pkg/kn/commands/service/service.go +++ b/pkg/kn/commands/service/service.go @@ -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)) diff --git a/pkg/kn/commands/service/service_get.go b/pkg/kn/commands/service/service_list.go similarity index 77% rename from pkg/kn/commands/service/service_get.go rename to pkg/kn/commands/service/service_list.go index 6d78d6d6cb..bc73863b1e 100644 --- a/pkg/kn/commands/service/service_get.go +++ b/pkg/kn/commands/service/service_list.go @@ -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 } diff --git a/pkg/kn/commands/service/service_get_flags.go b/pkg/kn/commands/service/service_list_flags.go similarity index 75% rename from pkg/kn/commands/service/service_get_flags.go rename to pkg/kn/commands/service/service_list_flags.go index f54d97671e..990ad08c95 100644 --- a/pkg/kn/commands/service/service_get_flags.go +++ b/pkg/kn/commands/service/service_list_flags.go @@ -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(), } diff --git a/pkg/kn/commands/service/service_get_test.go b/pkg/kn/commands/service/service_list_test.go similarity index 88% rename from pkg/kn/commands/service/service_get_test.go rename to pkg/kn/commands/service/service_list_test.go index 8988875920..a57f35d55f 100644 --- a/pkg/kn/commands/service/service_get_test.go +++ b/pkg/kn/commands/service/service_list_test.go @@ -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) } From 67a48b94a3110564884f2e7c91686960b48d4389 Mon Sep 17 00:00:00 2001 From: Navid Shaikh Date: Wed, 12 Jun 2019 18:17:49 +0530 Subject: [PATCH 2/3] Renames get references to list in e2e tests --- test/e2e/basic_workflow_test.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/test/e2e/basic_workflow_test.go b/test/e2e/basic_workflow_test.go index d8ca1ad418..8837d2d6ed 100644 --- a/test/e2e/basic_workflow_test.go +++ b/test/e2e/basic_workflow_test.go @@ -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) From edfc141e06d35cee58a628e69a10456969700578 Mon Sep 17 00:00:00 2001 From: Navid Shaikh Date: Wed, 12 Jun 2019 18:18:48 +0530 Subject: [PATCH 3/3] Replaces get to list in docs --- docs/README.md | 6 +++--- docs/workflows.md | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/README.md b/docs/README.md index d1f1841f2e..baa6f8f2ca 100644 --- a/docs/README.md +++ b/docs/README.md @@ -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 diff --git a/docs/workflows.md b/docs/workflows.md index d091d31481..c69fb27542 100644 --- a/docs/workflows.md +++ b/docs/workflows.md @@ -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. ```