HCP Packer Registry Support + CD-ROM Bus Portability - #49
Merged
Conversation
Implements native HCP Packer integration so the kubevirt-iso builder
registers its artifacts with the HCP Packer registry after each
successful build.
Changes:
- artifact.go: add Namespace and StateData fields; implement
State(registryimage.ArtifactStateURI) returning a *registryimage.Image
with provider=kubevirt, region=namespace, and generated_data labels;
Id() now returns namespace/name for an unambiguous artifact identifier
- builder.go: declare BootableVolumeName as a generated variable in
Prepare() so provisioners can reference it via build.BootableVolumeName;
wire packerbuilderdata.GeneratedData in Run(); add post-runner
error/cancel state checks before artifact construction; gate
StepCreateBootableVolume on !SkipCreateImage; return nil artifact
when SkipCreateImage is set
- config.go: add skip_create_image bool field to allow skipping final
image creation and HCP registration during iterative debugging
- config.hcl2spec.go: regenerated via go generate
- step_create_bootablevolume.go: add GeneratedData field; call
GeneratedData.Put("BootableVolumeName", ...) and store
bootable_volume_namespace in state bag alongside the existing
bootable_volume_name entry
- step_create_bootablevolume_test.go: wire GeneratedData into BeforeEach
to prevent nil pointer panic with new field
- artifact_test.go: new table-driven tests covering BuilderId, Id,
String, Files, Destroy, State(ArtifactStateURI) with and without
generated_data, and StateData fallthrough including nil map safety
KubeVirt rejects CD-ROM devices with no bus set because it defaults to virtio, which is invalid for CD-ROMs. Explicitly set bus to sata on both the cdrom and oemdrv disk devices for linux VMs, matching the existing behaviour of the windows VM disks.
Exposes the CD-ROM disk bus type as a user-configurable field so builds work across architectures without code changes. arm64 clusters (e.g. minikube on Apple Silicon) only support virtio and scsi for disk buses. sata is rejected by the admission webhook. x86 clusters accept sata. Previously the bus was hardcoded, breaking arm64 users. - Default is 'scsi', which is valid on both x86 and arm64 - User can override to 'sata' or 'virtio' via disk_bus in the template - Applied to both cdrom and oemdrv CD-ROM devices for linux VMs - Windows VM disks are unaffected (already explicitly set to sata)
Collaborator
Author
|
Hi @anurag5sh - sorry I duplicated PRs but I closed the other one. I fixed the tests and this should be good to go now. |
anurag5sh
approved these changes
Aug 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds native HCP Packer registry integration to the
kubevirt-isobuilder and fixes a pre-existing bug where Linux CD-ROM disk devices had no
bus type set, causing builds to fail on arm64 clusters.
Changes
1. HCP Packer registry support (
10f464d)The
kubevirt-isobuilder now registers build artifacts with the HCP Packerregistry after each successful build. When a
hcp_packer_registryblock ispresent in the template, Packer core will track the resulting
DataSourceas a versioned artifact in the registry.
artifact.goNamespaceandStateDatafields toArtifactId()now returnsnamespace/name(e.g.images/fedora-42) so HCP cantrack artifacts unambiguously across clusters
State()handles theregistryimage.ArtifactStateURIkey(
"par.artifact.metadata") and returns a populated*registryimage.Imagewith
provider=kubevirt,region=<namespace>, and labels includingnamespaceand any values fromgenerated_databuilder.goPrepare()returns[]string{"BootableVolumeName"}so provisioners canreference the artifact name at runtime via
build.BootableVolumeNameRun()wirespackerbuilderdata.GeneratedDataso generated values areaccessible in provisioner interpolation
state.GetOk("error")andstate.GetOk(StateCancelled)checks before artifact construction — previously a halted build would return
a misleading
"bootable volume name not found in state"error instead ofthe real underlying error
StepCreateBootableVolumeis gated on!SkipCreateImageso the step isskipped when the flag is set
config.goskip_create_image bool— whentrue, skips the finalStepCreateBootableVolumestep and returns no artifact, which alsosuppresses HCP registration. Useful for iterative debugging without
producing a final image.
step_create_bootablevolume.goGeneratedData *packerbuilderdata.GeneratedDatafieldGeneratedData.Put("BootableVolumeName", ds.Name)so the value isavailable to provisioners
bootable_volume_namespacein the state bag alongside the existingbootable_volume_namesoBuilder.Run()can construct a fully-qualifiedartifact ID
artifact_test.go(new)BuilderId,Id,String,Files,Destroy,State(ArtifactStateURI)with and withoutgenerated_data,and
StateDatafallthrough including nil map safetystep_create_bootablevolume_test.goGeneratedDataintoBeforeEachto prevent nil pointer panic2. CD-ROM bus type — intermediate fix (
cde2306)During testing, KubeVirt's admission webhook rejected the VM because Linux
CD-ROM devices had no
Busset. KubeVirt was defaulting tovirtio, whichis an invalid bus type for CD-ROM devices. This commit hardcoded
sataasa stepping stone; it was immediately superseded by commit
ef8f80d.3. Configurable CD-ROM bus type (
ef8f80d)The intermediate
satafix broke arm64 clusters (including OpenShift onARM), where the admission webhook only accepts
virtioorscsifor diskbuses. Rather than hardcode either value, this commit exposes
disk_busasa user-configurable field.
config.godisk_bus stringfield withmapstructure:"disk_bus"Prepare()defaults to"scsi"when unset — valid on both x86 and arm64resources.gogetLinuxVirtualMachineDisks()now acceptsdiskBus stringand appliesv1.DiskBus(diskBus)to both thecdromandoemdrvCD-ROM devicessata)step_create_virtualmachine.gos.Config.DiskBusand passes it through tovirtualMachine()Example usage in template:
What was tested
All existing unit tests pass. New unit tests for the HCP artifact wiring pass.
End-to-end testing was carried out on a local minikube cluster (qemu2 driver,
Apple Silicon). The following was verified locally:
packer validateacceptshcp_packer_registry {}andskip_create_imageTracking build on HCP Packer with fingerprint ...appears in build output)StepValidateIsoDataVolumereaches the cluster and validates the ISODataVolume successfully
StepCopyMediaFilescreates the ConfigMap successfullyStepCreateVirtualMachinecreates the VM withdisk_bus = "scsi"withoutrejection from the admission webhook
End-to-end VM boot and full HCP artifact registration could not be completed
locally due to a minikube + Docker networking constraint (
nf_nattableoperations are not permitted inside a Docker container, which prevents
KubeVirt's masquerade networking from initialising the VM's network stack).
This is an environment limitation, not a plugin issue.
Remaining tests required before merge
The following must be run on a Linux-based KubeVirt cluster (bare metal,
OpenShift Local/CRC, or a cloud-hosted cluster):
1. Full build completes and registers with HCP
Expected:
kubevirt-test→ latest version shows:images/hcp-test-imagekubevirtimagesimageshcp-test-image2.
build.BootableVolumeNameis accessible in provisionersAdd to the build block:
Expected: Provisioner output contains
BootableVolumeName=hcp-test-imageand not the
ERR_*placeholder.3. Second build creates a new version
Change
nametohcp-test-image-2and re-run.Expected: HCP bucket shows 2 distinct versions.
4. Failed build is not registered
Set
iso_volume_nameto a DataVolume that does not exist and run.Expected: Build exits non-zero, no new version in HCP bucket.
5.
skip_create_image = truesuppresses HCP registrationAdd
skip_create_image = trueto the source block and run.Expected: No
Creating a new bootable volumelog line, no artifactoutput, no new version in HCP bucket.