Skip to content

Commit

Permalink
Address review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
SupriyaKasten committed Aug 23, 2019
1 parent a73286f commit eeb62b4
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions pkg/function/scale_workload.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package function

import (
"context"
"strconv"
"strings"

"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/util/intstr"

kanister "github.com/kanisterio/kanister/pkg"
"github.com/kanisterio/kanister/pkg/kube"
Expand Down Expand Up @@ -65,14 +65,22 @@ func getArgs(tp param.TemplateParams, args map[string]interface{}) (namespace, k
if err != nil {
return namespace, kind, name, replicas, err
}
if val, ok := rep.(int); ok {
replicas = int32(val)
} else if val, ok := rep.(string); ok {
strToInt := intstr.Parse(val)
replicas = strToInt.IntVal
} else {
return namespace, kind, name, replicas, errors.Wrapf(err, "Failed to decode arg `%s`", ScaleWorkloadReplicas)

var val int
switch rep.(type) {
case int:
val = rep.(int)
case string:
if val, err = strconv.Atoi(rep.(string)); err != nil {
err = errors.Wrapf(err, "Cannot convert %s to int ", rep.(string))
return
}
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 eeb62b4

Please sign in to comment.