Skip to content

Commit

Permalink
Updated helper function/cleaned it up and resolved failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Petersen committed Sep 2, 2020
1 parent 7f05b8c commit f9e53d5
Showing 1 changed file with 23 additions and 31 deletions.
54 changes: 23 additions & 31 deletions pkg/kn/commands/service/configuration_edit_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

Expand Down Expand Up @@ -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
}

0 comments on commit f9e53d5

Please sign in to comment.