Skip to content

Commit

Permalink
Merge pull request #226 from kanisterio/scale-workload-func
Browse files Browse the repository at this point in the history
Update ScaleWorkload to provide replicas as string & int value
  • Loading branch information
SupriyaKasten committed Aug 23, 2019
2 parents b2106f4 + 11fa095 commit 519ef06
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 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
19 changes: 18 additions & 1 deletion pkg/function/scale_workload.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package function

import (
"context"
"strconv"
"strings"

"github.com/pkg/errors"
Expand Down Expand Up @@ -59,11 +60,27 @@ 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
}

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 519ef06

Please sign in to comment.