Repository: knative/client
Pull request #729 (2020-03-10 16:32:00)

chore(service export): Rename `--history` to `--with-revisions`

knative-prow-robot: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/knative/client/pull/729#" title="Author self-approved">rhuss</a>*

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=knative%2Fclient).

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

<details >
Needs approval from an approver in each of these files:

- ~~[OWNERS](https://github.com/knative/client/blob/master/OWNERS)~~ [rhuss]

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":[]} -->
knative-metrics-robot: The following is the coverage report on the affected files.
Say `/test pull-knative-client-go-coverage` to re-run this coverage report

File | Old Coverage | New Coverage | Delta
---- |:------------:|:------------:|:-----:
[pkg/kn/commands/service/export.go](https://storage.cloud.google.com/knative-prow/pr-logs/pull/knative_client/729/pull-knative-client-go-coverage/1237416375119515650/artifacts/line-cov.html#file0) | 83.3% | 82.1% | -1.3

knative-prow-robot: @rhuss: The following test **failed**, say `/retest` to rerun all failed tests:

Test name | Commit | Details | Rerun command
--- | --- | --- | ---
pull-knative-client-build-tests | e9af5fbb088ac876bfe934d4c204fb6aa9df16ef | [link](https://prow.knative.dev/view/gcs/knative-prow/pr-logs/pull/knative_client/729/pull-knative-client-build-tests/1237416375119515648) | `/test pull-knative-client-build-tests`

[Full PR test history](https://gubernator.knative.dev/pr/knative_client/729). [Your PR dashboard](https://gubernator.knative.dev/pr/rhuss).

<details>

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository. I understand the commands that are listed [here](https://go.k8s.io/bot-commands).
</details>
<!-- test report -->
knative-metrics-robot: The following is the coverage report on the affected files.
Say `/test pull-knative-client-go-coverage` to re-run this coverage report

File | Old Coverage | New Coverage | Delta
---- |:------------:|:------------:|:-----:
[pkg/kn/commands/service/export.go](https://storage.cloud.google.com/knative-prow/pr-logs/pull/knative_client/729/pull-knative-client-go-coverage/1237418136181936129/artifacts/line-cov.html#file0) | 83.3% | 82.1% | -1.3

knative-prow-robot: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/knative/client/pull/729#pullrequestreview-372138944" title="LGTM">navidshaikh</a>*, *<a href="https://github.com/knative/client/pull/729#" title="Author self-approved">rhuss</a>*

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=knative%2Fclient).

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

<details >
Needs approval from an approver in each of these files:

- ~~[OWNERS](https://github.com/knative/client/blob/master/OWNERS)~~ [navidshaikh,rhuss]

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":[]} -->

Patch:
diff --git a/docs/cmd/kn_service_export.md b/docs/cmd/kn_service_export.md
index f9491301..5c2b7266 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 a2cf1aa7..1b34abb9 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
 }
 


Test patch:
diff --git a/pkg/kn/commands/service/export_test.go b/pkg/kn/commands/service/export_test.go
index 6b9be103..59662281 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)