Description
BuildExecCmd in pkg/unikontainers/hypervisors/cloud_hypervisor.go adds --initramfs unconditionally when args.InitrdPath is non-empty, then adds --initramfs again if extraMonArgs.ExtraInitrd is also non-empty. Cloud Hypervisor does not accept multiple --initramfs flags and rejects the command. The Firecracker implementation in the same codebase handles this correctly by preferring args.InitrdPath and falling back to extraMonArgs.ExtraInitrd only when the former is empty.
Steps to reproduce
Add a test that builds a Cloud Hypervisor exec command with both args.InitrdPath and extraMonArgs.ExtraInitrd set:
go test ./pkg/unikontainers/hypervisors/ -v -run TestCloudHypervisorSingleInitrd
The test asserts that the resulting argument slice contains exactly one --initramfs flag. Before the fix, the slice contains two and the assertion fails.
Expected behavior: The Cloud Hypervisor command line contains at most one --initramfs flag. When both paths are set, args.InitrdPath takes precedence.
Current behavior: When both args.InitrdPath and extraMonArgs.ExtraInitrd are set, the command line contains two --initramfs flags and Cloud Hypervisor rejects it.
Proposed solution: Apply the same priority logic used in the Firecracker implementation: resolve the initrd path to args.InitrdPath if set, otherwise fall back to extraMonArgs.ExtraInitrd. Pass the single resolved path to --initramfs
Description
BuildExecCmdinpkg/unikontainers/hypervisors/cloud_hypervisor.goadds--initramfsunconditionally whenargs.InitrdPathis non-empty, then adds--initramfsagain ifextraMonArgs.ExtraInitrdis also non-empty. Cloud Hypervisor does not accept multiple--initramfsflags and rejects the command. The Firecracker implementation in the same codebase handles this correctly by preferringargs.InitrdPathand falling back toextraMonArgs.ExtraInitrdonly when the former is empty.Steps to reproduce
Add a test that builds a Cloud Hypervisor exec command with both
args.InitrdPathandextraMonArgs.ExtraInitrdset:go test ./pkg/unikontainers/hypervisors/ -v -run TestCloudHypervisorSingleInitrdThe test asserts that the resulting argument slice contains exactly one
--initramfsflag. Before the fix, the slice contains two and the assertion fails.Expected behavior: The Cloud Hypervisor command line contains at most one
--initramfsflag. When both paths are set,args.InitrdPathtakes precedence.Current behavior: When both
args.InitrdPathandextraMonArgs.ExtraInitrdare set, the command line contains two--initramfsflags and Cloud Hypervisor rejects it.Proposed solution: Apply the same priority logic used in the Firecracker implementation: resolve the initrd path to
args.InitrdPathif set, otherwise fall back toextraMonArgs.ExtraInitrd. Pass the single resolved path to--initramfs