Fix leftover importer pod blocking PVC deletion after a failed cleanup #4293
Hi @pujitha24. Thanks for your PR.
PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.
I understand the commands that are listed here.
<details>
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.
</details>
[APPROVALNOTIFIER] This PR is NOT APPROVED
This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign akalenyu for approval. For more information see the Code Review Process.
The full list of commands accepted by this bot can be found here.
<details open>
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment
</details>
<!-- META={"approvers":["akalenyu"]} -->
should we handle this on the predicate level? how come these make it into the queue at all?
thank you!
/test all

coverage: 49.862% (+0.05%) from 49.812% — pujitha24:auto/issue-4292 into kubevirt:main
They get in because the PVC watch in addImportControllerWatches is a plain EnqueueRequestForObject with no predicate, so every PVC event in the cluster gets queued and Reconcile does the filtering itself via shouldReconcilePVC. That test just pins down that my deletion-timestamp bypass doesn't widen that for PVCs without AnnEndpoint/AnnSource.
A predicate on that watch that drops PVCs without those two annotations does seem cleaner to me. It would change what the import controller enqueues in general though, so do you want it in this PR, or as a separate follow-up?
They get in because the PVC watch inaddImportControllerWatchesis a plainEnqueueRequestForObjectwith no predicate, so every PVC event in the cluster gets queued andReconciledoes the filtering itself viashouldReconcilePVC. That test just pins down that my deletion-timestamp bypass doesn't widen that for PVCs withoutAnnEndpoint/AnnSource.
> A predicate on that watch that drops PVCs without those two annotations does seem cleaner to me. It would change what the import controller enqueues in general though, so do you want it in this PR, or as a separate follow-up?
If it's otherwise equivalent (short circuited at predicate level instead of reconcile loop), we can include in this PR
They make it in because the PVC watch in addImportControllerWatches uses a plain EnqueueRequestForObject with no predicate, so every PVC in the cluster gets enqueued and Reconcile does the filtering itself via shouldReconcilePVC. That's how it works on main too, not something this PR adds. This test is only there to check that the new terminating-PVC case doesn't pick up unannotated PVCs. I agree a predicate that only lets through PVCs with AnnEndpoint/AnnSource would be cleaner. The upload and clone controllers have the same unfiltered PVC watch, and a predicate changes what reaches the queue for every event, not just the deletion path, so should I add it in this PR or send it as a separate follow-up?
They make it in because the PVC watch inaddImportControllerWatchesuses a plainEnqueueRequestForObjectwith no predicate, so every PVC in the cluster gets enqueued andReconciledoes the filtering itself viashouldReconcilePVC. That's how it works on main too, not something this PR adds. This test is only there to check that the new terminating-PVC case doesn't pick up unannotated PVCs. I agree a predicate that only lets through PVCs withAnnEndpoint/AnnSourcewould be cleaner. The upload and clone controllers have the same unfiltered PVC watch, and a predicate changes what reaches the queue for every event, not just the deletion path, so should I add it in this PR or send it as a separate follow-up?
Other ones can be in follow up
should we keep this test case in that case?
I'd lean towards keeping it. The predicate only covers the PVC watch, but the Pod owner watch still enqueues any PVC that controls a pod. The upload server pod is created with MakePVCOwnerReference, so a terminating upload PVC still lands in import Reconcile. I tried dropping && isImportPVC(pvc) from the gate locally and this test fails: the unannotated PVC gets requeued every 2s. That said, if you'd rather drop it, or reword it so it's clearly about the owner-watch path, I'm happy to do either.
/assign @akalenyu
The PVC watch predicate is in and the checks are green, so this should be ready for another look when you have time.
akalenyu
pujitha24
<!-- Thanks for sending a pull request! Here are some tips for you:
1. Follow the instructions for writing a release note from k8s: https://git.k8s.io/community/contributors/guide/release-notes.md
-->
What this PR does / why we need it:
If the importer pod delete in
updatePvcFromPodfails after a successful import (e.g. a transient API server error), the error is returned and the reconcile is requeued. On that requeue,shouldReconcilePVCreturnsfalsebecause the PVC's phase is alreadySucceeded, soReconcilereturns early and never retries the pod delete. The "PVC being terminated, delete pods" branch inreconcilePvcsits behind that same early-return check, so it is unreachable too — even after the PVC is deleted later, CDI never tries to remove the leftover pod. The pod keeps a controller owner reference (blockOwnerDeletion: true) to the PVC, and Kubernetes' pvc-protection controller treats any pod naming the PVC as a user regardless of phase, so the PVC'spvc-protectionfinalizer is never cleared and the PVC hangs inTerminatingindefinitely.This PR makes
Reconcileskip the early return for PVCs that CDI actually manages (has the importAnnEndpoint/AnnSourceannotations) while they are being deleted, soreconcilePvc's existing terminating-PVC branch can run and clean up a leftover importer pod even when the PVC itself was already marked complete. The gate is intentionally scoped to CDI import PVCs only (same annotation checkshouldReconcilePVCalready uses), so unrelated terminating PVCs that this controller merely watches are unaffected and don't pick up any extra reconcile activity.Per review, the import controller's PVC watch now also has a predicate that only admits PVCs with
AnnEndpoint/AnnSource, so unrelated PVCs are dropped before they reach the queue.Reconcilealready returned early for them, so this doesn't change behavior. The check inReconcileis kept because the Pod owner watch can still enqueue non-import PVCs. The same change for the upload and clone controllers is left for a follow-up.Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)format, will close the issue(s) when PR gets merged):Fixes #
Special notes for your reviewer:
This addresses the second of the two approaches suggested in the issue: run the "PVC being terminated, delete pods" branch even when the PVC is already complete, instead of retrying the initial post-import delete. It's the smaller, more surgical change of the two options.
Validation performed locally (no live cluster available in this environment):
go build ./pkg/controller/...andgo vet ./pkg/controller/...— clean.go test ./pkg/controller/ -run TestController— full existing suite (375 specs after the new tests) passes.Reconcilethrough the Pod owner watch).gofmt -lon the changed files: clean.golangci-lint(the repo's pinned v1.64.8) end to end: it fails with widespreadundefined: Expect/It/...typecheck errors across many pre-existing files inpkg/controller/unrelated to this change, reproducing identically against the unmodified tree — this looks like a localgo.workvendor sync issue in this environment (go build/go testprint benign "ignoring package ... missing from vendor/modules.txt" warnings but still succeed), not something introduced by this diff.ok-to-test.Release note:
<!-- Write your release note:
1. Enter your extended release note in the below block. If the PR requires additional action from users switching to the new release, include the string "action required".
2. If no release note is required, just write "NONE".
-->
``
release-noteTerminatingFixed a bug where a leftover importer pod could keep a PVC stuck in
forever if the pod's delete call failed once right after a successful import.
``Fixes #4292