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

Put ScaleUp logic behind an interface #5597

Merged
merged 7 commits into from
Mar 21, 2023

Conversation

kisieland
Copy link
Contributor

Which component does this PR applies to?

cluster-autoscaler

What type of PR is this?

/kind cleanup

What this PR does / why we need it:

This refactoring is similar to the one done for scale down logic in: #4806
The scale up is put behind interface and can be overridden by users.

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

This is a huge change and can be hard to review. I divided it into 6 commits that are self-contained (i.e. tests were passing on each commit). Looking at the changes may be simpler one commit at a time.
Note: any comments on how to modify the interface and make it more user expendable are welcome.

Does this PR introduce a user-facing change?

ScaleUp logic was significantly refactored. This should have no visible impact on the behavior of Cluster Autoscaler.

/assign @x13n
/cc @towca

* Move resource manager to a dedicated package
* Move pod equivalence groups to dedicated package
* Add ScaleUpManager interface, which is copy of existing stand-alone functions
* Add a wrapper which contains the current scale up logic code
* Simplify the ScaleUp* functions parameter list
* Introduce the ScaleUpManagerFactory to allow greater expandability
* Simplify helper functions in scale up wrapper
* Make the SkippedReasons public and move those to a dedicated file
* Introduced ExecuteScaleUp function, which runs chosen expansion options.
* Lowered intendation of ScaleUp function, by reverting bestOption check.
* Unified error and Autoscaling error variable names to 'err' and 'aErr'.
@k8s-ci-robot k8s-ci-robot added the kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. label Mar 15, 2023
@k8s-ci-robot k8s-ci-robot requested a review from towca March 15, 2023 10:35
@k8s-ci-robot k8s-ci-robot added area/cluster-autoscaler cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Mar 15, 2023
* Make the structures public, as well as some helper functions
* manager.go to scaleup.go file rename
* Minor code simplifications
* Minor comment fixes/style consolidations
@kisieland kisieland force-pushed the scale-up-changes-v2 branch from 1169d55 to 26a3604 Compare March 15, 2023 11:59
* Add field names to struct literals
* Slice iteration/population standardized
* Add boilerplate and fix comment lint errors
@kisieland kisieland force-pushed the scale-up-changes-v2 branch from 26a3604 to 9cd44fd Compare March 15, 2023 14:11
)

// ManagerFactory is a component that creates a new instance of the scale up manager.
type ManagerFactory interface {
Copy link
Member

Choose a reason for hiding this comment

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

What is the benefit of having a factory? Assuming there is one - what is the benefit of putting the factory object behind an interface? I think interfaces are useful if you have multiple possible implementations (e.g. mock for testing), but I don't think this is the case here.

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 idea was to allow users to specify a component with a custom scale up logic, unfortunately some of the required objects (autoscalingContext, clusterStateRegistry) are created in NewStaticAutoscaler function.
Another option I considered was to add an Initialize function to the Manager interface, if you think it makes more sense I can rewrite it.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, right, I forgot that function is quite a dependency mess. I think a factory is a bit more natural than the Initialize method, but I don't have a strong opinion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think Initialize looks better so leaving it for now.

cluster-autoscaler/core/scaleup/scaleup.go Outdated Show resolved Hide resolved
cluster-autoscaler/core/scaleup/wrapper/manager.go Outdated Show resolved Hide resolved
@kisieland
Copy link
Contributor Author

@x13n thanks for the review,

Uploaded a new version which:

  • Renames scaleup.Manager to scaleup.Orchestrator
  • Removes factory and add Initialize function
  • Renames the wrapper package to orchestrator

PTAL

@kisieland kisieland requested review from x13n and removed request for towca March 17, 2023 14:28
* Rename scaleup.Manager to scaleup.Orchestrator
* Remove factory and add Initialize function
* Rename the wrpapper package to orchestrator
* Rename NewOrchestrator func to just New
@kisieland kisieland force-pushed the scale-up-changes-v2 branch from 6957887 to 5b6c50e Compare March 20, 2023 17:17
@kisieland
Copy link
Contributor Author

@x13n responded to last comment, PTAL :)

@x13n
Copy link
Member

x13n commented Mar 21, 2023

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 21, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: kisieland, x13n

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 21, 2023
@k8s-ci-robot k8s-ci-robot merged commit 241643d into kubernetes:master Mar 21, 2023
@kisieland kisieland deleted the scale-up-changes-v2 branch March 22, 2023 11:08
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. area/cluster-autoscaler cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants