Skip to content

Conversation

@nirrozenbaum
Copy link
Contributor

@nirrozenbaum nirrozenbaum commented May 8, 2025

This PR simplifies scheduler filters structuring in order to simplify, improve readability and maintainability, and align with best practices.

  • removes the unnecessary use of global vars.
  • encapsulates and simplify each filter in its own file.
  • update the tests accordingly.

NO LOGIC CHANGE, only moving existing filters/logic to separate files.

the plugins that live in this repo should serve as an example for newcomers and adopters and as such, it's required to have the most simplified and aligned with best practices code.

not in scope of this PR:
handling of any scheduler package other than filter. any additional change will come in a separate PR.

@netlify
Copy link

netlify bot commented May 8, 2025

Deploy Preview for gateway-api-inference-extension ready!

Name Link
🔨 Latest commit eb5da45
🔍 Latest deploy log https://app.netlify.com/sites/gateway-api-inference-extension/deploys/681d0eee7edce00008953583
😎 Deploy Preview https://deploy-preview-797--gateway-api-inference-extension.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label May 8, 2025
@k8s-ci-robot k8s-ci-robot requested review from danehans and kfswain May 8, 2025 10:40
@k8s-ci-robot k8s-ci-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label May 8, 2025
@ahg-g ahg-g mentioned this pull request May 8, 2025
@liu-cong
Copy link
Contributor

liu-cong commented May 8, 2025

/assign

Copy link
Contributor

@liu-cong liu-cong left a comment

Choose a reason for hiding this comment

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

a few nits, will lgtm once #802 is merged

Thanks for the cleanup!

@nirrozenbaum
Copy link
Contributor Author

a few nits, will lgtm once #802 is merged

Thanks for the cleanup!

@liu-cong fixed all nits and rebased to incorporate the your changes from #802.
ready for final review.

Comment on lines -50 to -56
var defaultConfig = &SchedulerConfig{
preSchedulePlugins: []plugins.PreSchedule{},
filters: []plugins.Filter{&filter.SheddableRequestFilter{}, filter.LowLatencyFilter},
scorers: map[plugins.Scorer]int{},
picker: &picker.RandomPicker{},
postSchedulePlugins: []plugins.PostSchedule{},
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

after having some experience with setting a custom plugins, the recommended way would be to set in main.go the scheduler using NewSchedulerWithConfig.
no need for global var. default configuration is defined inside NewScheduler instead.

Comment on lines +47 to +50
// Filter filters out pods that doesn't meet the filter criteria.
func (f *HasCapacityFilter) Filter(ctx *types.SchedulingContext, pods []types.Pod) []types.Pod {
filteredPods := []types.Pod{}

Copy link
Contributor Author

@nirrozenbaum nirrozenbaum May 8, 2025

Choose a reason for hiding this comment

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

I'm reading this now again (reviewing myself lol).
@liu-cong does it make sense to get rid of Sheddable filter and put the following condition here at the beginning of the filter func?

if ctx.Req.Critical {
    return pods
}

sheddable filter doesn't do anything other than that..
anyway, if you agree with me, please let's defer to next PR since this is large enough and I don't want to include more changes unless it's a must.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah it makes sense to combine the two, perhaps call it HasCapacityForSheddableRequestFilter. Feel free to refactor or defer it.

@nirrozenbaum nirrozenbaum requested a review from liu-cong May 8, 2025 20:15
Copy link
Contributor

@liu-cong liu-cong left a comment

Choose a reason for hiding this comment

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

/lgtm

Thanks

Comment on lines +47 to +50
// Filter filters out pods that doesn't meet the filter criteria.
func (f *HasCapacityFilter) Filter(ctx *types.SchedulingContext, pods []types.Pod) []types.Pod {
filteredPods := []types.Pod{}

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah it makes sense to combine the two, perhaps call it HasCapacityForSheddableRequestFilter. Feel free to refactor or defer it.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 8, 2025
@ahg-g
Copy link
Contributor

ahg-g commented May 8, 2025

/approve
/hold

in case you want to address fusing the two filters into one

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 8, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ahg-g, nirrozenbaum

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 May 8, 2025
@nirrozenbaum
Copy link
Contributor Author

/unhold
will push the merging of the filter in a follow up.
I prefer not to hold this one open since it's big.

@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 May 8, 2025
@kfswain
Copy link
Collaborator

kfswain commented May 8, 2025

/lgtm

Great stuff!

@k8s-ci-robot k8s-ci-robot merged commit d212757 into kubernetes-sigs:main May 8, 2025
8 checks passed
@nirrozenbaum nirrozenbaum deleted the filter-refactor branch May 8, 2025 20:52
nayihz pushed a commit to nayihz/gateway-api-inference-extension that referenced this pull request May 14, 2025
* refactor schdeuler filters package to simplify and improve readability and maintainability

Signed-off-by: Nir Rozenbaum <[email protected]>

* filter refactor finalizing

Signed-off-by: Nir Rozenbaum <[email protected]>

---------

Signed-off-by: Nir Rozenbaum <[email protected]>
kaushikmitr pushed a commit to kaushikmitr/llm-instance-gateway that referenced this pull request May 15, 2025
* refactor schdeuler filters package to simplify and improve readability and maintainability

Signed-off-by: Nir Rozenbaum <[email protected]>

* filter refactor finalizing

Signed-off-by: Nir Rozenbaum <[email protected]>

---------

Signed-off-by: Nir Rozenbaum <[email protected]>
rlakhtakia pushed a commit to rlakhtakia/gateway-api-inference-extension that referenced this pull request Jun 11, 2025
* refactor schdeuler filters package to simplify and improve readability and maintainability

Signed-off-by: Nir Rozenbaum <[email protected]>

* filter refactor finalizing

Signed-off-by: Nir Rozenbaum <[email protected]>

---------

Signed-off-by: Nir Rozenbaum <[email protected]>
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. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants