-
Notifications
You must be signed in to change notification settings - Fork 201
Enhancement - Cleanup Orphaned PVCs #3789
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Enhancement - Cleanup Orphaned PVCs #3789
Conversation
|
Skipping CI for Draft Pull Request. |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: kolluria The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
@kolluria: GitHub didn't allow me to request PR reviews from the following users: skogta. Note that only kubernetes-sigs members and repo collaborators can review this PR, and authors cannot review their own PRs. |
a32f8f8 to
18fa18d
Compare
|
FAILED --- Jenkins Build #651 |
18fa18d to
c560755
Compare
c560755 to
d5b849c
Compare
|
Triggering CSI-WCP Pre-checkin Pipeline for this PR... Job takes approximately an hour to complete |
|
FAILED --- Jenkins Build #655 |
| } | ||
|
|
||
| // map to hold all the PVCs that have the finalizer added by the batch attach reconciler | ||
| pvcMap := make(map[string]map[string]struct{}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A description of what this map holds will be helpful
|
|
||
| // map to hold all the PVCs that have the finalizer added by the batch attach reconciler | ||
| pvcMap := make(map[string]map[string]struct{}) | ||
| for _, pvc := range pvcList { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider only those PVCs which have deletion timestamp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be a more general purpose finalizer remover. We do not have to wait for the pvc to get deleted to cleanup - as long as a PVC has the finalizer but no batch attach CR, the finalizer can be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, there can be PVCs being used by pod VMs or attached via the old CnsNodeVMAttachment CR. We should not be removing finalizer from them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. I see that older node vm attach and file access configs are also using this CR - but PodVMs won't have this finalizer on them.
Let me think more on how to address this.
|
SUCCESS --- Jenkins Build #718 |
Summary
Implements a periodic cleanup routine to remove orphaned CNS finalizers from PVCs when CnsNodeVMBatchAttachment CRs are deleted before removing PVC finalizers, preventing stuck PVCs and blocked namespace deletions.
Problem
During namespace deletion or manual disk detachment scenarios, the CnsNodeVMBatchAttachment reconciler can remove the finalizer from the CRD before removing finalizers from associated PVCs. This causes:
cns.vmware.com/pvc-protectionfinalizerRoot Cause
The issue manifests in scenarios where a volume entry is removed from the CnsNodeVmBatchAttach spec and the underlying VM is deleted simulatenously.
In such scenarios, the finalizer from the LOST PVC never gets removed leaving it perpetually stuck in terminating state.
Solution
Introduced
cleanupPVCs()cleanup routine that:cns.vmware.com/pvc-protectionfinalizerIt runs periodically similar to existing CnsRegisterVolume and CnsUnregisterVolume cleanup routines.
Testing Done
Test Scenarios
Scenario 1: PVC attached to a Pod ✓
Expected: Ignored by cleanup (not processed)
Result: PASS
Scenario 2: PVC actively attached to a VM ✓
Expected: Finalizer preserved (PVC still in CR spec)
Result: PASS
Scenario 3: Orphaned PVC ✓
Simulated this by manually adding the finalizer on the PVC.
Expected: Finalizer removed (PVC not in any CR spec)
Result: PASS
Scenario 4: Unused PVCs ✓
Expected: No Op
Result: Pass
Verification
Deleted all the PVCs and verified that that the PVCs that are still in use are stuck in Terminating state while both the unused PVCs and the orphaned PVCs got cleaned up.
Test Results
All 4 test scenarios passed successfully:
Safety Considerations
Special Notes for Reviewer
cleanUpCnsRegisterVolumeInstancesandcleanUpCnsUnregisterVolumeInstancesroutines (infinite loop with sleep intervals)Release Note