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

This commit is contained in:
Roland Huß 2020-03-10 18:04:28 +01:00 committed by GitHub
parent 74e43b8806
commit a0f13548a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 13 deletions

View File

@ -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) --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 -h, --help help for export
-r, --history Export all active revisions
-n, --namespace string Specify the namespace to operate in. -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. -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]. --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 ### Options inherited from parent commands

View File

@ -70,7 +70,7 @@ func NewServiceExportCommand(p *commands.KnParams) *cobra.Command {
return err return err
} }
history, err := cmd.Flags().GetBool("history") withRevisions, err := cmd.Flags().GetBool("with-revisions")
if err != nil { if err != nil {
return err return err
} }
@ -80,8 +80,8 @@ func NewServiceExportCommand(p *commands.KnParams) *cobra.Command {
return err return err
} }
if history { if withRevisions {
if svcList, err := exportServicewithActiveRevisions(service, client); err != nil { if svcList, err := exportServiceWithActiveRevisions(service, client); err != nil {
return err return err
} else { } else {
return printer.PrintObj(svcList, cmd.OutOrStdout()) return printer.PrintObj(svcList, cmd.OutOrStdout())
@ -92,7 +92,7 @@ func NewServiceExportCommand(p *commands.KnParams) *cobra.Command {
} }
flags := command.Flags() flags := command.Flags()
commands.AddNamespaceFlags(flags, false) 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) machineReadablePrintFlags.AddFlags(command)
return command return command
} }
@ -135,22 +135,19 @@ func constructServicefromRevision(latestSvc *servingv1.Service, revision serving
return exportedSvc 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 var exportedSvcItems []servingv1.Service
//get revisions to export from traffic //get revisions to export from traffic
revsMap := getRevisionstoExport(latestSvc) revsMap := getRevisionstoExport(latestSvc)
var params []clientservingv1.ListConfig
params = append(params, clientservingv1.WithService(latestSvc.ObjectMeta.Name))
// Query for list with filters // Query for list with filters
revisionList, err := client.ListRevisions(params...) revisionList, err := client.ListRevisions(clientservingv1.WithService(latestSvc.ObjectMeta.Name))
if err != nil { if err != nil {
return nil, err return nil, err
} }
if len(revisionList.Items) == 0 { 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 // 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 //set traffic in the latest revision
exportedSvcItems[len(exportedSvcItems)-1] = setTrafficSplit(latestSvc, exportedSvcItems[len(exportedSvcItems)-1]) 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 { func setTrafficSplit(latestSvc *servingv1.Service, exportedSvc servingv1.Service) servingv1.Service {
exportedSvc.Spec.RouteSpec = latestSvc.Spec.RouteSpec exportedSvc.Spec.RouteSpec = latestSvc.Spec.RouteSpec
return exportedSvc return exportedSvc
} }

View File

@ -171,7 +171,7 @@ func callServiceExportHistoryTest(t *testing.T, expectedService *servingv1.Servi
r.ListRevisions(mock.Any(), revs, nil) 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) assert.NilError(t, err)