Skip to content

cleanup(flowcontrol): Refactor registry with generic leasing and atomic GC#2198

Merged
k8s-ci-robot merged 1 commit into
kubernetes-sigs:mainfrom
LukeAVanDrie:refactor/registry-deduplication
Jan 28, 2026
Merged

cleanup(flowcontrol): Refactor registry with generic leasing and atomic GC#2198
k8s-ci-robot merged 1 commit into
kubernetes-sigs:mainfrom
LukeAVanDrie:refactor/registry-deduplication

Conversation

@LukeAVanDrie
Copy link
Copy Markdown
Contributor

What type of PR is this?

/kind cleanup
/kind test

What this PR does / why we need it:

This PR refactors the FlowRegistry to extract the optimistic resource leasing and garbage collection logic into a dedicated, generic leasing.go file. Previously, the "Check-Pin-Retry" loops and "Mark-and-Sweep" GC logic were duplicated for both Flows and Priority Bands. This duplication obscured the critical concurrency safety invariants.

Key Changes:

  • Introduced leasedState and pinLeasedResource. This encapsulates the complex lock-free retry loops, sync.Once handling, etc. into a single, reusable primitive.
  • Leveraged generics to deduplicate the GC logic (collectLeasedResources). This ensures that Flows and Priority Bands adhere to identical lifecycle safety contracts.
  • Added leasing_test.go with unit tests for the leasedState state machine and a high-contention chaos test verifying that "Pin vs GC" races result in deterministic behavior without data corruption.

Which issue(s) this PR fixes:

Cleanup following #2127 and #2097. Pure refactoring for maintainability, not tracked in any issue.

Does this PR introduce a user-facing change?:

NONE

Extract generic leasing and GC logic into leasing.go to reduce
duplication and complexity. Inline helper methods into WithConnection.
Add leasing_test.go with concurrency coverage.
@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 Jan 23, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

@LukeAVanDrie: The label(s) kind/test cannot be applied, because the repository doesn't have them.

Details

In response to this:

What type of PR is this?

/kind cleanup
/kind test

What this PR does / why we need it:

This PR refactors the FlowRegistry to extract the optimistic resource leasing and garbage collection logic into a dedicated, generic leasing.go file. Previously, the "Check-Pin-Retry" loops and "Mark-and-Sweep" GC logic were duplicated for both Flows and Priority Bands. This duplication obscured the critical concurrency safety invariants.

Key Changes:

  • Introduced leasedState and pinLeasedResource. This encapsulates the complex lock-free retry loops, sync.Once handling, etc. into a single, reusable primitive.
  • Leveraged generics to deduplicate the GC logic (collectLeasedResources). This ensures that Flows and Priority Bands adhere to identical lifecycle safety contracts.
  • Added leasing_test.go with unit tests for the leasedState state machine and a high-contention chaos test verifying that "Pin vs GC" races result in deterministic behavior without data corruption.

Which issue(s) this PR fixes:

Cleanup following #2127 and #2097. Pure refactoring for maintainability, not tracked in any issue.

Does this PR introduce a user-facing change?:

NONE

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.

@netlify
Copy link
Copy Markdown

netlify Bot commented Jan 23, 2026

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

Name Link
🔨 Latest commit d22e721
🔍 Latest deploy log https://app.netlify.com/projects/gateway-api-inference-extension/deploys/6972bc72f82f2100082cac24
😎 Deploy Preview https://deploy-preview-2198--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 Jan 23, 2026
@k8s-ci-robot k8s-ci-robot requested review from ahg-g and kfswain January 23, 2026 00:10
@k8s-ci-robot k8s-ci-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Jan 23, 2026
@LukeAVanDrie
Copy link
Copy Markdown
Contributor Author

/assign @evacchi
/assign @aishukamal

This is purely a cleanup effort based on some of the discussion on the flow and band leasing PRs we deferred. It should be functionally equivalent but nearly fully deduped between these resource types now. Trying to make this pattern a bit more maintainable and reduce cognitive load. leasing.go is still quite complex, but it is at least well-encapsulated now.

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

@LukeAVanDrie: GitHub didn't allow me to assign the following users: evacchi, aishukamal.

Note that only kubernetes-sigs members with read permissions, repo collaborators and people who have commented on this issue/PR can be assigned. Additionally, issues/PRs can only have 10 assignees at the same time.
For more information please see the contributor guide

Details

In response to this:

/assign @evacchi
/assign @aishukamal

This is purely a cleanup effort based on some of the discussion on the flow and band leasing PRs we deferred. It should be functionally equivalent but nearly fully deduped between these resource types now. Trying to make this pattern a bit more maintainable and reduce cognitive load. leasing.go is still quite complex, but it is at least well-encapsulated now.

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.

@ahg-g
Copy link
Copy Markdown
Contributor

ahg-g commented Jan 28, 2026

/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 Jan 28, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

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

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details 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 Jan 28, 2026
@k8s-ci-robot k8s-ci-robot merged commit aea9ebe into kubernetes-sigs:main Jan 28, 2026
11 checks passed
elevran pushed a commit to llm-d/llm-d-router that referenced this pull request Apr 23, 2026
…ay-api-inference-extension#2198)

Extract generic leasing and GC logic into leasing.go to reduce
duplication and complexity. Inline helper methods into WithConnection.
Add leasing_test.go with concurrency coverage.
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. 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.

3 participants