Skip to content

Conversation

loktev-d
Copy link
Contributor

@loktev-d loktev-d commented Oct 10, 2025

Description

Add condition error for PersistentVolume node affinity when attached block devices via VMBDA is not available on VM node.

Why do we need it, and what problem does it solve?

When using storage classes with node affinity, the PersistentVolume is pinned to a specific node. If a user tries to hot-plug such a disk to a VM running on a different node, the attachment fails silently or with unclear errors.

What is the expected result?

Checklist

  • The code is covered by unit tests.
  • e2e tests passed.
  • Documentation updated according to the changes.
  • Changes were tested in the Kubernetes cluster manually.

Changelog entries

section: vmbda
type: fix
summary:  VMBDA now reports a clear error if the device is not available on the VM's node.

Signed-off-by: Daniil Loktev <[email protected]>
@loktev-d loktev-d added this to the v1.2.0 milestone Oct 10, 2025
Copy link
Contributor

sourcery-ai bot commented Oct 10, 2025

Reviewer's Guide

Adds explicit node affinity validation for PersistentVolumes in VMBDA: AttachmentService now fetches the PV and target Node to verify the volume’s node affinity, and the handler fails hot-plug operations with a clear 'DeviceNotAvailableOnNode' status when the PV isn’t available on the VM’s node.

Sequence diagram for VMBDA block device attachment with node affinity validation

sequenceDiagram
    participant "LifeCycleHandler"
    participant "AttachmentService"
    participant "PersistentVolumeClaim (PVC)"
    participant "PersistentVolume (PV)"
    participant "Node"
    participant "VirtualMachineInstance (kvvmi)"
    actor "User"

    "User"->>"LifeCycleHandler": Request block device attachment
    "LifeCycleHandler"->>"AttachmentService": GetPersistentVolumeClaim(ad)
    "AttachmentService"->>"PersistentVolumeClaim (PVC)": Fetch PVC
    "AttachmentService"->>"LifeCycleHandler": Return PVC
    "LifeCycleHandler"->>"AttachmentService": IsPVAvailableOnVMNode(pvc, kvvmi)
    "AttachmentService"->>"PersistentVolume (PV)": Fetch PV
    "AttachmentService"->>"Node": Fetch Node (kvvmi.Status.NodeName)
    "AttachmentService"->>"AttachmentService": Check PV node affinity against Node
    alt PV not available on VM node
        "AttachmentService"->>"LifeCycleHandler": Return false
        "LifeCycleHandler"->>"User": Report error: DeviceNotAvailableOnNode
    else PV available on VM node
        "AttachmentService"->>"LifeCycleHandler": Return true
        "LifeCycleHandler"->>"AttachmentService": HotPlugDisk(...)
    end
Loading

Class diagram for updated AttachmentService and LifeCycleHandler

classDiagram
    class AttachmentService {
        +GetPersistentVolumeClaim(ctx, ad)
        +GetPersistentVolume(ctx, pvName)
        +GetVirtualMachine(ctx, name, namespace)
        +GetKVVMI(ctx, vm)
        +IsPVAvailableOnVMNode(ctx, pvc, kvvmi)
    }
    class LifeCycleHandler {
        +Handle(ctx, vmbda)
        -attacher: AttachmentService
    }
    AttachmentService <.. LifeCycleHandler: uses
Loading

Class diagram for vmbdacondition with new DeviceNotAvailableOnNode reason

classDiagram
    class AttachedReason {
        +Conflict
        +DeviceNotAvailableOnNode
    }
    class DiskAttachmentCapacityAvailableReason {
        +CapacityAvailable
    }
Loading

File-Level Changes

Change Details Files
Implement PV node affinity check in AttachmentService
  • Add GetPersistentVolume to retrieve a PersistentVolume by name
  • Add IsPVAvailableOnVMNode to validate PV.Spec.NodeAffinity against the VM’s node, including nil checks, fetching PV and Node, and matching via nodeaffinity.NewNodeSelector
  • Import the nodeaffinity helper from k8s component-helpers
