Keep requiresDirectIo while a cache=trynone import is still running or needs scratch space #4331
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>
[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:
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"]} -->
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.
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.
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)
@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).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?
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?
Can we gate the call to ShouldDeletePod instead of having to extend it?
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.
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.
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.
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).
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.
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.
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.
akalenyu
jay23606
Bug
For a
cache=trynoneimport,updatePvcFromPodsetrequiresDirectIotofalseon every reconcile where the pod env hadcache=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
SucceededandpodModificationsNeededis false, so a running pod or a scratch-space restart keepsrequiresDirectIo.Testing
Three specs in
pkg/controller/import-controller_test.gocover the clause:cache=trynonepod keepsrequiresDirectIo;cache=trynonepod that needs scratch space keepsrequiresDirectIo;cache=trynonepod 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-colorrun 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.