Skip to content

Commit

Permalink
Refactor ScaleWorkload (#238)
Browse files Browse the repository at this point in the history
* Refactore ScaleWorkload

* nit fix
  • Loading branch information
SupriyaKasten committed Aug 26, 2019
1 parent 55df6da commit 23f43b2
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions pkg/function/scale_workload.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,25 +66,24 @@ func getArgs(tp param.TemplateParams, args map[string]interface{}) (namespace, k
return namespace, kind, name, replicas, err
}

var val int
switch rep.(type) {
switch val := rep.(type) {
case int:
val = rep.(int)
replicas = int32(val)
case int32:
val = int(rep.(int32))
replicas = val
case int64:
val = int(rep.(int64))
replicas = int32(val)
case string:
if val, err = strconv.Atoi(rep.(string)); err != nil {
err = errors.Wrapf(err, "Cannot convert %s to int ", rep.(string))
var v int
if v, err = strconv.Atoi(val); err != nil {
err = errors.Wrapf(err, "Cannot convert %s to int ", val)
return
}
replicas = int32(v)
default:
err = errors.Errorf("Invalid arg type %T for Arg %s ", rep, ScaleWorkloadReplicas)
return
}

replicas = int32(val)
// Populate default values for optional arguments from template parameters
switch {
case tp.StatefulSet != nil:
Expand Down

0 comments on commit 23f43b2

Please sign in to comment.