8000
Skip to content

fix: reject setting serial disk number for lun disks - #18882

Open
dsanatar wants to merge 1 commit into
kubevirt:mainfrom
dsanatar:reject-serial-lun
Open

fix: reject setting serial disk number for lun disks#18882
dsanatar wants to merge 1 commit into
kubevirt:mainfrom
dsanatar:reject-serial-lun

Conversation

@dsanatar
Copy link
Copy Markdown
Contributor

What this PR does

LibVirt does not allow specifying a disk serial number for LUN disks and are currently silently ignored when set.

This PR adds new check at the disk spec validation layer to reject VMs that are configured with LUN disks containing a serial. Add similar rejection to the addvolume API call so this specific disk configuration cannot be hotplugged.

Before this PR:

After this PR:

References

Why we need it and why it was done in this way

The following tradeoffs were made:

The following alternatives were considered:

Links to places where the discussion took place:

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

reject setting serial disk number for lun disks

Signed-off-by: dsanatar <dsanatar@redhat.com>
@kubevirt-prow kubevirt-prow 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 Aug 21, 2026
@coderabbitai
coderabbitai Bot commented Aug 21, 2026
Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 720f2e58-335c-47c8-a9ca-ccdf39e39600

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@kubevirt-prow
kubevirt-prow Bot commented Aug 21, 2026
Copy link
Copy Markdown
Contributor

[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 jean-edouard 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

@sourcery-ai sourcery-ai Bot left a comment
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.

Hey - I've found 1 issue, and left some high level feedback:

  • The error message "Serial definition is not supported for LUN disks" is duplicated in both the validation layer and the virtctl addvolume path; consider centralizing this string (or using a shared helper) so future changes keep these errors consistent.
  • In validateSerialDevice, you hardcode the SCSI bus check alongside the LUN disk type; if LUN disks are already constrained to SCSI elsewhere, you could simplify the condition to just the disk type, or alternatively document in a comment why the bus check is needed here to avoid confusion.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The error message "Serial definition is not supported for LUN disks" is duplicated in both the validation layer and the virtctl addvolume path; consider centralizing this string (or using a shared helper) so future changes keep these errors consistent.
- In `validateSerialDevice`, you hardcode the SCSI bus check alongside the LUN disk type; if LUN disks are already constrained to SCSI elsewhere, you could simplify the condition to just the disk type, or alternatively document in a comment why the bus check is needed here to avoid confusion.

## Individual Comments

### Comment 1
<location path="pkg/storage/admitters/disks_test.go" line_range="366-375" />
<code_context>
+			Expect(causes[0].Field).To(Equal("fake[0].serial"))
+		})
+
+		It("should accept serial set for scsi disk", func() {
+			vmi.Spec.Domain.Devices.Disks = append(vmi.Spec.Domain.Devices.Disks, v1.Disk{
+				Name:   "scsi-disk",
+				Serial: "testserial",
+				DiskDevice: v1.DiskDevice{
+					Disk: &v1.DiskTarget{
+						Bus: v1.DiskBusSCSI,
+					},
+				},
+			})
+
+			causes := ValidateDisks(k8sfield.NewPath("fake"), vmi.Spec.Domain.Devices.Disks)
+			Expect(causes).To(BeEmpty())
+		})
+
</code_context>
<issue_to_address>
**suggestion (testing):** Add a positive test for LUN without serial to show the constraint is only on serial presence

We already cover the rejected case (LUN with serial) and accepted case (SCSI disk with serial). Please also add a test for a SCSI LUN with an empty serial to confirm LUNs are still valid when `serial` is omitted, and to make the validation rule’s intent explicit.
</issue_to_address>

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.

Comment on lines +366 to +375
It("should accept serial set for scsi disk", func() {
vmi.Spec.Domain.Devices.Disks = append(vmi.Spec.Domain.Devices.Disks, v1.Disk{
Name: "scsi-disk",
Serial: "testserial",
DiskDevice: v1.DiskDevice{
Disk: &v1.DiskTarget{
Bus: v1.DiskBusSCSI,
},
},
})
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.

suggestion (testing): Add a positive test for LUN without serial to show the constraint is only on serial presence

We already cover the rejected case (LUN with serial) and accepted case (SCSI disk with serial). Please also add a test for a SCSI LUN with an empty serial to confirm LUNs are still valid when serial is omitted, and to make the validation rule’s intent explicit.

@kubevirt-prow
kubevirt-prow Bot commented Aug 21, 2026
Copy link
Copy Markdown
Contributor

@dsanatar: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-kubevirt-e2e-k8s-1.37-sig-compute 7667cfc link false /test pull-kubevirt-e2e-k8s-1.37-sig-compute
pull-kubevirt-e2e-k8s-1.37-sig-storage 7667cfc link false /test pull-kubevirt-e2e-k8s-1.37-sig-storage
pull-kubevirt-e2e-k8s-1.36-sig-storage 7667cfc link true /test pull-kubevirt-e2e-k8s-1.36-sig-storage
Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

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

Labels

area/api-server area/virtctl 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. sig/compute sig/storage size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0