From 9fda7059a50b43b0461bbcd4c4dfa2e2cc3d1212 Mon Sep 17 00:00:00 2001 From: Peng Tao Date: Tue, 22 Aug 2023 07:49:26 +0000 Subject: [PATCH] runtime/clh: fix image/initrd annotation handling We should make sure annotations are preferred over config options in image and initrd path handling. Fixes: #7705 Signed-off-by: Peng Tao --- src/runtime/virtcontainers/clh.go | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/runtime/virtcontainers/clh.go b/src/runtime/virtcontainers/clh.go index 10a1fc7ab9..25bcef3774 100644 --- a/src/runtime/virtcontainers/clh.go +++ b/src/runtime/virtcontainers/clh.go @@ -538,14 +538,14 @@ func (clh *cloudHypervisor) CreateVM(ctx context.Context, id string, network Net clh.vmconfig.Rng = chclient.NewRngConfig(clh.config.EntropySource) // set the initial root/boot disk of hypervisor - imagePath, err := clh.config.ImageAssetPath() + assetPath, assetType, err := clh.config.ImageOrInitrdAssetPath() if err != nil { return err } - if imagePath != "" { + if assetType == types.ImageAsset { if clh.config.ConfidentialGuest { - disk := chclient.NewDiskConfig(imagePath) + disk := chclient.NewDiskConfig(assetPath) disk.SetReadonly(true) diskRateLimiterConfig := clh.getDiskRateLimiterConfig() @@ -559,7 +559,7 @@ func (clh *cloudHypervisor) CreateVM(ctx context.Context, id string, network Net clh.vmconfig.Disks = &[]chclient.DiskConfig{*disk} } } else { - pmem := chclient.NewPmemConfig(imagePath) + pmem := chclient.NewPmemConfig(assetPath) *pmem.DiscardWrites = true if clh.vmconfig.Pmem != nil { @@ -569,12 +569,8 @@ func (clh *cloudHypervisor) CreateVM(ctx context.Context, id string, network Net } } } else { - initrdPath, err := clh.config.InitrdAssetPath() - if err != nil { - return err - } - - clh.vmconfig.Payload.SetInitramfs(initrdPath) + // assetType == types.InitrdAsset + clh.vmconfig.Payload.SetInitramfs(assetPath) } if clh.config.ConfidentialGuest {