← Back to Pull requests

libvirt: fix volume cleanup and UUID capture on domain start failure #3357

Closed
unknown closed this pull request without merging on Oct 02, 2026 14:21 UTC
View on GitHub
unknown unknown commented on Oct 01, 2026 07:45 UTC
Author

What this PR does

Fixes two bugs in CreateDomain in src/cloud-providers/libvirt/libvirt.go.

1. Volumes leaked on domain start / IP-wait failure

Root and ISO volumes were uploaded to the storage pool before the domain was defined, but no cleanup ran if Create() failed or the subsequent IP-wait timed out. Stale volumes accumulated on every retry, particularly visible when using a corrupted backing image (related: #1737).

Deferred cleanup guards are added for both volumes and are disarmed only once the domain is started and ownership of cleanup is transferred to DeleteDomain. This avoids double-deletion since DeleteDomain already removes the domain and its associated volumes via getDeletableDiskPaths.

2. UUID captured after Create()

The domain UUID was retrieved after Create() was called. If Create() failed, the function returned nil with no instanceID, leaving the caller unable to invoke DeleteDomain for cleanup. UUID is now captured immediately after DefineXML returns (before Create()), so a non-nil result with a valid instanceID is always returned on error.

Testing

Unit tests

  • All existing unit tests pass.

  • New test TestCreateDomainBootFailureReturnsInstanceForCleanup: uploads a deliberately corrupt backing image, calls CreateDomain, asserts a non-nil result with a populated instanceID is returned on boot failure, and verifies DeleteDomain fully removes the domain and its volumes — covering the cleanup path end to end.
  • Integration tests (live libvirt)

  • Full test suite run against a live libvirt connection on an s390x host. All connection-dependent tests pass, including TestCreateDomainXMLArchitectures, TestGetDeletableDiskPaths, and TestGetGuestForArchType.
  • End-to-end

  • Smoke-tested with an updated CAA image carrying these changes deployed on a libvirt-backed peer-pods cluster. Pod creation, IP assignment, and teardown all behaved correctly across multiple runs, including a forced failure scenario to confirm stale volume cleanup no longer occurs.
  • Diff: 261 lines (+195 / -66) across 3 files Reviewer: mkulke Review duration: 1836m
    All Vouch review confidence checks passed
    Residual risk 0.15 = Change Risk (0.39) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.39 · 261 lines diff across 3 files
    0.39
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    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.333
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #3357"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% 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: 39.2% (MEDIUM) · Higher = larger blast radius
    39.2%
    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: 60.5% · Lower = rushed or shallow review
    60.5%
    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: 15.5% · Safe to merge
    15.5%