images/virtualization-artifact/pkg/controller/service/attachment_service.go
Fail VMBDA lifecycle when PV is unavailable on VM node
  • In life_cycle handler, fetch PVC and call IsPVAvailableOnVMNode before hot-plug
  • Set vmbda.Status.Phase to BlockDeviceAttachmentPhaseFailed with DeviceNotAvailableOnNode reason and a descriptive message
images/virtualization-artifact/pkg/controller/vmbda/internal/life_cycle.go
Introduce DeviceNotAvailableOnNode condition reason
  • Define new AttachedReason constant DeviceNotAvailableOnNode in condition.go
api/core/v1alpha2/vmbdacondition/condition.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

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 and they look great!


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.

@loktev-d loktev-d marked this pull request as draft October 10, 2025 11:56
@loktev-d loktev-d added the e2e/run Run e2e test on cluster of PR author label Oct 10, 2025
@deckhouse-BOaTswain
Copy link
Contributor

deckhouse-BOaTswain commented Oct 10, 2025

Workflow has started.
Follow the progress here: Workflow Run

The target step completed with status: failure.

@deckhouse-BOaTswain deckhouse-BOaTswain removed the e2e/run Run e2e test on cluster of PR author label Oct 10, 2025
@loktev-d loktev-d added the e2e/run Run e2e test on cluster of PR author label Oct 13, 2025
@deckhouse-BOaTswain
Copy link
Contributor

deckhouse-BOaTswain commented Oct 13, 2025

Workflow has started.
Follow the progress here: Workflow Run

The target step completed with status: failure.

@deckhouse-BOaTswain deckhouse-BOaTswain removed the e2e/run Run e2e test on cluster of PR author label Oct 13, 2025
@loktev-d loktev-d added the e2e/run Run e2e test on cluster of PR author label Oct 14, 2025
@deckhouse-BOaTswain
Copy link
Contributor

deckhouse-BOaTswain commented Oct 14, 2025

Workflow has started.
Follow the progress here: Workflow Run

The target step completed with status: failure.

@Isteb4k Isteb4k modified the milestones: v1.2.0, v1.1.1 Oct 14, 2025
@deckhouse-BOaTswain deckhouse-BOaTswain removed the e2e/run Run e2e test on cluster of PR author label Oct 14, 2025
@loktev-d loktev-d added the e2e/run Run e2e test on cluster of PR author label Oct 14, 2025
@deckhouse-BOaTswain
Copy link
Contributor

deckhouse-BOaTswain commented Oct 14, 2025

Workflow has started.
Follow the progress here: Workflow Run

The target step completed with status: failure.

@deckhouse-BOaTswain deckhouse-BOaTswain removed the e2e/run Run e2e test on cluster of PR author label Oct 14, 2025
Signed-off-by: Daniil Loktev <[email protected]>
@loktev-d loktev-d added the e2e/run Run e2e test on cluster of PR author label Oct 15, 2025
@deckhouse-BOaTswain
Copy link
Contributor

deckhouse-BOaTswain commented Oct 15, 2025

Workflow has started.
Follow the progress here: Workflow Run

The target step completed with status: failure.

@deckhouse-BOaTswain deckhouse-BOaTswain removed the e2e/run Run e2e test on cluster of PR author label Oct 15, 2025
@loktev-d loktev-d added the e2e/run Run e2e test on cluster of PR author label Oct 15, 2025
@deckhouse-BOaTswain
Copy link
Contributor

deckhouse-BOaTswain commented Oct 15, 2025

Workflow has started.
Follow the progress here: Workflow Run

The target step completed with status: success.

@deckhouse-BOaTswain deckhouse-BOaTswain removed the e2e/run Run e2e test on cluster of PR author label Oct 15, 2025
@loktev-d loktev-d marked this pull request as ready for review October 15, 2025 19:42
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 and they look great!


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.

@nevermarine nevermarine modified the milestones: v1.1.1, v1.2.0 Oct 16, 2025
@loktev-d loktev-d merged commit 6d58ad7 into main Oct 17, 2025
89 of 90 checks passed
@loktev-d loktev-d deleted the fix/vmbda/node-affinity-check branch October 17, 2025 12:05
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.

5 participants