Skip to content

fix(pods): translate observed generations for synced Pods - #4293

Open
Devin-Yue wants to merge 2 commits into
loft-sh:mainfrom
Devin-Yue:fix/pod-observed-generation-translation-20261124
Open

Devin-Yue wants to merge 2 commits into
loft-sh:mainfrom
Devin-Yue:fix/pod-observed-generation-translation-20261124

Conversation

@Devin-Yue

@Devin-Yue Devin-Yue commented Nov 24, 2026 •

Copy link
Copy Markdown

What issue type does this pull request address?
/kind bugfix

What does this pull request do? Which issues does it resolve?

A virtual Pod can change before its host Pod is created, for example when a scheduling gate is removed while the virtual scheduler is enabled. The two API servers then have different generation histories. Copying the host's observedGeneration unchanged can leave a genuinely terminated virtual Pod at generation/observedGeneration 3/2, then 4/2 after deletion. Controllers that require current termination evidence cannot safely make progress.

Record a host-owned, UID-fenced generation receipt after the translated host object has been accepted by the API server, using the returned generation and an optimistic-lock metadata patch. Translate Pod and condition observations through that receipt in both normal and deleting-host synchronization. A kubelet observation of the host DELETE generation proves the last accepted spec, so it maps to that virtual spec version rather than an unobserved newer virtual version. Missing, stale or mismatched receipts produce unknown observations instead of promoting them to the current generation.

Normalize virtual condition generations back into the host domain before bidirectional merging, and exclude the receipt from virtual annotation updates. Expected optimistic-lock conflicts requeue without emitting a misleading SyncError; genuine API failures still produce error events. Existing handling for virtual API servers that strip observed-generation fields remains in place.

Please provide a short message that should be published in the vcluster release notes

Fixed observed-generation translation for managed Pods with different host and virtual generation histories, including termination during deletion.

What else do we need to know?

  • The receipt uses vcluster.loft.sh/pod-generation-mapping on the host Pod. It is tied to both Pod UIDs and persists through syncer restarts.
  • No controller-side generation checks are relaxed. In particular, a pending virtual spec is not marked observed merely because an older host spec terminated.
  • The generation-aware status conversion is shared by normal synchronization and the host-deletion branch.

Validation:

  • The pre-materialization generation regression fails on unmodified v0.37.7 and passes with this change.
  • go test -mod=vendor -p=4 ./pkg/controllers/resources/pods/translate ./pkg/controllers/resources/pods ./pkg/patcher
  • go test -mod=vendor -p=4 -race ./pkg/controllers/resources/pods/translate ./pkg/controllers/resources/pods ./pkg/patcher
  • Real-kubelet CPU regression in a local Kubernetes/vCluster setup: gate removal before host creation, activeDeadlineSeconds termination, then ordinary deletion. Virtual generation/observedGeneration progresses through 2/2, 3/3, 4/3.
  • Real-kubelet delete-before-termination regression: a finite container exits successfully during graceful deletion. The host observes its DELETE generation while the virtual status correctly retains the last accepted virtual spec generation.
  • A production Sync regression verifies quiet conflict requeues and visible forbidden-operation errors.
  • Negative coverage includes stale status, unknown receipts, child-supplied receipts, mismatched Pod incarnations, unsynchronized host versions and pending virtual specs.

E2E Tests

The mandatory PR suite can run with the default selection. No new Ginkgo suite is introduced.

none

Note

Medium Risk
Touches core pod sync/status translation and failure signaling; incorrect mapping could misreport termination readiness, though receipts are conservative (unknown when unproven) and conflicts are handled quietly.

Overview
Introduces a host-owned generation receipt (vcluster.loft.sh/pod-generation-mapping) written on the host Pod after the translated spec is successfully accepted, and uses it to map observedGeneration between independent host and virtual generation histories.

Sync path: After CreateHostObject and successful bidirectional patch, the syncer calls RecordPodGenerationMapping with the API-returned host Pod (patcher.HostObject()). Status projection switches to DesiredVirtualPodStatus, which only translates kubelet-reported generations when the receipt proves which virtual spec the host accepted; otherwise observations are unknown (0). Condition merging normalizes virtual observed generations into the host domain via hostConditionGenerations. The receipt annotation is excluded from virtual annotation sync and stripped when translating virtual→host.

Operational behavior: Optimistic-lock conflicts on receipt recording requeue without SyncError events; non-conflict failures still emit sync errors. Host-deletion status propagation uses the same generation-aware status logic.

Tests: New unit/integration coverage for mapping recording, translation edge cases (deletion, stale/missing receipts), and conflict-vs-forbidden receipt patch behavior.

Reviewed by Cursor Bugbot for commit e646cda. Bugbot is set up for automated code reviews on this repo. Configure here.

@Devin-Yue
Devin-Yue requested review from a team as code owners November 24, 2026 12:36

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want fixes drafted automatically? Bugbot Autofix can create code changes for findings. A team admin can enable Autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 46c3650. Configure here.

This branch has not been deployed

No deployments
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.

1 participant