Skip to content

fix(operator): key timed entity queue by uid to keep delete/recreate events apart - #1267

Merged
kimpenhaus merged 2 commits into
mainfrom
fix/queue-uid-key
Sep 30, 2026
Merged

kimpenhaus merged 2 commits into
mainfrom
fix/queue-uid-key

Conversation

@kimpenhaus

Copy link
Copy Markdown
Collaborator

Fixes #1266

Problem

TimedEntityQueue<TEntity> keyed pending entries by namespace/name, and its merge logic preserved a pending Deleted reconciliation type while taking over the incoming entity. When an object was deleted and a new object with the same name was created while the Deleted entry was still pending (one 100 ms promotion tick for watch events, the full backoff for a failed DeletedAsync retry), the two different objects were coalesced:

  • DeletedAsync was invoked with the new, still existing object.
  • The new object's Added reconciliation was lost. Because the watcher's UID-keyed generation cache had already recorded the new object's generation, it stayed unreconciled until a spec change or a watch re-list.

The same happened in reverse when a Deleted error-retry of the old object hit a pending Added of the new one.

The name-based key dates back to #801, which added the namespace to the original name-only key (#800); the UID was never considered. All other identity-sensitive components of the pipeline (watcher dedup cache, shared pipeline membership, per-entity reconcile locks) are already UID-based.

Changes

  • TimedEntityQueueExtensions.GetKey now returns the entity's UID and falls back to namespace/name only for entities without a UID (e.g. locally constructed objects passed to EntityQueue<T>). The Deleted-preserving merge rule is unchanged, but now only applies to events of the same object.
  • EntityQueueBackgroundService.ReconcileSingleAsync skips a non-deleted entry when the object loaded by name has a different UID than the queued entity. Without this, a stale entry of a deleted object (e.g. a pending requeueAfter whose Deleted event was never observed because of a re-list) would reconcile the recreated object under the old UID's lock, i.e. potentially concurrently with the recreated object's own entry.
  • Docs: queue-strategy.mdx describes the UID-based de-duplication contract; controllers.mdx notes that DeletedAsync of a deleted object and ReconcileAsync of its recreated namesake are independent and may run in any order or in parallel.

Behaviour change

No public API signature changes, but observable behaviour changes:

  • A delete/recreate under the same name now yields both reconciliations: DeletedAsync with the old object and ReconcileAsync with the new one. They are not ordered relative to each other.
  • GetKey returns the UID for entities that have one. Custom ITimedEntityQueue<T> implementations following the documented contract should de-duplicate by UID as well.

Tests

  • TimedEntityQueue: the reproduction from the issue (pending Deleted + Added of the recreated object), the reverse case (Deleted retry + pending Added), merge of same-UID entries, and the GetKey UID/fallback behaviour.
  • EntityQueueBackgroundService: a stale entry is skipped when the object was recreated.
  • ScopeAwareEntityQueueBackgroundService tests used different UIDs only to label "snapshot" and "current" state of the same object; they now share the UID and differ by resource version.

…events apart

TimedEntityQueue keyed pending entries by namespace/name and preserved a
pending Deleted type on merge while taking over the incoming entity. When an
object was deleted and recreated under the same name within the coalescing
window, the new object's Added was merged into the old object's Deleted:
DeletedAsync received the live object and the new object was never
reconciled until a generation bump or re-list.

Entries are now keyed by the object's UID (falling back to namespace/name
for entities without a UID), so the old object's Deleted and the new
object's Added are scheduled independently. Non-deleted entries whose name
now resolves to a different (recreated) object are skipped on dequeue, as
that object is reconciled through its own entry.

Fixes #1266
@kimpenhaus
kimpenhaus enabled auto-merge (squash) September 30, 2026 20:03
@kimpenhaus
kimpenhaus merged commit 283c508 into main Sep 30, 2026
5 checks passed
@kimpenhaus
kimpenhaus deleted the fix/queue-uid-key branch September 30, 2026 20:09
@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 13.3.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug]: TimedEntityQueue coalesces a recreated object's Added into the namesake's pending Deleted — the new object is never reconciled

1 participant