Repository navigation
attachdetach: wait for the force detach metric in reconciler tests - #142385
kubernetes-prow[bot] merged 2 commits into
Conversation
The reconciler records the force detach metric after DetachVolume returns, but the detach itself runs in a goroutine started by the operation executor. The tests wait for the fake detacher to be called and then read the counter once, so on a slow or loaded machine they can observe the detach before the increment. Poll the counter the same way the other assertions in this file do.
|
This issue is currently awaiting triage. If a SIG or subproject determines this is a relevant issue, they will accept it by applying the The DetailsInstructions 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. |
|
Hi @LiRunGuo. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Regular contributors should join the org to skip this step. Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions 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. |
|
This commit is similar to the one I drafted on my local. lgtm Compared to |
| // The reconciler records the metric after DetachVolume returns, but the | ||
| // detach itself runs in its own goroutine, so the fake detacher can be | ||
| // called before the counter is incremented. |
There was a problem hiding this comment.
This fix seems fine, but noting here that we should really also have each test wait for its reconciler to stop before returning (to fix the leak into the next test you described in PR description, which can still happen from tests here that don't check the metric, for example see https://prow.k8s.io/view/gs/kubernetes-ci-logs/pr-logs/pull/141979/pull-kubernetes-unit/2100717770399289344).
There was a problem hiding this comment.
Thanks, agreed. The leak you linked is a different path: Test_Run_OneVolumeDetachOnUnhealthyNode's reconciler did one more timeout force detach after the test returned, and the next test's "unchanged" check saw it. I've added a helper that starts the reconciler and, in t.Cleanup, cancels it and waits for Run to return, used at all 14 call sites. The metric is recorded on the reconciler goroutine, so nothing can increment it after a test ends.
Under contention (all Test_Run_*, 3,000 iterations), the first commit alone still hit this once (lines 1281/1302) and logged 63 lines from reconcilers that outlived their test; with the helper, 0 failures and 0 such lines.
|
/ok-to-test |
|
/retest |
The tests start the reconciler with "go reconciler.Run(ctx)" and only cancel its context on return, so a reconciler can finish one more loop iteration after its test is done. When that iteration force detaches a volume, the global force detach metric changes under the next test and its "unchanged" check fails. Run the reconciler through a helper that cancels it and waits for Run to return in t.Cleanup. The metric is recorded on the reconciler goroutine, so nothing can change it once Run has returned.
|
Thanks @matteopulcini6 for checking it with stress, and sorry for the overlap: I hadn't seen your |
torredil
left a comment
There was a problem hiding this comment.
Thanks, latest rev looks great.
/lgtm
|
LGTM label has been added. DetailsGit tree hash: 619a8cf08ee9e43c0cbf0474e5096dd2e3427042 |
|
/cherry-pick release-1.34 |
|
/assign @gnufied |
|
Thanks for the review! Heads-up on the cherry-picks: on release-1.34 and release-1.35 the second commit conflicts (the tests there create their context right above |
|
Friendly ping @gnufied: this has /lgtm from torredil; could you take a look for approval when you have a moment? Thanks! |
|
/approve |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: jsafrane, LiRunGuo The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
/kind flake
/sig storage
What this PR does / why we need it:
Two fixes for the force detach metric checks in the reconciler tests.
testForceDetachMetricread the counter once, right after the test saw thefake detacher called. But the reconciler increments the counter only after
DetachVolumereturns, while the detach itself runs in a goroutine startedby the operation executor (
nestedpendingoperations). If that goroutinewins, the test sees the detach before the increment:
It now polls with the file's existing
waitForCondition, like the otherassertions here. For "unchanged" checks it returns on the first read.
The tests start the reconciler with
go reconciler.Run(ctx)and only cancelit on return, so a reconciler can finish one more loop after its test is
done. If that loop force detaches, the global counter changes under the next
test and its "unchanged" check fails (the failure linked in review, from
Test_Run_OneVolumeDetachOnUnhealthyNode). ArunReconcilerhelper nowcancels the reconciler and waits for
Runto return int.Cleanup; all 14call sites use it. The metric is recorded on the reconciler goroutine, so
nothing can change it after
Runreturns.Which issue(s) this PR is related to:
Fixes #142349
Special notes for your reviewer:
Reproduced on an x86 host under CPU contention (processes pinned to a few
cores,
GOMAXPROCS=1,-race). "Leaked" counts log lines that ktesting tagsas coming from a reconciler that outlived its test.
Test_Run_*, 8 cores, 3,000 iterationsmake test WHAT=./pkg/controller/volume/attachdetach/...with-count=3passes.
The same helpers exist on release branches (the issue also lists
ci-kubernetes-unit-1-34), so this may be worth cherry-picking.
AI disclosure: an AI assistant (Claude) helped find the issue, write the
stress harness and the fix, and draft this description. I reviewed the change
and ran the tests.
Does this PR introduce a user-facing change?