Skip to content

Conversation

@Isteb4k
Copy link
Contributor

@Isteb4k Isteb4k commented Oct 23, 2025

Description

@Isteb4k Isteb4k marked this pull request as draft October 23, 2025 16:34
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Oct 23, 2025

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
Loading

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
Loading

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

@Isteb4k Isteb4k changed the title Feat/vd/create using volume snapshot feat(vd): creare pvc using volume snapshot Oct 23, 2025
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes - here's some feedback:

  • The CreateVolumeSnapshot method’s bound-state check seems reversed (it errors when PVC is Bound) – flip the condition or message to only snapshot after PVC is Bound.
  • There are many scattered checks for the use-volume-snapshot annotation; extract this into a shared helper/constant to reduce duplication and improve maintainability.
  • Guard against nil on vs.Status or ReadyToUse pointer (the && check can panic and should treat nil as not ready) to prevent dereference errors.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The CreateVolumeSnapshot method’s bound-state check seems reversed (it errors when PVC is Bound) – flip the condition or message to only snapshot after PVC is Bound.
- There are many scattered checks for the use-volume-snapshot annotation; extract this into a shared helper/constant to reduce duplication and improve maintainability.
- Guard against nil on vs.Status or ReadyToUse pointer (the && check can panic and should treat nil as not ready) to prevent dereference errors.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@Isteb4k Isteb4k added this to the v1.2.0 milestone Oct 23, 2025
@Isteb4k Isteb4k force-pushed the feat/vd/create-using-volume-snapshot branch 6 times, most recently from dfcbfe0 to 05c28fb Compare October 23, 2025 17:56
@Isteb4k Isteb4k force-pushed the feat/vd/create-using-volume-snapshot branch from 05c28fb to 2ba1f4c Compare October 23, 2025 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant