-
Notifications
You must be signed in to change notification settings - Fork 208
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
OCM-5677 | feat: Added rosa describe autoscaler
command
#1837
OCM-5677 | feat: Added rosa describe autoscaler
command
#1837
Conversation
/remove-approve |
d2aafc3
to
c6eede7
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1837 +/- ##
=========================================
Coverage 20.91% 20.92%
=========================================
Files 103 113 +10
Lines 17351 18662 +1311
=========================================
+ Hits 3629 3905 +276
- Misses 13447 14470 +1023
- Partials 275 287 +12 ☔ View full report in Codecov by Sentry. |
|
||
func IsAutoscalerSupported(runtime *rosa.Runtime, cluster *cmv1.Cluster) error { | ||
if cluster.Hypershift().Enabled() { | ||
return fmt.Errorf(NoHCPAutoscalerSupportMessage) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Autoscaler is supported on HCP, but is only enabled for IBM if I'm not mistaken
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gdbranco I replicated the logic from create autoscaler
which doesn't seem to do any check to see if current org has capability to create autoscaler for their HCP cluster. IIRC, IBM doesn't use the CLI, but OCM SDK directly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, they are using SDK from what I know
b1f8b38
to
f421090
Compare
err = clusterautoscaler.IsAutoscalerSupported(runtime, cluster) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
autoscaler, err := runtime.OCMClient.GetClusterAutoscaler(cluster.ID()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if autoscaler == nil { | ||
return fmt.Errorf("No autoscaler exists for cluster '%s'", runtime.ClusterKey) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense to decompose this further into a new ClusterAutoscalerService
so that the command becomes even briefer e.g:
service := NewClusterAutoscalerService(runtime.OCMClient)
supported, err = service.IsAutoscalerSupported(runtime, cluster)
autoscaler, err := service.GetClusterAutoscaler(cluster.ID())
if err != nil {
return err
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's ok to keep it that way, it seems like we return nil for StatusNotFound
, and have different error messages per command.
I wish all the commands in ROSA were as brief as this one:)
With that being said, we could return a boolean from the function for exist
and check the boolean value instead of nil to improve readability (maybe outside of the scope of this PR).
rosa describe autoscaler --cluster foo` | ||
) | ||
|
||
func NewDescribeAutoscalerCommand() *cobra.Command { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The command is returned, fully initialised from a function. There is no use of global variables (ignoring the output.AddFlag
and ocm.AddClusterFlag
calls which are beyond the scope of this particular refactor). There is no use of init
return cmd | ||
} | ||
|
||
func DescribeAutoscalerRunner() rosa.CommandRunner { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Command logic is executed by a CommandRunner
. The runner does not os.Exit
, but instead returns an error
if something went wrong. This makes it fully testable. The passed Runtime
can be instantiated with mocks in the tests.
|
||
// DefaultRunner is a centralised implementation of the default Cobra Command.run function that takes care | ||
// of instantiating several key resources on behalf of a command | ||
func DefaultRunner(visitor RuntimeVisitor, runner CommandRunner) func(command *cobra.Command, args []string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Centralised handling of Context
and Runtime
instantiation. Also centralised the handling of the deferred r.Cleanup()
(Need to further discuss if we actually need this as the runtime exits at the end of the execution.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice approach!
I wonder how complicated would it be for interactive commands.
Is it worth going through the PR during one of the office hours? to enhance understanding and share with the team?
f421090
to
47a0009
Compare
@@ -242,10 +242,8 @@ func run(cmd *cobra.Command, _ []string) { | |||
case aws.ModeAuto: | |||
if isUpgradeNeedForAccountRolePolicies { | |||
reporter.Infof("Starting to upgrade the policies") | |||
err = r.WithSpinner(func() error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our AWS SDK v2 rebase incorrectly bought this back in, so just returning us to previous state.
2b5b12b
to
4c54777
Compare
LGTM, happy to merge this if we want. I think the overall struct is good, and small improvements can be followed up as we tackle a more complex command next |
@ciaranRoche That makes sense to me. +1 |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ciaranRoche, oriAdler The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@robpblake: all tests passed! Full PR test history. Your PR dashboard. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
This PR adds
rosa describe autoscaler
to the ROSA CLI to allow customers to view details of their cluster autoscaler.This PR attempts to introduced some of the concepts from the ROSA unit testing DDR to explore how we can make our commands more test friendly.