Skip to content
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

Merged
merged 3 commits into from
Aug 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
Copy link
Contributor

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

Copy link
Contributor Author

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.

},
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
Copy link
Contributor

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

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