-
Notifications
You must be signed in to change notification settings - Fork 152
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
Update ScaleWorkload to provide replicas as string & int value #226
Conversation
pkg/function/scale_workload.go
Outdated
if err != nil { | ||
return namespace, kind, name, replicas, err | ||
} | ||
|
||
if val, ok := rep.(int); ok { |
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.
please use a type switch here: https://tour.golang.org/methods/16
pkg/function/scale_workload.go
Outdated
if val, ok := rep.(int); ok { | ||
replicas = int32(val) | ||
} else if val, ok := rep.(string); ok { | ||
strToInt := intstr.Parse(val) |
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.
let's just use https://golang.org/pkg/strconv/#Atoi
pkg/function/scale_workload.go
Outdated
strToInt := intstr.Parse(val) | ||
replicas = strToInt.IntVal | ||
} else { | ||
return namespace, kind, name, replicas, errors.Wrapf(err, "Failed to decode arg `%s`", ScaleWorkloadReplicas) |
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.
typically I'd use a naked return with named return values.
return namespace, kind, name, replicas, errors.Wrapf(err, "Failed to decode arg `%s`", ScaleWorkloadReplicas) | |
err = errors.Errorf("Invalid arg type %T for Arg %s ", rep, ScaleWorkloadReplicas) | |
return |
@@ -269,7 +269,7 @@ func (s *ScaleSuite) TestGetArgs(c *C) { | |||
}, | |||
}, | |||
args: map[string]interface{}{ | |||
ScaleWorkloadReplicas: 2, | |||
ScaleWorkloadReplicas: "2", |
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.
Let's leave one of these an int to test both codepaths
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.
@tdmanv we do have two of these as int.
if err != nil { | ||
return namespace, kind, name, replicas, err | ||
} | ||
|
||
var val int |
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.
[minor] Should this be a function? Okay to be done as an enhancement later
Change Overview
ScaleWorkload only allowed static int values for
replicas
parameter. With these changes, we can provide string values toreplicas
in addition to int, kanister will take care of conversion.Pull request type
Please check the type of change your PR introduces:
Test Plan