Skip to content

Commit

Permalink
chore(service export): Rename --history to --with-revisions (#729)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhuss authored Mar 10, 2020
1 parent 74e43b8 commit a0f1354
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion docs/cmd/kn_service_export.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 11 additions & 11 deletions pkg/kn/commands/service/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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())
Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand All @@ -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])

Expand All @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/kn/commands/service/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit a0f1354

Please sign in to comment.