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
Remove newScheduler for reducing complexity #112563
Remove newScheduler for reducing complexity #112563
Conversation
@kerthcet: This issue is currently awaiting triage. If a SIG or subproject determines this is a relevant issue, they will accept it by applying the The 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. |
/retest |
cc @kubernetes/sig-scheduling-leads |
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 more common in the codebase that we use withX
Yes, that's what came into my mind first. But I found we already have This pattern is widely used in cli. kubernetes/staging/src/k8s.io/cli-runtime/pkg/resource/builder.go Lines 730 to 733 in 9c9b290
|
oh right... This seems to be another legacy leftover from the times when the scheduler was split in two objects. We should just get rid of |
pkg/scheduler/scheduler.go
Outdated
@@ -98,6 +98,52 @@ type Scheduler struct { | |||
nextStartNodeIndex int | |||
} | |||
|
|||
// newScheduler creates a Scheduler object. | |||
func newScheduler( |
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.
Is that newScheduler() is still present b/c all usecases need the 4 parameters? Or, you're going to get rid of this function as well?
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.
Yes, these 4 parameters are widely used in summary.
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 suggest the following: remove the newScheduler
function and create an applyDefaultHandlers
function for Scheduler
that sets SchedulePod
and FailureHandler
.
In New
and the tests, just create a Scheduler
struct and invoke applyDefaultHandlers
right after (unless the handlers needs to be set to something different).
It would be a little difficult, |
I'm against adding more setup complexity just because unit tests use the low level builder. I think changing the unit tests is the right direction. |
In unit tests, scheduler should not care much about api level fields, e.g. in extender tests, we use the framework extender which is an interface, it's easy to mock the implementation kubernetes/pkg/scheduler/extender_test.go Lines 43 to 51 in 575031b
But if we change to api lever extender, we have to define many fields, it's verbosely. kubernetes/pkg/scheduler/apis/config/types.go Lines 246 to 252 in 575031b
|
To reduce the complexity, I'll follow @ahg-g advices, create a |
eb5ff4c
to
af8f92c
Compare
please squash |
Signed-off-by: kerthcet <kerthcet@gmail.com>
af8f92c
to
1271786
Compare
Squashed @ahg-g |
/approve |
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.
/lgtm
/approve
way better 😃
/hold cancel |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ahg-g, alculquicondor, kerthcet 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 |
Signed-off-by: kerthcet kerthcet@gmail.com
What type of PR is this?
/kind cleanup
/sig scheduling
What this PR does / why we need it:
For readability and maintainability.
Which issue(s) this PR fixes:
Fixes #108788
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: