From a0f13548a6cbefc24cbbde25f3b01efd1095ab49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20Hu=C3=9F?= Date: Tue, 10 Mar 2020 18:04:28 +0100 Subject: [PATCH] chore(service export): Rename `--history` to `--with-revisions` (#729) --- docs/cmd/kn_service_export.md | 2 +- pkg/kn/commands/service/export.go | 22 +++++++++++----------- pkg/kn/commands/service/export_test.go | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/docs/cmd/kn_service_export.md b/docs/cmd/kn_service_export.md index f9491301d8..5c2b726699 100644 --- a/docs/cmd/kn_service_export.md +++ b/docs/cmd/kn_service_export.md @@ -25,10 +25,10 @@ kn service export NAME [flags] ``` --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 export - -r, --history Export all active revisions -n, --namespace string Specify the namespace to operate in. -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]. + --with-revisions Export all routed revisions (experimental) ``` ### Options inherited from parent commands diff --git a/pkg/kn/commands/service/export.go b/pkg/kn/commands/service/export.go index a2cf1aa726..1b34abb92f 100644 --- a/pkg/kn/commands/service/export.go +++ b/pkg/kn/commands/service/export.go @@ -70,7 +70,7 @@ func NewServiceExportCommand(p *commands.KnParams) *cobra.Command { return err } - history, err := cmd.Flags().GetBool("history") + withRevisions, err := cmd.Flags().GetBool("with-revisions") if err != nil { return err } @@ -80,8 +80,8 @@ func NewServiceExportCommand(p *commands.KnParams) *cobra.Command { return err } - if history { - if svcList, err := exportServicewithActiveRevisions(service, client); err != nil { + if withRevisions { + if svcList, err := exportServiceWithActiveRevisions(service, client); err != nil { return err } else { return printer.PrintObj(svcList, cmd.OutOrStdout()) @@ -92,7 +92,7 @@ func NewServiceExportCommand(p *commands.KnParams) *cobra.Command { } flags := command.Flags() commands.AddNamespaceFlags(flags, false) - flags.BoolP("history", "r", false, "Export all active revisions") + flags.Bool("with-revisions", false, "Export all routed revisions (experimental)") machineReadablePrintFlags.AddFlags(command) return command } @@ -135,22 +135,19 @@ func constructServicefromRevision(latestSvc *servingv1.Service, revision serving return exportedSvc } -func exportServicewithActiveRevisions(latestSvc *servingv1.Service, client clientservingv1.KnServingClient) (*servingv1.ServiceList, error) { +func exportServiceWithActiveRevisions(latestSvc *servingv1.Service, client clientservingv1.KnServingClient) (*servingv1.ServiceList, error) { var exportedSvcItems []servingv1.Service //get revisions to export from traffic revsMap := getRevisionstoExport(latestSvc) - var params []clientservingv1.ListConfig - params = append(params, clientservingv1.WithService(latestSvc.ObjectMeta.Name)) - // Query for list with filters - revisionList, err := client.ListRevisions(params...) + revisionList, err := client.ListRevisions(clientservingv1.WithService(latestSvc.ObjectMeta.Name)) if err != nil { return nil, err } if len(revisionList.Items) == 0 { - return nil, fmt.Errorf("No revisions found for the service %s", latestSvc.ObjectMeta.Name) + return nil, fmt.Errorf("no revisions found for the service %s", latestSvc.ObjectMeta.Name) } // sort revisions to main the order of generations @@ -163,6 +160,10 @@ func exportServicewithActiveRevisions(latestSvc *servingv1.Service, client clien } } + if len(exportedSvcItems) == 0 { + return nil, fmt.Errorf("no revisions found for service %s", latestSvc.ObjectMeta.Name) + } + //set traffic in the latest revision exportedSvcItems[len(exportedSvcItems)-1] = setTrafficSplit(latestSvc, exportedSvcItems[len(exportedSvcItems)-1]) @@ -181,7 +182,6 @@ func exportServicewithActiveRevisions(latestSvc *servingv1.Service, client clien func setTrafficSplit(latestSvc *servingv1.Service, exportedSvc servingv1.Service) servingv1.Service { exportedSvc.Spec.RouteSpec = latestSvc.Spec.RouteSpec - return exportedSvc } diff --git a/pkg/kn/commands/service/export_test.go b/pkg/kn/commands/service/export_test.go index 6b9be103a2..59662281e5 100644 --- a/pkg/kn/commands/service/export_test.go +++ b/pkg/kn/commands/service/export_test.go @@ -171,7 +171,7 @@ func callServiceExportHistoryTest(t *testing.T, expectedService *servingv1.Servi r.ListRevisions(mock.Any(), revs, nil) - output, err := executeServiceCommand(client, "export", expectedService.ObjectMeta.Name, "-r", "-o", "json") + output, err := executeServiceCommand(client, "export", expectedService.ObjectMeta.Name, "--with-revisions", "-o", "json") assert.NilError(t, err)