Skip to content

fix: clear PV ClaimRef on release and fix VolumeName translation - #4035

Open
jainbhavya65 wants to merge 2 commits into
loft-sh:mainfrom
jainbhavya65:fix/pv-claimref-lifecycle
Open

fix: clear PV ClaimRef on release and fix VolumeName translation#4035
jainbhavya65 wants to merge 2 commits into
loft-sh:mainfrom
jainbhavya65:fix/pv-claimref-lifecycle

Conversation

@jainbhavya65

@jainbhavya65 jainbhavya65 commented Jun 25, 2026

Copy link
Copy Markdown

What issue type does this pull request address? (keep at least one, remove the others)
kind bug
kind fix

What does this pull request do? Which issues does it resolve? (use resolves #<issue_number> if possible)
Fixes PV ClaimRef being incorrectly cleared when PVC is deleted with Retain policy.
Fixes PV stuck in Released phase after admin clears ClaimRef.
Fixes host PV deletion not propagating to virtual PV.
Fixes VolumeName double-wrapping for dynamically provisioned PVs.

Please provide a short message that should be published in the vcluster release notes
Fixed PersistentVolume lifecycle sync: ClaimRef now preserved on Released PVs matching standard Kubernetes behavior, admin-cleared ClaimRef correctly propagates to host allowing PV reuse, host PV deletion cleans up virtual PV, and VolumeName translation no longer double-wraps dynamic PV names.

What else do we need to know?

Changes in pkg/controllers/resources/persistentvolumes/:

SyncToHost: host-originated PVs no longer incorrectly deleted; ClaimRef clearing on virtual PV propagates to host
Sync + SyncToVirtual: host PV deletion now deletes virtual PV
shouldSync: Available PVs with existing virtual PV continue syncing instead of being deleted
translate.go: nil-safety guards for ClaimRef access during PVC deletion transitions
Changes in pkg/controllers/resources/persistentvolumeclaims/:

translate.go: VolumeName uses PV mapper (mappings.VirtualToHostName) to prevent double-wrapping
E2E Tests
Default Test Execution
The mandatory PR suite runs automatically. Only specify additional test suites below if needed.

Additional test suites
Additional test suite(s) that will be executed before the mandatory PR suite:


Note

Medium Risk
Changes core PV/PVC sync paths that affect reclaim, binding, and deletion propagation between host and virtual clusters.

Overview
Fixes PersistentVolume and PVC sync behavior around Retain reclaim, ClaimRef clearing, host deletion, and VolumeName mapping.

PV syncer no longer treats host-originated PVs (annotated with HostClusterPersistentVolumeAnnotation) as delete-on-sync; clearing ClaimRef on the virtual PV now propagates to a Released host PV so both can move to Available. Host PV deletion triggers virtual PV deletion in Sync and SyncToVirtual. shouldSync keeps syncing host PVs that have no ClaimRef when a matching virtual PV still exists (status updates). translateUpdateBackwards allows copying a cleared ClaimRef from the host while still blocking new claim refs when the host PV is Available.

PVC translate replaces blind HostNameCluster on VolumeName with logic that uses the host PV name from the annotation when the PV was synced from the host, leaves the name unchanged if a host PV with that name already exists, and only translates otherwise—avoiding double-wrapping of dynamic PV names.

Adds a Retain reclaim e2e case (PVC delete → PV Available on vCluster and host) and wires WithContext(ctx) on existing Eventually polls; adds a PVC syncer unit test for VolumeName when PV sync is enabled.

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

@jainbhavya65
jainbhavya65 requested review from a team as code owners June 25, 2026 15:34
Comment thread pkg/controllers/resources/persistentvolumes/translate.go
Comment thread e2e/test_core/sync/test_pvc.go Outdated
Comment thread pkg/controllers/resources/persistentvolumes/translate.go
Comment thread pkg/controllers/resources/persistentvolumeclaims/translate.go Outdated
- Use mappings.VirtualToHostName instead of HostNameCluster for
  VolumeName to prevent double-wrapping of dynamic PV names
- Clear ClaimRef on Released host PVs when PVC is deleted and
  reclaimPolicy is Retain
- Add nil-safety guards in translateUpdateBackwards
@jainbhavya65
jainbhavya65 force-pushed the fix/pv-claimref-lifecycle branch from 7842ed8 to daadb3a Compare June 25, 2026 16:53

@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.

Reviewed by Cursor Bugbot for commit daadb3a. Configure here.

Comment thread pkg/controllers/resources/persistentvolumes/syncer.go
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