Skip to content

Commit

Permalink
Ran build to update docs/created a helper script
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Petersen committed Sep 1, 2020
1 parent ad39a84 commit 7f05b8c
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 31 deletions.
2 changes: 1 addition & 1 deletion docs/cmd/kn_service_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion docs/cmd/kn_service_update.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
71 changes: 42 additions & 29 deletions pkg/kn/commands/service/configuration_edit_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

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

0 comments on commit 7f05b8c

Please sign in to comment.