virtualization icon indicating copy to clipboard operation
virtualization copied to clipboard

feat(vd): creare pvc using volume snapshot

Open Isteb4k opened this issue 5 months ago • 1 comments

Description

Isteb4k avatar Oct 23 '25 16:10 Isteb4k

Reviewer's Guide

Introduce optional volume snapshot–based provisioning for HTTP data sources and VirtualDisk creation when the annotation 'virtualization.deckhouse.io/use-volume-snapshot' is set, including snapshot lifecycle management and PVC creation from snapshots.

Sequence diagram for VirtualDisk creation using VolumeSnapshot

sequenceDiagram
    participant VD as VirtualDisk Controller
    participant VI as VirtualImage
    participant VS as VolumeSnapshot
    participant PVC as PersistentVolumeClaim
    participant K8s as Kubernetes API
    VD->>VI: Check for 'use-volume-snapshot' annotation
    alt Annotation present
        VD->>VI: Fetch VirtualImage
        VI->>VS: Fetch VolumeSnapshot (by PVC name)
        alt VolumeSnapshot not found
            VI->>VS: Create VolumeSnapshot
            VI->>VD: Requeue until snapshot ready
        else VolumeSnapshot found
            VI->>VS: Check ReadyToUse status
            alt Not ready
                VI->>VD: Requeue until snapshot ready
            else Ready
                VD->>PVC: Create PVC from VolumeSnapshot
                PVC->>K8s: Request PVC creation
                K8s-->>PVC: PVC created
            end
        end
    else Annotation not present
        VD->>PVC: Standard PVC creation flow
    end

Class diagram for CreatePVCFromVSStep and related types

classDiagram
    class CreatePVCFromVSStep {
        - pvc: PersistentVolumeClaim
        - client: Client
        - cb: ConditionBuilder
        + Take(ctx, vd): (*reconcile.Result, error)
        + buildPVC(vd, vs): *PersistentVolumeClaim
        + addOriginalMetadata(vd, vs)
    }
    class VirtualDisk {
        + Annotations: map[string]string
        + Labels: map[string]string
        + Status: VirtualDiskStatus
        + Spec: VirtualDiskSpec
    }
    class VolumeSnapshot {
        + Status: VolumeSnapshotStatus
        + Annotations: map[string]string
    }
    class PersistentVolumeClaim {
        + Name: string
        + Namespace: string
        + OwnerReferences: []OwnerReference
        + Spec: PersistentVolumeClaimSpec
    }
    CreatePVCFromVSStep --> VirtualDisk
    CreatePVCFromVSStep --> VolumeSnapshot
    CreatePVCFromVSStep --> PersistentVolumeClaim

File-Level Changes

Change Details Files
Branch HTTP data source import to use volume snapshots
  • Import external-snapshotter API
  • Detect 'use-volume-snapshot' annotation in StoreToPVC
  • Get or create VolumeSnapshot via diskService
  • Requeue until snapshot ReadyToUse before marking image ready
pkg/controller/vi/internal/source/http.go
Add CreateVolumeSnapshot method to disk service
  • Validate PVC bound state
  • Construct and create vsv1.VolumeSnapshot with owner reference
  • Handle already-exists errors
pkg/controller/service/disk_service.go
Skip standard VirtualDisk steps when using snapshots
  • Early return in CreateDataVolumeFromVirtualImageStep
  • Early return in EnsureNodePlacementStep
  • Early return in WaitForDVStep
pkg/controller/vd/internal/source/step/create_dv_from_vi_step.go
pkg/controller/vd/internal/source/step/ensure_node_placement.go
pkg/controller/vd/internal/source/step/wait_for_dv_step.go
Register new step for PVC creation from snapshots
  • Insert CreatePVCFromVSStep into ObjectRefVirtualImage Sync pipeline
pkg/controller/vd/internal/source/object_ref_vi.go
Implement CreatePVCFromVSStep for VolumeSnapshot support
  • Fetch VirtualImage and corresponding VolumeSnapshot
  • Validate snapshot readiness
  • Build PVC spec using snapshot annotations (storageClass, accessModes, volumeMode, size)
  • Create PVC, update VirtualDisk status and metadata
pkg/controller/vd/internal/source/step/create_pvc_from_vs_step.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an issue from a review comment by replying to it. You can also reply to a review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull request title to generate a title at any time. You can also comment @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in the pull request body to generate a PR summary at any time exactly where you want it. You can also comment @sourcery-ai summary on the pull request to (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the pull request to resolve all Sourcery comments. Useful if you've already addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull request to dismiss all existing Sourcery reviews. Especially useful if you want to start fresh with a new review - don't forget to comment @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

  • Contact our support team for questions or feedback.
  • Visit our documentation for detailed guides and information.
  • Keep in touch with the Sourcery team by following us on X/Twitter, LinkedIn or GitHub.

sourcery-ai[bot] avatar Oct 23 '25 16:10 sourcery-ai[bot]