← Back to Pull requests

Keep requiresDirectIo while a cache=trynone import is still running or needs scratch space #4331

Open
jay23606 opened this pull request with 141 lines diff across 2 files
View on GitHub
jay23606 jay23606 commented on Oct 29, 2026 17:28 UTC
Author

Bug

For a cache=trynone import, updatePvcFromPod set requiresDirectIo to false on every reconcile where the pod env had cache=trynone, including while the pod was still running or after it had asked for scratch space. An OOM-driven retry therefore lost the flag, and the next OOM restarted the cycle: scratch space, then OOM, then scratch space again.

Change

The flag is now cleared only when the pod has Succeeded and podModificationsNeeded is false, so a running pod or a scratch-space restart keeps requiresDirectIo.

Testing

Three specs in pkg/controller/import-controller_test.go cover the clause:

  • a running cache=trynone pod keeps requiresDirectIo;

  • a succeeded cache=trynone pod that needs scratch space keeps requiresDirectIo;

  • a succeeded cache=trynone pod that does not need scratch space clears it.
  • Run with go test ./pkg/controller/ -run TestController -count=1 -ginkgo.focus="requiresDirectIo". The focused run passes on the fix. On the base controller, the running and scratch-space specs fail.

    The full go test ./pkg/controller/ -run TestController -count=1 -ginkgo.no-color run has one failure, a DataImportCron spec.

    Regression test: fails on base three times, passes on fix three times (go test ./pkg/controller/ -run TestController -count=1 -ginkgo.focus="requiresDirectIo")

    Fixes #4329

    Release note

    ``release-note
    Fixed cache=trynone imports clearing requiresDirectIo while the pod is still running or after it requests scratch space, which caused repeated OOM and scratch-space cycles.
    ``

    Diff: 141 lines (+139 / -2) across 2 files Reviewer: akalenyu Review duration: 49640m
    All Vouch review confidence checks passed
    Residual risk 0.05 = Change Risk (0.41) × (1 − Review Confidence (0.88)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.41 · 141 lines diff across 2 files
    0.41
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.88 · 5 substantive comment(s)
    0.88
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    88%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.296
    Real PR Conversation Timeline
    16 items
    kubevirt-prow[bot] kubevirt-prow[bot] commented on Oct 29, 2026 17:28 UTC
    Bot

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

    kubevirt-prow[bot] kubevirt-prow[bot] commented on Oct 29, 2026 17:28 UTC
    Bot

    [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 aglitke 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:

  • OWNERS
  • 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":["aglitke"]} -->

    akalenyu akalenyu commented on Oct 30, 2026 15:33 UTC
    Contributor

    Thanks! such a coincidence, was just looking at failures in kubevirt/kubevirt CI related to this:
    https://prow.ci.kubevirt.io/view/gs/kubevirt-prow/pr-logs/pull/kubevirt_kubevirt/19690/pull-kubevirt-e2e-k8s-1.37-sig-compute-migrations-1.10/2116128934419501056

    In my case I think that the real issue is that OOMKilled reason is not reported, I don't even see the logs spotting it in the pod status. Are you sure this is actually an issue? I can't debug this rn but I am pretty sure the mechanism was intact for ages with this env var handling exactly as is.

    jay23606 jay23606 commented on Nov 07, 2026 09:49 UTC
    Author

    No code change this round. The old clause cleared requiresDirectIo on any reconcile where the pod env had cache=trynone, including while that pod was still Pending or Running, and that env is only set because the flag was true, so the flag was dropped before the retry finished; the three focused requiresDirectIo specs pass on this branch. This PR does not touch the path where OOMKilled never reaches the container status, and I did not check the linked CI run.

    akalenyu akalenyu commented on code on Nov 08, 2026 11:51 UTC
    Code Review
    pkg/controller/import-controller.go:1
    @@ -461,7 +461,7 @@ func (r *ImportReconciler) updatePvcFromPod(pvc *corev1.PersistentVolumeClaim, p
     	}
     
     	for _, ev := range pod.Spec.Containers[0].Env {
    -		if ev.Name == common.CacheMode && ev.Value == common.CacheModeTryNone {
    +		if ev.Name == common.CacheMode && ev.Value == common.CacheModeTryNone && pod.Status.Phase == corev1.PodSucceeded && !podModificationsNeeded {

    I think the right fix would be to stop setting false here and just harden ShouldDeletePod against deleting a pod that already has this env var (instead of just based on the ann existence)

    jay23606 jay23606 commented on Nov 08, 2026 17:54 UTC
    Author

    @akalenyu thanks for the pointer. Before I change the code I need a design call, because the suggestion conflicts with current behaviour:

  • AnnRequiresDirectIO is set to "true" on OOM and cleared to "false" in updatePvcFromPod. If the clear is removed, the annotation stays "true" after a successful try-none import. That keeps forcing cacheMode=trynone on future pods and keeps ShouldDeletePod true.

  • ShouldDeletePod takes only the PVC, so refusing to delete a pod that has the env var needs a signature change (it has seven callers).

  • The existing test that expects the annotation to be cleared to "false" would need to change.
  • Which do you want: (a) keep the annotation "true" after success, and how should completed try-none pods be cleaned up; or (b) keep clearing it on success and harden ShouldDeletePod another way?

    jay23606 jay23606 commented on code on Nov 11, 2026 03:39 UTC
    Code Review
    pkg/controller/import-controller.go:1
    @@ -461,7 +461,7 @@ func (r *ImportReconciler) updatePvcFromPod(pvc *corev1.PersistentVolumeClaim, p
     	}
     
     	for _, ev := range pod.Spec.Containers[0].Env {
    -		if ev.Name == common.CacheMode && ev.Value == common.CacheModeTryNone {
    +		if ev.Name == common.CacheMode && ev.Value == common.CacheModeTryNone && pod.Status.Phase == corev1.PodSucceeded && !podModificationsNeeded {

    Thanks. Agreed the annotation-clearing condition is the weak point. I'd like to take the approach of keeping requiresDirectIo set by hardening ShouldDeletePod so it does not delete a pod that still carries CACHE_MODE=TRYNONE and has not finished, rather than clearing the annotation in updatePvcFromPod. ShouldDeletePod only receives the PVC today, and it has about seven callers (clone, pvc-clone, forklift populator, upload, import). So the change needs either a new helper that takes the pod, or a PVC-level signal for the cache mode. Which one do you prefer?

    akalenyu akalenyu commented on code on Nov 11, 2026 10:47 UTC
    Code Review
    pkg/controller/import-controller.go:1
    @@ -461,7 +461,7 @@ func (r *ImportReconciler) updatePvcFromPod(pvc *corev1.PersistentVolumeClaim, p
     	}
     
     	for _, ev := range pod.Spec.Containers[0].Env {
    -		if ev.Name == common.CacheMode && ev.Value == common.CacheModeTryNone {
    +		if ev.Name == common.CacheMode && ev.Value == common.CacheModeTryNone && pod.Status.Phase == corev1.PodSucceeded && !podModificationsNeeded {

    Can we gate the call to ShouldDeletePod instead of having to extend it?

    jay23606 jay23606 commented on code on Nov 11, 2026 11:18 UTC
    Code Review
    pkg/controller/import-controller.go:1
    @@ -461,7 +461,7 @@ func (r *ImportReconciler) updatePvcFromPod(pvc *corev1.PersistentVolumeClaim, p
     	}
     
     	for _, ev := range pod.Spec.Containers[0].Env {
    -		if ev.Name == common.CacheMode && ev.Value == common.CacheModeTryNone {
    +		if ev.Name == common.CacheMode && ev.Value == common.CacheModeTryNone && pod.Status.Phase == corev1.PodSucceeded && !podModificationsNeeded {

    Yes, gated at the call site. ShouldDeletePod keeps its signature and its seven callers are untouched.

    In updatePvcFromPod, the cleanup now runs only when !isTryNoneInProgress(pod) && cc.ShouldDeletePod(pvc). isTryNoneInProgress returns true when the import pod has CACHE_MODE=trynone and its phase is neither Succeeded nor Failed. A try-none pod that is still running (for example one OOM-killed and restarted in place, since the import pod uses RestartPolicyOnFailure) is no longer deleted, so requiresDirectIo is not dropped before its retry finishes. updatePvcFromPod's annotation handling is unchanged.

    Test: added a spec in import-controller_test.go ("Should not delete a running cache=trynone pod that was OOM killed and restarted in place"). It failed before the change (the pod was deleted) and passes after. The focused requiresDirectIo specs pass. Full pkg/controller run: all new and related specs pass; one DataImportCron spec (LastUseTime comparison) is flaky and also fails on the base commit, so it is unrelated.

    Caveat: a try-none pod that OOMs again in place stays alive until it reaches a terminal phase, rather than being deleted and recreated.

    jay23606 jay23606 commented on code on Nov 12, 2026 17:13 UTC
    Code Review
    pkg/controller/import-controller.go:1
    @@ -461,7 +461,7 @@ func (r *ImportReconciler) updatePvcFromPod(pvc *corev1.PersistentVolumeClaim, p
     	}
     
     	for _, ev := range pod.Spec.Containers[0].Env {
    -		if ev.Name == common.CacheMode && ev.Value == common.CacheModeTryNone {
    +		if ev.Name == common.CacheMode && ev.Value == common.CacheModeTryNone && pod.Status.Phase == corev1.PodSucceeded && !podModificationsNeeded {

    No change this round. Removing the clear would leave requiresDirectIo set after a successful import, so later imports would keep cache=trynone and ShouldDeletePod would always return true. The running-pod check already sits at the call site (import-controller.go:514), so ShouldDeletePod does not need the pod.

    jay23606 jay23606 commented on code on Nov 12, 2026 17:13 UTC
    Code Review
    pkg/controller/import-controller.go:1
    @@ -461,7 +461,7 @@ func (r *ImportReconciler) updatePvcFromPod(pvc *corev1.PersistentVolumeClaim, p
     	}
     
     	for _, ev := range pod.Spec.Containers[0].Env {
    -		if ev.Name == common.CacheMode && ev.Value == common.CacheModeTryNone {
    +		if ev.Name == common.CacheMode && ev.Value == common.CacheModeTryNone && pod.Status.Phase == corev1.PodSucceeded && !podModificationsNeeded {

    No change this round: the ShouldDeletePod call at import-controller.go:514 is already gated by !isTryNoneInProgress(pod), and ShouldDeletePod in pkg/controller/common/util.go is unchanged.

    jay23606 jay23606 commented on Nov 12, 2026 17:13 UTC
    Author

    I could not reproduce your CI failure here, so I can't say whether OOMKilled appears in that run's pod status. The flag is cleared only after a successful run, so a running cache=trynone pod keeps requiresDirectIo regardless of what the status reports, and the OOM check reads LastTerminationState as well as State (import-controller.go:1588).

    jay23606 jay23606 commented on code on Nov 12, 2026 19:13 UTC
    Code Review
    pkg/controller/import-controller.go:1
    @@ -461,7 +461,7 @@ func (r *ImportReconciler) updatePvcFromPod(pvc *corev1.PersistentVolumeClaim, p
     	}
     
     	for _, ev := range pod.Spec.Containers[0].Env {
    -		if ev.Name == common.CacheMode && ev.Value == common.CacheModeTryNone {
    +		if ev.Name == common.CacheMode && ev.Value == common.CacheModeTryNone && pod.Status.Phase == corev1.PodSucceeded && !podModificationsNeeded {

    No change in this round; I'm declining this one. Clearing the flag only on success is deliberate: if we stop writing false, a finished try-none import keeps requiresDirectIo=true, and ShouldDeletePod treats that flag as a reason to delete the pod. ShouldDeletePod also takes only the PVC and is shared by the clone, upload, and populator controllers, so teaching it about the pod env would change those paths too.

    jay23606 jay23606 commented on code on Nov 12, 2026 19:13 UTC
    Code Review
    pkg/controller/import-controller.go:1
    @@ -461,7 +461,7 @@ func (r *ImportReconciler) updatePvcFromPod(pvc *corev1.PersistentVolumeClaim, p
     	}
     
     	for _, ev := range pod.Spec.Containers[0].Env {
    -		if ev.Name == common.CacheMode && ev.Value == common.CacheModeTryNone {
    +		if ev.Name == common.CacheMode && ev.Value == common.CacheModeTryNone && pod.Status.Phase == corev1.PodSucceeded && !podModificationsNeeded {

    No change in this round. The cleanup call at pkg/controller/import-controller.go:514 is already gated with !isTryNoneInProgress(pod), and ShouldDeletePod itself is unchanged.

    jay23606 jay23606 commented on Nov 12, 2026 19:13 UTC
    Author

    No change in this round. In the code before this PR, the OOM branch set requiresDirectIo=true and the CACHE_MODE=TRYNONE loop in the same updatePvcFromPod call set it back to false, so the flag was lost whenever OOMKilled was reported. If the runtime never reports OOMKilled, isOOMKilled never fires and this PR does not change that path; I have not reproduced the kubevirt CI failure, so I can't confirm it from the log.

    Reviewers
    Assignees
    jay23606 jay23606
    Labels
    risk: low confidence: 88.2% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 41.1% (MEDIUM) · Higher = larger blast radius
    41.1%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 88.2% · Lower = rushed or shallow review
    88.2%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 4.9% · Safe to merge
    4.9%