Skip to content

Commit

Permalink
Update ScaleWorkload to accept replicas as str & int
Browse files Browse the repository at this point in the history
  • Loading branch information
SupriyaKasten committed Aug 22, 2019
1 parent b88d1b9 commit a73286f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
6 changes: 3 additions & 3 deletions pkg/function/scale_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func newScaleBlueprint(kind string) *crv1alpha1.Blueprint {
Name: "testScale",
Func: "ScaleWorkload",
Args: map[string]interface{}{
ScaleWorkloadReplicas: 2,
ScaleWorkloadReplicas: "2",
},
},
},
Expand Down Expand Up @@ -234,7 +234,7 @@ func (s *ScaleSuite) TestGetArgs(c *C) {
{
tp: param.TemplateParams{},
args: map[string]interface{}{
ScaleWorkloadReplicas: 2,
ScaleWorkloadReplicas: "2",
ScaleWorkloadNamespaceArg: "foo",
ScaleWorkloadNameArg: "app",
ScaleWorkloadKindArg: param.StatefulSetKind,
Expand Down Expand Up @@ -269,7 +269,7 @@ func (s *ScaleSuite) TestGetArgs(c *C) {
},
},
args: map[string]interface{}{
ScaleWorkloadReplicas: 2,
ScaleWorkloadReplicas: "2",
},
wantKind: param.DeploymentKind,
wantName: "app",
Expand Down
13 changes: 11 additions & 2 deletions pkg/function/scale_workload.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"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 @@ -59,11 +60,19 @@ func (*scaleWorkloadFunc) RequiredArgs() []string {
}

func getArgs(tp param.TemplateParams, args map[string]interface{}) (namespace, kind, name string, replicas int32, err error) {
err = Arg(args, ScaleWorkloadReplicas, &replicas)
var rep interface{}
err = Arg(args, ScaleWorkloadReplicas, &rep)
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)
}
// Populate default values for optional arguments from template parameters
switch {
case tp.StatefulSet != nil:
Expand Down

0 comments on commit a73286f

Please sign in to comment.