Skip to content

Fix offline migration with a hotplugged volume#48

Open
awels wants to merge 1 commit intokubevirt:mainfrom
awels:fix_hotplugged_offline
Open

Fix offline migration with a hotplugged volume#48
awels wants to merge 1 commit intokubevirt:mainfrom
awels:fix_hotplugged_offline

Conversation

@awels
Copy link
Copy Markdown
Member

@awels awels commented Mar 31, 2026

What this PR does / why we need it:
When migrating an offline VM with hotplugged volumes, the controller was attempting to update
DataVolumeTemplate entries for all volumes being migrated. However, hotplugged volumes don't have corresponding DataVolumeTemplate entries (they're in spec.template.spec.volumes with hotpluggable:true, but not in spec.dataVolumeTemplates).

This caused KubeVirt's admission webhook to reject the VM update with: "DataVolumeTemplate
entry spec.dataVolumeTemplate[0] must be referenced in the VMI template's 'volumes' list"

Changes:

  • Track which volumes are present in spec.template.spec.volumes
  • Only update DataVolumeTemplates if corresponding volume is in template
  • Skip DVTemplate updates for hotplugged volumes (no DVTemplate exists)
  • Add comprehensive test with 4 naming combinations:
    1. Both volumes have explicit target names
    2. Regular explicit, hotplug generated suffix
    3. Regular generated suffix, hotplug explicit
    4. Both use generated suffix names

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #

Special notes for your reviewer:

Checklist

This checklist is not enforcing, but it's a reminder of items that could be relevant to every PR.
Approvers are expected to review this list.

Release note:

BugFix: fix bug where offline migration of VM with hotplugged volume would fail

When migrating an offline VM with hotplugged
volumes, the controller was attempting to update
DataVolumeTemplate entries for all volumes being
migrated. However, hotplugged volumes don't have
corresponding DataVolumeTemplate entries
(they're in spec.template.spec.volumes with
hotpluggable:true, but not in
spec.dataVolumeTemplates).

This caused KubeVirt's admission webhook to
reject the VM update with: "DataVolumeTemplate
entry spec.dataVolumeTemplate[0] must be
referenced in the VMI template's 'volumes' list"

Changes:
- Track which volumes are present in spec.template.spec.volumes
- Only update DataVolumeTemplates if corresponding volume is in template
- Skip DVTemplate updates for hotplugged volumes (no DVTemplate exists)
- Add comprehensive test with 4 naming combinations:
  1. Both volumes have explicit target names
  2. Regular explicit, hotplug generated suffix
  3. Regular generated suffix, hotplug explicit
  4. Both use generated suffix names

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Signed-off-by: Alexander Wels <awels@redhat.com>
@kubevirt-bot kubevirt-bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. labels Mar 31, 2026
@kubevirt-bot kubevirt-bot requested a review from akalenyu March 31, 2026 20:31
@kubevirt-bot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign akalenyu for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

vmCopy := vm.DeepCopy()

// Track which volumes are present in the template and being migrated
volumesInTemplate := make(map[string]bool)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

just me or we don't usually use the "template" term when reasoning about vmis? so variable names/comments here are bit confusing

planPVCNameMap[pvc.Name] = pvc.VolumeName
}
// Only update DataVolumeTemplates if the corresponding volume is in the template.
// Hotplugged volumes may have DVTemplates but not be in spec.template.spec.volumes,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is this line correct?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dco-signoff: yes Indicates the PR's author has DCO signed all their commits. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants