feat(virtualmachine): Add CD-ROM eject support via tray state#162
feat(virtualmachine): Add CD-ROM eject support via tray state#162jniedergang wants to merge 2 commits intoharvester:masterfrom
Conversation
6219482 to
e9ff7a7
Compare
|
This pull request is now in conflict. Could you fix it @jniedergang? 🙏 |
e9ff7a7 to
25519e9
Compare
|
This pull request is now in conflict. Could you fix it @jniedergang? 🙏 |
25519e9 to
9b15aa7
Compare
There was a problem hiding this comment.
Pull request overview
This pull request adds support for ejecting CD-ROM disks in Harvester virtual machines by controlling the tray state through a new eject boolean field in the disk configuration. When set to true, the CD-ROM tray is opened, effectively ejecting the media. When set to false (default), the tray remains closed with media mounted. This feature enables a common workflow where users can install an OS from an ISO and then eject the CD-ROM via Terraform without manual intervention.
Changes:
- Added
ejectfield to disk schema with proper validation and documentation - Implemented tray state control in the constructor by setting
CDRom.Tray = TrayStateOpenwhen eject is enabled - Updated importer to read tray state from cluster and map it to the eject boolean
- Added comprehensive unit tests covering CD-ROM with open tray, closed tray, and regular disks
- Updated documentation for both resource and data source
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/constants/constants_virtualmachine.go | Added FieldDiskEject constant following existing naming conventions |
| internal/provider/virtualmachine/schema_virtualmachine_disk.go | Added eject boolean field with default value false and clear description |
| internal/provider/virtualmachine/resource_virtualmachine_constructor.go | Implemented tray control by setting TrayStateOpen when eject is true for CD-ROM disks |
| pkg/importer/resource_virtualmachine_importer.go | Added logic to read tray state and map to eject field for both CD-ROM and regular disks |
| pkg/importer/resource_virtualmachine_importer_test.go | Added TestDiskEjectImport with test cases for open/closed tray states and regular disks |
| docs/resources/virtualmachine.md | Added documentation for eject field with description |
| docs/data-sources/virtualmachine.md | Added eject field to data source schema (missing description) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
internal/provider/virtualmachine/resource_virtualmachine_constructor.go
Outdated
Show resolved
Hide resolved
dd2d1a4 to
60e1fd2
Compare
|
This pull request is now in conflict. Could you fix it @jniedergang? 🙏 |
Add eject field to disk block that controls the CD-ROM tray state. When eject=true, the tray opens (KubeVirt TrayStateOpen), ejecting the CD-ROM media. Only applies to cd-rom type disks. Signed-off-by: Terraform Provider Developer <terraform@harvester.local>
- Add description to eject field in data source docs - Validate that eject is only set on cd-rom type disks, return clear error instead of silently ignoring - Add test case for CD-ROM with no Tray field set (default behavior) Signed-off-by: Terraform Provider Developer <terraform@harvester.local>
60e1fd2 to
01b692c
Compare
Summary
Add an
ejectboolean field to thediskblock that controls the CD-ROM tray state via KubeVirt'sCDRomTarget.TrayAPI.eject = false(default): tray is closed, CD-ROM media is mountedeject = true: tray is open, CD-ROM media is ejectedThis enables the common workflow of installing an OS from an ISO, then ejecting the CD-ROM via Terraform without manual kubectl intervention.
Only applies to
type = "cd-rom"disks. Regular disks ignore this field.Related issue: harvester/harvester#10049
Changes
pkg/constants/constants_virtualmachine.goFieldDiskEjectconstantinternal/provider/virtualmachine/schema_virtualmachine_disk.goejectfield (TypeBool, Optional, Default: false)internal/provider/virtualmachine/resource_virtualmachine_constructor.govmBuilder.Disk(), setCDRom.Tray = TrayStateOpenwhen eject is truepkg/importer/resource_virtualmachine_importer.goCDRom.Traystate and map toejectbooleanpkg/importer/resource_virtualmachine_importer_test.godocs/resources/virtualmachine.mdejectfield documentationdocs/data-sources/virtualmachine.mdejectfield documentationExample Usage
Test plan
go test ./pkg/importer/ -run TestDiskEjectImport— 3 sub-tests (tray open, tray closed, regular disk)go build ./...— compilation passesgofmt -l .— no formatting issuesgo generate ./...— docs generatedtype = "cd-rom",eject = false) — verified tray closedeject = true— verified tray opened viakubectl get vm -o jsonterraform planshows 0 changes after ejectterraform destroy— VM cleaned up