Skip to content

Conversation

kfirtoledo
Copy link
Contributor

The schedulingContextState type was renamed to SchedulingContextState to make it accessible from other packages and enable sharing of prefix state across different plugins.

…lugins

Signed-off-by: Kfir Toledo <kfir.toledo@ibm.com>
Copy link

netlify bot commented Jun 25, 2025

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

Name Link
🔨 Latest commit 32c1cc2
🔍 Latest deploy log https://app.netlify.com/projects/gateway-api-inference-extension/deploys/685d1d60d8bde5000824023b
😎 Deploy Preview https://deploy-preview-1063--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 project configuration.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jun 25, 2025
@k8s-ci-robot k8s-ci-robot requested review from ahg-g and robscott June 25, 2025 16:47
@k8s-ci-robot
Copy link
Contributor

Hi @kfirtoledo. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jun 25, 2025
@kfirtoledo
Copy link
Contributor Author

/assign @liu-cong

@nirrozenbaum
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jun 25, 2025
@nirrozenbaum
Copy link
Contributor

this LGTM. overall the idea behind CycleState is to share state between different plugins.
for this to happen, the state struct should be public and not private (so other plugins can read it).
/approve

leaving final stamp for @liu-cong.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: kfirtoledo, 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 Jun 25, 2025
// getPrefixState returns the cycle state as a schedulingContextState.
func (m *Plugin) getPrefixState(cycleState *types.CycleState) (*schedulingContextState, error) {
// getPrefixState returns the cycle state as a SchedulingContextState.
func (m *Plugin) getPrefixState(cycleState *types.CycleState) (*SchedulingContextState, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

To share this state, I think we need to make the getPrefixState also public.

Copy link
Contributor Author

@kfirtoledo kfirtoledo Jun 25, 2025

Choose a reason for hiding this comment

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

This code will also work.

raw, err := cycleState.Read(prefix.PrefixCachePluginType)
	if err != nil {....}
prefixState, ok := raw.(*prefix.SchedulingContextState)

@nirrozenbaum also suggested a good idea to add a function like cycleState.ReadAsType to make it more generic instead of using specific get<XXX>State methods for each plugin. But in both cases, you still need to export SchedulingContextState.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is essentially duplicating this helper function. Let's make this also public so people don't need to do the error handling and type assertion.

Otherwise this looks good to me.

Copy link
Contributor

Choose a reason for hiding this comment

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

it won’t help to make this function public as long as it’s part of the prefix scorer.
different plugins don’t have access to the scorer, only to cycle state.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, actually this method doesn't need to be a method on the prefix Plugin. It can be its own standalone helper method.

Copy link
Contributor

Choose a reason for hiding this comment

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

if you decide to do that (not a big deal from my side if not, its 3 LoC), maybe you can extract state struct and the helper function to a different file. just to have all state related code organized together.

Copy link
Contributor Author

@kfirtoledo kfirtoledo Jun 26, 2025

Choose a reason for hiding this comment

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

@nirrozenbaum and @liu-cong, I replaced getPrefixState with a more generic function - PTAL

Copy link
Contributor

Choose a reason for hiding this comment

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

this looks great

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jun 26, 2025
Signed-off-by: Kfir Toledo <kfir.toledo@ibm.com>
@liu-cong
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 26, 2025
@k8s-ci-robot k8s-ci-robot merged commit 5f64c1d into kubernetes-sigs:main Jun 26, 2025
9 checks passed
EyalPazz pushed a commit to EyalPazz/gateway-api-inference-extension that referenced this pull request Jul 9, 2025
…lugins (kubernetes-sigs#1063)

* refactor: Allow export prefix SchedulingContextState for use across plugins

Signed-off-by: Kfir Toledo <kfir.toledo@ibm.com>

* refactor: replace getPrefixState with generic ReadCycleStateAs

Signed-off-by: Kfir Toledo <kfir.toledo@ibm.com>

---------

Signed-off-by: Kfir Toledo <kfir.toledo@ibm.com>
BenjaminBraunDev pushed a commit to BenjaminBraunDev/gateway-api-inference-extension that referenced this pull request Aug 12, 2025
…lugins (kubernetes-sigs#1063)

* refactor: Allow export prefix SchedulingContextState for use across plugins

Signed-off-by: Kfir Toledo <kfir.toledo@ibm.com>

* refactor: replace getPrefixState with generic ReadCycleStateAs

Signed-off-by: Kfir Toledo <kfir.toledo@ibm.com>

---------

Signed-off-by: Kfir Toledo <kfir.toledo@ibm.com>
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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants