From 7f05b8c4824df0833307d093e915abc2fa84890b Mon Sep 17 00:00:00 2001 From: Mike Petersen Date: Tue, 1 Sep 2020 15:44:27 -0700 Subject: [PATCH] Ran build to update docs/created a helper script --- docs/cmd/kn_service_create.md | 2 +- docs/cmd/kn_service_update.md | 2 +- .../service/configuration_edit_flags.go | 71 +++++++++++-------- 3 files changed, 44 insertions(+), 31 deletions(-) diff --git a/docs/cmd/kn_service_create.md b/docs/cmd/kn_service_create.md index f9ebc02ee5..74cc1a42ba 100644 --- a/docs/cmd/kn_service_create.md +++ b/docs/cmd/kn_service_create.md @@ -86,7 +86,7 @@ kn service create NAME --image IMAGE --requests-cpu string DEPRECATED: please use --request instead. The requested CPU (e.g., 250m). --requests-memory string DEPRECATED: please use --request instead. The requested memory (e.g., 64Mi). --revision-name string The revision name to set. Must start with the service name and a dash as a prefix. Empty revision name will result in the server generating a name for the revision. Accepts golang templates, allowing {{.Service}} for the service name, {{.Generation}} for the generation, and {{.Random [n]}} for n random consonants. (default "{{.Service}}-{{.Random 5}}-{{.Generation}}") - --scale string Set the Minimum and Maximum number of replicas. You can use this flag to set both to a single value, or set a range with min/max values, or set either min or max values without specifying the other. Example: --scale 5 or --scale 1..5 or --scale 1.. or --scale ..5. + --scale string Minimum and maximum number of replicas. (default "1") --scale-max int Maximum number of replicas. --scale-min int Minimum number of replicas. --service-account string Service account name to set. An empty argument ("") clears the service account. The referenced service account must exist in the service's namespace. diff --git a/docs/cmd/kn_service_update.md b/docs/cmd/kn_service_update.md index 8609e2c3db..62f2364e4f 100644 --- a/docs/cmd/kn_service_update.md +++ b/docs/cmd/kn_service_update.md @@ -69,7 +69,7 @@ kn service update NAME --requests-cpu string DEPRECATED: please use --request instead. The requested CPU (e.g., 250m). --requests-memory string DEPRECATED: please use --request instead. The requested memory (e.g., 64Mi). --revision-name string The revision name to set. Must start with the service name and a dash as a prefix. Empty revision name will result in the server generating a name for the revision. Accepts golang templates, allowing {{.Service}} for the service name, {{.Generation}} for the generation, and {{.Random [n]}} for n random consonants. (default "{{.Service}}-{{.Random 5}}-{{.Generation}}") - --scale string Set the Minimum and Maximum number of replicas. You can use this flag to set both to a single value, or set a range with min/max values, or set either min or max values without specifying the other. Example: --scale 5 or --scale 1..5 or --scale 1.. or --scale ..5. + --scale string Minimum and maximum number of replicas. (default "1") --scale-max int Maximum number of replicas. --scale-min int Minimum number of replicas. --service-account string Service account name to set. An empty argument ("") clears the service account. The referenced service account must exist in the service's namespace. diff --git a/pkg/kn/commands/service/configuration_edit_flags.go b/pkg/kn/commands/service/configuration_edit_flags.go index 589e5e406e..144939a4d8 100644 --- a/pkg/kn/commands/service/configuration_edit_flags.go +++ b/pkg/kn/commands/service/configuration_edit_flags.go @@ -334,35 +334,7 @@ func (p *ConfigurationEditFlags) Apply( } else if cmd.Flags().Changed("scale-min") { return fmt.Errorf("only --scale or --scale-min can be specified") } else { - if !strings.Contains(p.Scale, "..") { - scaleMin, _ := strconv.Atoi(p.Scale) - scaleMax := scaleMin - err = servinglib.UpdateMaxScale(template, scaleMax) - if err != nil { - return err - } - err = servinglib.UpdateMinScale(template, scaleMin) - if err != nil { - return err - } - } else { - scaleParts := strings.Split(p.Scale, "..") - scaleMin, _ := strconv.Atoi(scaleParts[0]) - scaleMax, _ := strconv.Atoi(scaleParts[1]) - if scaleMax > 0 { - err = servinglib.UpdateMaxScale(template, scaleMax) - if err != nil { - return err - } - } - if scaleMin > 0 { - err = servinglib.UpdateMinScale(template, scaleMin) - if err != nil { - return err - } - } - } - + p.ScaleConversion(template, p.Scale) } } @@ -502,3 +474,44 @@ func (p *ConfigurationEditFlags) AnyMutation(cmd *cobra.Command) bool { } return false } + +func (p *ConfigurationEditFlags) ScaleConversion(template *servingv1.RevisionTemplateSpec, scale string) { + var scaleMin, scaleMax int + var err error + + if !strings.Contains(scale, "..") { + scaleMin, err := strconv.Atoi(scale) + if err != nil { + fmt.Printf("%v", err) + } + scaleMax = scaleMin + } else { + scaleParts := strings.Split(scale, "..") + + scaleMin, _ = strconv.Atoi(scaleParts[0]) + if err != nil { + fmt.Printf("%d %v", scaleMin, err) + } + scaleMax, _ = strconv.Atoi(scaleParts[1]) + if err != nil { + fmt.Printf("%d %v", scaleMax, err) + } + fmt.Printf("%d %d", scaleMax, scaleMin) + + } + fmt.Printf("max = %d, min=%d", scaleMax, scaleMin) + if scaleMax > 0 { + err = servinglib.UpdateMaxScale(template, scaleMax) + fmt.Printf("Updating scaleMax %d", scaleMax) + if err != nil { + fmt.Printf("%d %v", scaleMax, err) + } + } + if scaleMin > 0 { + err = servinglib.UpdateMinScale(template, scaleMin) + fmt.Printf("Updating scaleMin %d", scaleMin) + if err != nil { + fmt.Printf("%d %v", scaleMin, err) + } + } +}