-
Notifications
You must be signed in to change notification settings - Fork 263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add range options to --scale #1070
Changes from 9 commits
3db3cdb
7f91820
2edf4c4
84eb376
abb75e4
2b7631a
33d9193
efa9e27
537973f
ed67482
a75cb2c
c31eac4
6d00de6
6ed76ae
6fa4098
ad4a7b1
d1552ee
8ca97c7
c60b851
8a0067d
3614bd6
5787e95
a0ddad9
4b84de3
26867f1
45ffade
b72e4be
1f0e5f9
0075a6e
629b995
a6279dc
5da8f3c
9567f05
0ede82b
b3e962a
871ba72
55c9980
be8e590
3a0c74e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
package service | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"strconv" | ||
"strings" | ||
|
@@ -39,7 +40,7 @@ type ConfigurationEditFlags struct { | |
PodSpecFlags knflags.PodSpecFlags | ||
|
||
// Direct field manipulation | ||
Scale int | ||
Scale string | ||
MinScale int | ||
MaxScale int | ||
ConcurrencyTarget int | ||
|
@@ -88,7 +89,11 @@ func (p *ConfigurationEditFlags) addSharedFlags(command *cobra.Command) { | |
command.Flags().MarkHidden("max-scale") | ||
p.markFlagMakesRevision("max-scale") | ||
|
||
command.Flags().IntVar(&p.Scale, "scale", 0, "Minimum and maximum number of replicas.") | ||
command.Flags().StringVar(&p.Scale, "scale", "1", | ||
"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 (scale-min = 5, scale-max = 5) or --scale 1..5 (scale-min = 1, scale-max = 5) or --scale "+ | ||
"1.. (scale-min = 1, scale-max = undefined) or --scale ..5 (scale-min = undefined, scale-max = 5)") | ||
p.markFlagMakesRevision("scale") | ||
|
||
command.Flags().IntVar(&p.MinScale, "scale-min", 0, "Minimum number of replicas.") | ||
|
@@ -358,13 +363,21 @@ func (p *ConfigurationEditFlags) Apply( | |
} else if cmd.Flags().Changed("scale-min") { | ||
return fmt.Errorf("only --scale or --scale-min can be specified") | ||
} else { | ||
err = servinglib.UpdateMaxScale(template, p.Scale) | ||
scaleMin, scaleMax, err := p.scaleConversion(p.Scale) | ||
if err != nil { | ||
return err | ||
} | ||
err = servinglib.UpdateMinScale(template, p.Scale) | ||
if err != nil { | ||
return err | ||
if scaleMin != 0 { | ||
err = servinglib.UpdateMinScale(template, scaleMin) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
if scaleMax != 0 { | ||
err = servinglib.UpdateMaxScale(template, scaleMax) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -560,3 +573,33 @@ func (p *ConfigurationEditFlags) AnyMutation(cmd *cobra.Command) bool { | |
} | ||
return false | ||
} | ||
|
||
// Helper function for --scale | ||
func (p *ConfigurationEditFlags) scaleConversion(scale string) (scaleMin int, scaleMax int, err error) { | ||
if len(scale) <= 2 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My preference would be to divide this into smaller private functions for each of the cases... might simply things. Also for each case returning early could also simply code since once case identified the result is there. No need for big if/else if/else. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I break up the helper function into multiple private functions it will complicate the cmd.Flags().Changed("scale") section, is that ok? I was trying to minimize how large that code block was going to be. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Working on breaking this up next - I should be able to avoid complication in the cmd.Flags().Changed("scale") section. |
||
if !strings.Contains(scale, "..") { | ||
scaleMin, err = strconv.Atoi(scale) | ||
if err != nil { | ||
return 0, 0, err | ||
} | ||
scaleMax = scaleMin | ||
} | ||
} else if strings.Contains(scale, "..") { | ||
scaleParts := strings.Split(scale, "..") | ||
if scaleParts[0] != "" { | ||
scaleMin, err = strconv.Atoi(scaleParts[0]) | ||
if err != nil { | ||
return 0, 0, err | ||
} | ||
} | ||
if scaleParts[1] != "" { | ||
scaleMax, err = strconv.Atoi(scaleParts[1]) | ||
if err != nil { | ||
return 0, 0, err | ||
} | ||
} | ||
} else { | ||
return 0, 0, errors.New("Scale must be of the format x..y or x") | ||
} | ||
return scaleMin, scaleMax, err | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think saying “undefined” isn’t as clear as saying that the current value is unchanged. And there is no default value so I would remove that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that is is "unchanged" as we are here talking about a create operation. Also for an update operation I still think that
--scale 1..
mean min-scale is set to one, but no max-scale is set or removed if set, so that there is no upper bound specified by the user (regardless what was specified before). If you want to change only the minimal scale, you should use--min-scale
.+1 that the default value
1
is wrong as there is supposed to be no default at all, the argument is mandatory.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So maybe instead of
scale-max = undefined
, better useno maximum scale defined
) ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused. @rhuss in the past I think you said you wanted
1..
to mean only the lower bound is set, and upper bound is untouched. That's why I commented the way I did - I thought you still wanted that.Let's back up a bit... at one point people wanted to deprecate --scale-min and only have --scale - is that still in the cards or is that idea dead? If --scale-min/max will live on, then I'm ok with a missing value in
..
meaning unset that value (or in the 'create' case it means just leave it as the default). And yes--scale ..
would mean unset both :-)