Skip to content

fix: requeue transient policy snapshot lookup errors - #796

Open
Jack Walker (jackwalkerlabs) wants to merge 1 commit into
kubefleet-dev:mainfrom
jackwalkerlabs:fix/scheduler-policy-snapshot-requeue
Open

fix: requeue transient policy snapshot lookup errors#796
Jack Walker (jackwalkerlabs) wants to merge 1 commit into
kubefleet-dev:mainfrom
jackwalkerlabs:fix/scheduler-policy-snapshot-requeue

Conversation

@jackwalkerlabs

Copy link
Copy Markdown

Description of your changes

The scheduler treated every failure to look up the latest policy snapshot as watcher-recoverable. That is correct when no latest snapshot exists (and for the multiple-active-snapshot invariant), but a transient API-server or cache List failure has no guaranteed follow-up event, so Forget could drop a quiet placement indefinitely.

This change branches on the two dedicated non-requeue sentinels. Those cases still call Forget, while all other lookup failures call AddRateLimited and retry with backoff.

Fixes #681

I have:

  • Associated this change with a known KubeFleet Issue (Bug, Feature, etc).
  • Run make reviewable to ensure this PR is ready for review.

How has this code been tested

  • Red on unchanged main: go test ./pkg/scheduler -run TestScheduleOncePolicySnapshotLookupErrors -count=1 failed because API-server and unexpected cache errors were forgotten instead of rate-limited.
  • Green after the fix: the same four-case regression passes for no snapshot, API-server failure, unexpected cache failure, and multiple active snapshots.
  • KUBEBUILDER_ASSETS="$(make --silent kubebuilder-assets-path)" go test ./pkg/scheduler/... -count=1
  • CGO_ENABLED=1 KUBEBUILDER_ASSETS="$(make --silent kubebuilder-assets-path)" go test ./pkg/scheduler -race -count=1
  • make reviewable
  • git diff --check

Special notes for your reviewer

There are no API or schema changes. The new scheduler-level test uses an intercepted fake client and a tracking queue so it can verify the exact Forget versus AddRateLimited decision without waiting on real backoff timers.

AI assistance disclosure: OpenAI Codex was used to help inspect the repository, implement the change, and run validation. I reviewed the complete diff and verified the red/green behavior locally.

Signed-off-by: Jack Walker <jackwalkerlabs@gmail.com>
@jackwalkerlabs
Jack Walker (jackwalkerlabs) requested a review from a team as a code owner August 5, 2026 22:25
@michaelawyu

Copy link
Copy Markdown
Member

Hi Jack! Thanks so much for the fix 🙏 I think it looks great.

@michaelawyu Chen Yu (michaelawyu) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Some minor comments. Thanks again for submitting the fix.

@@ -0,0 +1,146 @@
/*

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just a minor issue with the UTs: if possible, could this be merged into the current scheduler_test.go file?

"github.com/kubefleet-dev/kubefleet/pkg/scheduler/queue"
)

type trackingPlacementSchedulingQueue struct {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hi Jack! It might be easier to stub the rate limiter and use the simple queue instead. But that's not a blocker in any way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Scheduler drops placement from queue on transient apiserver errors during policy snapshot lookup

2 participants