-
Notifications
You must be signed in to change notification settings - Fork 183
volumemgr: retry failed volume deletes instead of leaking them #6176
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
Merged
eriknordmark
merged 1 commit into
lf-edge:master
from
rene:fix-volumedelete-after-prune
Jul 21, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| // Copyright (c) 2026 Zededa, Inc. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package volumemgr | ||
|
|
||
| import ( | ||
| "github.com/lf-edge/eve/pkg/pillar/types" | ||
| ) | ||
|
|
||
| // maxVolumeDeleteRetries bounds how many times a volume whose destroy failed is | ||
| // re-driven off the gc tick before volumemgr gives up. Deleting a PVC/Longhorn | ||
| // volume is normally quick, but the owner node can be unreachable for a while | ||
| // during a purge or a cluster update; this budget covers such a window (~gc | ||
| // interval * this count) while still parking a permanently-undeletable volume | ||
| // terminally instead of resubmitting a worker job forever. | ||
| const maxVolumeDeleteRetries = 12 | ||
|
|
||
| // volumeDeleteRetryAction is what retryFailedVolumeDelete should do with a single | ||
| // VolumeStatus. Split out as a pure function so the bounded-retry boundary is | ||
| // unit-testable without pubsub/worker wiring. | ||
| type volumeDeleteRetryAction int | ||
|
|
||
| const ( | ||
| vdSkip volumeDeleteRetryAction = iota // not a parked failed delete | ||
| vdRedrive // resubmit the destroy work | ||
| vdGiveUp // retry budget just spent; log once and park terminally | ||
| vdParked // already given up; leave published, do nothing | ||
| ) | ||
|
|
||
| // volumeDeleteRetryActionFor decides, from a VolumeStatus and how many times its | ||
| // delete has already been re-driven, whether to skip it, re-drive it, give up, or | ||
| // leave it parked. A volume is a retry candidate only while it is unreferenced | ||
| // (RefCount 0), parked in the Deleting sub-state, and carries an error - i.e. a | ||
| // destroy that failed rather than one still in flight. It is re-driven until it has | ||
| // been retried maxVolumeDeleteRetries times, at which point it is given up once and | ||
| // then left parked (still published with its error, for operator visibility) so a | ||
| // permanently-failing delete stops consuming worker slots without disappearing. | ||
| func volumeDeleteRetryActionFor(status *types.VolumeStatus, retryCount int) volumeDeleteRetryAction { | ||
| if status.RefCount != 0 || | ||
| status.SubState != types.VolumeSubStateDeleting || | ||
| !status.HasError() { | ||
| return vdSkip | ||
| } | ||
| if retryCount > maxVolumeDeleteRetries { | ||
| return vdParked | ||
| } | ||
| if retryCount == maxVolumeDeleteRetries { | ||
| return vdGiveUp | ||
| } | ||
| return vdRedrive | ||
| } | ||
|
|
||
| // retryFailedVolumeDelete re-drives volume deletions that previously failed and | ||
| // were left published (by maybeDeleteVolume) in the Deleting sub-state with an | ||
| // error, rather than being unpublished and leaked. For each such volume it | ||
| // resubmits the destroy work; the result flows back through | ||
| // processVolumeWorkResult -> maybeDeleteVolume, which unpublishes on success | ||
| // (clearing the retry count) or leaves the error set for another pass. After | ||
| // maxVolumeDeleteRetries attempts it gives up: the volume is left published in the | ||
| // Deleting sub-state with its error (mirroring the cluster-create give-up) so a | ||
| // permanently-undeletable, possibly-orphaned volume stays visible to the operator | ||
| // in status instead of silently disappearing; it just stops being re-driven. | ||
| // Called from the periodic gc handler. | ||
| func retryFailedVolumeDelete(ctx *volumemgrContext) { | ||
| for _, st := range ctx.pubVolumeStatus.GetAll() { | ||
| status := st.(types.VolumeStatus) | ||
| key := status.Key() | ||
| switch volumeDeleteRetryActionFor(&status, ctx.volumeDeleteRetryCount[key]) { | ||
| case vdSkip: | ||
| // Not (or no longer) a parked failed delete. Drop any stale retry | ||
| // count so a volume that left the candidate set another way (e.g. it | ||
| // got re-referenced during a redeploy) doesn't resume a later delete | ||
| // from a shortened budget. A no-op for untracked keys. | ||
| delete(ctx.volumeDeleteRetryCount, key) | ||
| continue | ||
| case vdParked: | ||
| // Already gave up on this delete; it stays published with its error | ||
| // for operator visibility. Nothing more to do until it stops being a | ||
| // candidate (handled by vdSkip above). | ||
| continue | ||
| case vdGiveUp: | ||
| log.Errorf("retryFailedVolumeDelete: giving up on delete of %s (%s) "+ | ||
| "after %d retries; leaving it published in Deleting with a terminal "+ | ||
| "error, underlying volume may be orphaned: %s", | ||
| key, status.DisplayName, ctx.volumeDeleteRetryCount[key], status.Error) | ||
| // Consume the stale worker result but keep the VolumeStatus (and its | ||
| // disk metrics) published; bump the count past the cap so subsequent gc | ||
| // ticks see vdParked and neither re-drive nor re-log. | ||
| _ = popVolumeWorkResult(ctx, key) | ||
| ctx.volumeDeleteRetryCount[key] = maxVolumeDeleteRetries + 1 | ||
| case vdRedrive: | ||
| ctx.volumeDeleteRetryCount[key]++ | ||
| log.Noticef("retryFailedVolumeDelete: retrying delete of %s (%s) "+ | ||
| "(attempt %d/%d): %s", | ||
| key, status.DisplayName, ctx.volumeDeleteRetryCount[key], | ||
| maxVolumeDeleteRetries, status.Error) | ||
| AddWorkDestroy(ctx, &status) | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| // Copyright (c) 2026 Zededa, Inc. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package volumemgr | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/lf-edge/eve/pkg/pillar/types" | ||
| ) | ||
|
|
||
| // parkedFailedDeleteVolume builds a VolumeStatus in the state the volume-delete | ||
| // retry treats as a candidate: unreferenced, in the Deleting sub-state, with a | ||
| // recorded error (a destroy that failed rather than one still in flight). | ||
| func parkedFailedDeleteVolume() types.VolumeStatus { | ||
| vs := types.VolumeStatus{ | ||
| RefCount: 0, | ||
| SubState: types.VolumeSubStateDeleting, | ||
| } | ||
| vs.SetErrorDescription(types.ErrorDescription{Error: "DeletePVC failed: node unreachable"}) | ||
| return vs | ||
| } | ||
|
|
||
| // TestVolumeDeleteRetryActionFor pins the bounded-retry boundary: a parked failed | ||
| // delete is re-driven until it has been retried maxVolumeDeleteRetries times, at | ||
| // which point the retry gives up exactly once and then leaves the volume parked | ||
| // (still published with its error) instead of resubmitting a destroy worker job or | ||
| // re-logging every gc tick forever. Anything that is not a parked failed delete is | ||
| // skipped. | ||
| func TestVolumeDeleteRetryActionFor(t *testing.T) { | ||
| // Under the cap: re-drive. | ||
| for _, n := range []int{0, 1, maxVolumeDeleteRetries - 1} { | ||
| vs := parkedFailedDeleteVolume() | ||
| if got := volumeDeleteRetryActionFor(&vs, n); got != vdRedrive { | ||
| t.Errorf("retryCount=%d: got %d, want vdRedrive(%d)", n, got, vdRedrive) | ||
| } | ||
| } | ||
| // Exactly at the cap: give up (log once, park). | ||
| { | ||
| vs := parkedFailedDeleteVolume() | ||
| if got := volumeDeleteRetryActionFor(&vs, maxVolumeDeleteRetries); got != vdGiveUp { | ||
| t.Errorf("retryCount=%d: got %d, want vdGiveUp(%d)", | ||
| maxVolumeDeleteRetries, got, vdGiveUp) | ||
| } | ||
| } | ||
| // Beyond the cap: already given up, stay parked (no re-drive, no re-log). | ||
| for _, n := range []int{maxVolumeDeleteRetries + 1, maxVolumeDeleteRetries + 5} { | ||
| vs := parkedFailedDeleteVolume() | ||
| if got := volumeDeleteRetryActionFor(&vs, n); got != vdParked { | ||
| t.Errorf("retryCount=%d: got %d, want vdParked(%d)", n, got, vdParked) | ||
| } | ||
| } | ||
| // Not a retry candidate: skip. | ||
| skips := map[string]func(*types.VolumeStatus){ | ||
| "still referenced": func(v *types.VolumeStatus) { v.RefCount = 1 }, | ||
| "not deleting": func(v *types.VolumeStatus) { v.SubState = types.VolumeSubStateCreated }, | ||
| } | ||
| for name, mutate := range skips { | ||
| vs := parkedFailedDeleteVolume() | ||
| mutate(&vs) | ||
| if got := volumeDeleteRetryActionFor(&vs, 0); got != vdSkip { | ||
| t.Errorf("%s: got %d, want vdSkip(%d)", name, got, vdSkip) | ||
| } | ||
| } | ||
|
|
||
| // A fresh (never-failed) delete in flight must not be treated as a failed | ||
| // delete: Deleting sub-state but no error yet. | ||
| inFlight := types.VolumeStatus{SubState: types.VolumeSubStateDeleting} | ||
| if got := volumeDeleteRetryActionFor(&inFlight, 0); got != vdSkip { | ||
| t.Errorf("in-flight delete: got %d, want vdSkip(%d)", got, vdSkip) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.