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

OCM-5677 | feat: Added rosa describe autoscaler command #1837

Merged

Conversation

robpblake
Copy link
Contributor

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.

@openshift-ci openshift-ci bot requested review from den-rgb and oriAdler March 12, 2024 15:27
@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 12, 2024
@robpblake
Copy link
Contributor Author

/remove-approve

@openshift-ci openshift-ci bot removed the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 12, 2024
Copy link

codecov bot commented Mar 12, 2024

Codecov Report

Attention: Patch coverage is 80.66667% with 29 lines in your changes are missing coverage. Please review.

Project coverage is 20.92%. Comparing base (b049fc4) to head (4c54777).
Report is 6 commits behind head on master.

Files Patch % Lines
pkg/rosa/runner.go 36.36% 13 Missing and 1 partial ⚠️
pkg/ocm/output/nodepools.go 0.00% 5 Missing ⚠️
cmd/describe/cluster/cmd.go 0.00% 3 Missing ⚠️
pkg/ocm/output/machinepools.go 0.00% 3 Missing ⚠️
pkg/output/output.go 0.00% 3 Missing ⚠️
pkg/ocm/flag.go 85.71% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.


func IsAutoscalerSupported(runtime *rosa.Runtime, cluster *cmv1.Cluster) error {
if cluster.Hypershift().Enabled() {
return fmt.Errorf(NoHCPAutoscalerSupportMessage)
Copy link
Contributor

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

Copy link
Contributor Author

@robpblake robpblake Mar 13, 2024

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?

Copy link
Contributor

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

@robpblake robpblake force-pushed the ocm-5677-view-autoscaler branch 2 times, most recently from b1f8b38 to f421090 Compare March 13, 2024 17:09
Comment on lines +45 to +57
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)
}
Copy link
Contributor Author

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
}

Copy link
Contributor

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 {
Copy link
Contributor Author

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 {
Copy link
Contributor Author

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.

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 14, 2024

// 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) {
Copy link
Contributor Author

@robpblake robpblake Mar 14, 2024

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

Copy link
Contributor

@oriAdler oriAdler left a 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?

cmd/describe/autoscaler/cmd_test.go Outdated Show resolved Hide resolved
cmd/describe/autoscaler/cmd_test.go Outdated Show resolved Hide resolved
cmd/describe/autoscaler/cmd_test.go Outdated Show resolved Hide resolved
cmd/describe/autoscaler/cmd_test.go Outdated Show resolved Hide resolved
pkg/ocm/flag.go Show resolved Hide resolved
pkg/rosa/runner.go Outdated Show resolved Hide resolved
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 21, 2024
@@ -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 {
Copy link
Contributor Author

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.

@ciaranRoche
Copy link
Member

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
WDYT?

@robpblake
Copy link
Contributor Author

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 WDYT?

@ciaranRoche That makes sense to me. +1

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 24, 2024
@ciaranRoche
Copy link
Member

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Mar 25, 2024
Copy link
Contributor

openshift-ci bot commented Mar 25, 2024

[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:
  • OWNERS [ciaranRoche,oriAdler]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link
Contributor

openshift-ci bot commented Mar 25, 2024

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

@openshift-merge-bot openshift-merge-bot bot merged commit 68ce5a0 into openshift:master Mar 25, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants