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

Conversation

SupriyaKasten
Copy link
Contributor

@SupriyaKasten SupriyaKasten commented Aug 22, 2019

Change Overview

ScaleWorkload only allowed static int values for replicas parameter. With these changes, we can provide string values to replicas in addition to int, kanister will take care of conversion.

Pull request type

Please check the type of change your PR introduces:

  • Work in Progress
  • Refactoring (no functional changes, no api changes)
  • Trival/Minor
  • Bugfix
  • Feature
  • Documentation

Test Plan

  • Manual
  • Unit test
  • E2E

if err != nil {
return namespace, kind, name, replicas, err
}

if val, ok := rep.(int); ok {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use a type switch here: https://tour.golang.org/methods/16

if val, ok := rep.(int); ok {
replicas = int32(val)
} else if val, ok := rep.(string); ok {
strToInt := intstr.Parse(val)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strToInt := intstr.Parse(val)
replicas = strToInt.IntVal
} else {
return namespace, kind, name, replicas, errors.Wrapf(err, "Failed to decode arg `%s`", ScaleWorkloadReplicas)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typically I'd use a naked return with named return values.

Suggested change
return namespace, kind, name, replicas, errors.Wrapf(err, "Failed to decode arg `%s`", ScaleWorkloadReplicas)
err = errors.Errorf("Invalid arg type %T for Arg %s ", rep, ScaleWorkloadReplicas)
return

@@ -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.

@SupriyaKasten SupriyaKasten merged commit 519ef06 into master Aug 23, 2019
@SupriyaKasten SupriyaKasten deleted the scale-workload-func branch August 23, 2019 18:43
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants