Repository navigation
feat: add cinder DeleteAttachment for stale volume attachments - #107
Merged
Merged
Conversation
A 409 that is not a duplicate previously surfaced as a bare *http.HttpError. Map it to a new Conflict error code so callers can tell it apart, and add errors.IsConflict next to the existing predicates. The existing "already exists" handling is unchanged. Signed-off-by: Seyeong Kim <seyeong.kim@canonical.com>
Add an attachments-API call to remove a volume attachment, which frees a volume whose attachment has gone stale, for example when the instance was deleted while a detach was still in flight and the volume is left wedged in detaching. Cinder checks with the Compute API first: it removes the attachment once the instance is gone and frees the volume, and refuses with 409 while the instance is still using it. Unlike the os-force_detach admin action this is permitted for the volume's owner. The attachments API needs microversion 3.27, so the request sets the OpenStack-API-Version header. Also expose attachment_id on VolumeAttachment. On modern clouds the volume's attachment entry reports the volume id in its id field, so a caller targeting a specific attachment needs the real attachment id. Signed-off-by: Seyeong Kim <seyeong.kim@canonical.com>
Merged
3 of 5 tasks
There was a problem hiding this comment.
Pull request overview
Adds support for cleaning up stale Cinder volume attachments by calling the Cinder attachments API (microversion 3.27), and introduces a first-class Conflict error to repr
8000
esent HTTP 409 responses surfaced through the shared HTTP client error handling.
Changes:
- Map HTTP 409 responses (when not detected as “duplicate”) to a new
Conflicterror type (errors.IsConflict). - Add
Client.DeleteAttachmentto the Cinder client, backed by a generateddeleteAttachmentrequest with microversionvolume 3.27. - Extend Cinder attachment modeling to expose
attachment_id, and add unit tests covering the new behavior.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| http/client.go | Map 409 responses to a new Conflict error in shared HTTP error handling. |
| http/client_test.go | Add unit test asserting 409 maps to errors.IsConflict. |
| errors/errors.go | Add Conflict error code/type helpers and constructor. |
| cinder/client.go | Expose DeleteAttachment on the Cinder client API. |
| cinder/client_test.go | Add tests for DeleteAttachment success and conflict cases. |
| cinder/autogenerated_client.go | Add attachment ID field + generated delete-attachment request with microversion header. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
wallyworld
reviewed
Jul 13, 2026
Pass response messages as format arguments for forbidden, duplicate value, and conflict errors. This preserves percent signs in plain text and JSON error responses. Signed-off-by: Seyeong Kim <seyeong.kim@canonical.com>
xtrusia
force-pushed
the
force-detach-volume
branch
from
July 18, 2026 22:58
a4759a3 to
687d33b
Compare
Return a not implemented error for Cinder v2 endpoints and for servers that reject Block Storage microversion 3.27. Signed-off-by: Seyeong Kim <seyeong.kim@canonical.com>
wallyworld
approved these changes
Jul 20, 2026
jujubot
added a commit
to juju/juju
that referenced
this pull request
Jul 20, 2026
#22753 Destroying a model hangs forever when a cinder volume is wedged in `detaching`/`attaching`. Detach is orchestrated by nova, so if the instance is removed before nova finalises it, the attachment is orphaned and the volume never leaves the transitional state. `destroyVolume` only issues a Compute-API detach and then polls, so the poll times out and the destroy retries forever — the controller log loops on `destroying volumes: timed out` roughly every 70s. This change deletes the attachment directly via the cinder Attachments API (`DELETE /v3/{project}/attachments/{id}`, `OpenStack-API-Version: volume 3.27`) right after requesting the ordinary Compute-API detach. It is permitted for the volume's owner (no admin needed): cinder removes the attachment when the instance is gone, returns 409 (Conflict) while it's still in use (we keep waiting), and on 403 we log and fall back to plain polling — no worse off than before. In `destroyVolume`, a transitional `detaching`/`attaching` volume now falls through to `DeleteAttachment(attachmentId)` (once per attachment) instead of polling blindly. The attachment id comes from `VolumeAttachment.AttachmentId` (`attachment_id`), not `Id` — on modern cinder (2026.1, v3) `attachments[].id` is the *volume* id. Depends on go-goose/goose#107 (`cinder.DeleteAttachment`, the `VolumeAttachment.AttachmentId` field, 409 `IsConflict` handling). `go.mod` carries a temporary `replace` to the goose fork; bump it to a tagged goose release once that PR merges. ## Checklist - [x] Code style: imports ordered, good names, simple structure, etc - [x] Comments saying why design decisions were made - [x] Go unit tests, with comments saying what you're testing - [ ] ~~[Integration tests](https://github.com/juju/juju/tree/main/tests), with comments saying what you're testing~~ — provider-level behaviour exercised by the unit tests and the live QA below - [ ] ~~[doc.go](https://discourse.charmhub.io/t/readme-in-packages/451) added or updated in changed packages~~ — no package responsibilities changed ## QA steps Unit tests: ``` go test ./internal/provider/openstack/ -check.f TestDestroyVolumesDeleteAttachment -count=1 ``` Live (OpenStack 2026.1, cinder v3 mv 3.71), patched 3.6.25 vs stock 3.6.23 controller: 1. `juju deploy postgresql --storage pgdata=cinder,1G`; wait for the volume to be `in-use`. 2. Orphan it: `openstack server delete <instance-id>` (the server is then "No Server found", but the volume keeps an attachment pointing at it). 3. `juju remove-machine 0 --force` — the out-of-band delete leaves Juju's machine/filesystem records stale, blocking storage-attachment cleanup (`filesystem "0" on "machine 0" not found`) before the volume is destroyed; the real bug already has the machine gone, so this just reproduces that state. 4. `juju destroy-model fd-repro --no-prompt --destroy-storage`. - Stock 3.6.23: the volume stays wedged, the log loops on `destroying volumes: timed out`, destroy hangs. - Patched 3.6.25: `DeleteAttachment` clears the orphan, the volume is deleted, and destroy-model completes. ## Documentation changes None. `juju` CLI output, flags and the client API are unchanged. ## Links - Related: [#1845172](https://bugs.launchpad.net/juju/+bug/1845172), [#1784876](https://bugs.launchpad.net/juju/+bug/1784876), [#1854893](https://bugs.launchpad.net/juju/+bug/1854893), [nova #2060696](https://bugs.launchpad.net/nova/+bug/2060696) - Depends on: [go-goose/goose#107](go-goose/goose#107) - ~~Jira card~~ — none
jujubot
added a commit
to juju/juju
that referenced
this pull request
Jul 23, 2026
…on-destroy #22753 Destroying a model hangs forever when a cinder volume is wedged in `detaching`/`attaching`. Detach is orchestrated by nova, so if the instance is removed before nova finalises it, the attachment is orphaned and the volume never leaves the transitional state. `destroyVolume` only issues a Compute-API detach and then polls, so the poll times out and the destroy retries forever — the controller log loops on `destroying volumes: timed out` roughly every 70s. This change deletes the attachment directly via the cinder Attachments API (`DELETE /v3/{project}/attachments/{id}`, `OpenStack-API-Version: volume 3.27`) right after requesting the ordinary Compute-API detach. It is permitted for the volume's owner (no admin needed): cinder removes the attachment when the instance is gone, returns 409 (Conflict) while it's still in use (we keep waiting), and on 403 we log and fall back to plain polling — no worse off than before. In `destroyVolume`, a transitional `detaching`/`attaching` volume now falls through to `DeleteAttachment(attachmentId)` (once per attachment) instead of polling blindly. The attachment id comes from `VolumeAttachment.AttachmentId` (`attachment_id`), not `Id` — on modern cinder (2026.1, v3) `attachments[].id` is the *volume* id. Depends on go-goose/goose#107 (`cinder.DeleteAttachment`, the `VolumeAttachment.AttachmentId` field, 409 `IsConflict` handling). `go.mod` carries a temporary `replace` to the goose fork; bump it to a tagged goose release once that PR merges. - [x] Code style: imports ordered, good names, simple structure, etc - [x] Comments saying why design decisions were made - [x] Go unit tests, with comments saying what you're testing - [ ] ~~[Integration tests](https://github.com/juju/juju/tree/main/tests), with comments saying what you're testing~~ — provider-level behaviour exercised by the unit tests and the live QA below - [ ] ~~[doc.go](https://discourse.charmhub.io/t/readme-in-packages/451) added or updated in changed packages~~ — no package responsibilities changed Unit tests: ``` go test ./internal/provider/openstack/ -check.f TestDestroyVolumesDeleteAttachment -count=1 ``` Live (OpenStack 2026.1, cinder v3 mv 3.71), patched 3.6.25 vs stock 3.6.23 controller: 1. `juju deploy postgresql --storage pgdata=cinder,1G`; wait for the volume to be `in-use`. 2. Orphan it: `openstack server delete <instance-id>` (the server is then "No Server found", but the volume keeps an attachment pointing at it). 3. `juju remove-machine 0 --force` — the out-of-band delete leaves Juju's machine/filesystem records stale, blocking storage-attachment cleanup (`filesystem "0" on "machine 0" not found`) before the volume is destroyed; the real bug already has the machine gone, so this just reproduces that state. 4. `juju destroy-model fd-repro --no-prompt --destroy-storage`. - Stock 3.6.23: the volume stays wedged, the log loops on `destroying volumes: timed out`, destroy hangs. - Patched 3.6.25: `DeleteAttachment` clears the orphan, the volume is deleted, and destroy-model completes. None. `juju` CLI output, flags and the client API are unchanged. - Related: [#1845172](https://bugs.launchpad.net/juju/+bug/1845172), [#1784876](https://bugs.launchpad.net/juju/+bug/1784876), [#1854893](https://bugs.launchpad.net/juju/+bug/1854893), [nova #2060696](https://bugs.launchpad.net/nova/+bug/2060696) - Depends on: [go-goose/goose#107](go-goose/goose#107) - ~~Jira card~~ — none (cherry picked from commit eef62a8)
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Adds
DeleteAttachmentto remove a Cinder volume attachment via the attachments API (microversion 3.27), to free a volume left wedged indetachingafter its instance was deleted mid-detach.Cinder refuses with 409 while the instance still uses the volume, so non-duplicate 409s now map to a new
Conflicterror (errors.IsConflict) — split into its own commit since it affects all goose APIs viahandleError.go test ./...passes; new tests cover the 409 mapping and the cinder path.