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

Remove newScheduler for reducing complexity #112563

Merged

Conversation

kerthcet
Copy link
Member

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?

None

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Sep 19, 2022
@k8s-ci-robot
Copy link
Contributor

@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 triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

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.

@k8s-ci-robot k8s-ci-robot added needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Sep 19, 2022
@kerthcet
Copy link
Member Author

/retest

@kerthcet
Copy link
Member Author

cc @kubernetes/sig-scheduling-leads

Copy link
Member

@alculquicondor alculquicondor left a 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

@kerthcet
Copy link
Member Author

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 schedulerOptions under the package. It seems conflicts in names and easy to confuse.

This pattern is widely used in cli.

func (b *Builder) Latest() *Builder {
b.latest = true
return b
}

@alculquicondor
Copy link
Member

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 newScheduler instead (and migrate the tests that use it to New).

@@ -98,6 +98,52 @@ type Scheduler struct {
nextStartNodeIndex int
}

// newScheduler creates a Scheduler object.
func newScheduler(
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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

pkg/scheduler/scheduler.go Outdated Show resolved Hide resolved
pkg/scheduler/scheduler.go Outdated Show resolved Hide resolved
@kerthcet
Copy link
Member Author

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 newScheduler instead (and migrate the tests that use it to New).

It would be a little difficult, scheduler.New() helps to instantiate a scheduler with API-level options, like apiVersion, KubeSchedulerProfile, but the newScheduler here instantiates with internal parameters, they're from different layer. As a result, lots of unit tests depend on newScheduler to mock the server, I think it works well.

@alculquicondor
Copy link
Member

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.

@kerthcet
Copy link
Member Author

kerthcet commented Oct 8, 2022

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

func TestSchedulerWithExtenders(t *testing.T) {
tests := []struct {
name string
registerPlugins []st.RegisterPluginFunc
extenders []st.FakeExtender
nodes []string
expectedResult ScheduleResult
expectsErr bool
}{

But if we change to api lever extender, we have to define many fields, it's verbosely.

type Extender struct {
// URLPrefix at which the extender is available
URLPrefix string
// Verb for the filter call, empty if not supported. This verb is appended to the URLPrefix when issuing the filter call to extender.
FilterVerb string
// Verb for the preempt call, empty if not supported. This verb is appended to the URLPrefix when issuing the preempt call to extender.
PreemptVerb string

@kerthcet
Copy link
Member Author

kerthcet commented Oct 8, 2022

To reduce the complexity, I'll follow @ahg-g advices, create a Scheduler directly.

@kerthcet kerthcet force-pushed the cleanup/optimize-new-scheduler branch from eb5ff4c to af8f92c Compare October 8, 2022 09:18
@ahg-g
Copy link
Member

ahg-g commented Oct 10, 2022

please squash

Signed-off-by: kerthcet <kerthcet@gmail.com>
@kerthcet kerthcet force-pushed the cleanup/optimize-new-scheduler branch from af8f92c to 1271786 Compare October 10, 2022 02:25
@kerthcet
Copy link
Member Author

Squashed @ahg-g

@kerthcet kerthcet changed the title Refactor newScheduler with builder pattern Remove newScheduler for reducing complexity Oct 10, 2022
@ahg-g
Copy link
Member

ahg-g commented Oct 10, 2022

/approve
/hold
leaving lgtm to Wei or Aldo

@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Oct 10, 2022
Copy link
Member

@alculquicondor alculquicondor left a 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 😃

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 11, 2022
@alculquicondor
Copy link
Member

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 11, 2022
@k8s-ci-robot
Copy link
Contributor

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

@k8s-ci-robot k8s-ci-robot merged commit 5113b70 into kubernetes:master Oct 11, 2022
@k8s-ci-robot k8s-ci-robot added this to the v1.26 milestone Oct 11, 2022
@kerthcet kerthcet deleted the cleanup/optimize-new-scheduler branch October 11, 2022 23:49
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. 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. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. release-note-none Denotes a PR that doesn't merit a release note. sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

unroll scheduler.New and remove Configurator
5 participants