diff --git a/pkg/kn/commands/service/configuration_edit_flags.go b/pkg/kn/commands/service/configuration_edit_flags.go index 144939a4d8..31fbb0e248 100644 --- a/pkg/kn/commands/service/configuration_edit_flags.go +++ b/pkg/kn/commands/service/configuration_edit_flags.go @@ -334,7 +334,15 @@ func (p *ConfigurationEditFlags) Apply( } else if cmd.Flags().Changed("scale-min") { return fmt.Errorf("only --scale or --scale-min can be specified") } else { - p.ScaleConversion(template, p.Scale) + scaleMin, scaleMax, err := p.ScaleConversion(p.Scale) + err = servinglib.UpdateMaxScale(template, scaleMax) + if err != nil { + return err + } + err = servinglib.UpdateMinScale(template, scaleMin) + if err != nil { + return err + } } } @@ -475,43 +483,27 @@ 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 - +func (p *ConfigurationEditFlags) ScaleConversion(scale string) (scaleMin int, scaleMax int, err error) { if !strings.Contains(scale, "..") { - scaleMin, err := strconv.Atoi(scale) + scaleMin, err = strconv.Atoi(scale) if err != nil { - fmt.Printf("%v", err) + return 0, 0, 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 scaleParts[0] != "" { + scaleMin, err = strconv.Atoi(scaleParts[0]) + if err != nil { + return 0, 0, err + } } - } - if scaleMin > 0 { - err = servinglib.UpdateMinScale(template, scaleMin) - fmt.Printf("Updating scaleMin %d", scaleMin) - if err != nil { - fmt.Printf("%d %v", scaleMin, err) + if scaleParts[1] != "" { + scaleMax, err = strconv.Atoi(scaleParts[1]) + if err != nil { + return 0, 0, err + } } } + return scaleMin, scaleMax, err }