From cd898d28c79a076357cd23c5681ca6d10ca4a450 Mon Sep 17 00:00:00 2001 From: Bo Chen Date: Wed, 17 Aug 2022 12:15:04 -0700 Subject: [PATCH] runtime: clh: Use the new 'payload' interface The new 'payload' interface now contains the 'kernel' and 'initramfs' config. Fixes: #4952 Signed-off-by: Bo Chen (cherry picked from commit 3a597c274240aae16eb4d380b37c64b21d0642e8) --- src/runtime/virtcontainers/clh.go | 12 ++++++------ src/runtime/virtcontainers/clh_test.go | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/runtime/virtcontainers/clh.go b/src/runtime/virtcontainers/clh.go index aaa8e2886a..b14391b932 100644 --- a/src/runtime/virtcontainers/clh.go +++ b/src/runtime/virtcontainers/clh.go @@ -459,13 +459,15 @@ func (clh *cloudHypervisor) CreateVM(ctx context.Context, id string, network Net // to fetch if this is the first time the hypervisor is created. clh.Logger().WithField("function", "CreateVM").Info("Sandbox not found creating") + // Create the VM config via the constructor to ensure default values are properly assigned + clh.vmconfig = *chclient.NewVmConfig(*chclient.NewPayloadConfig()) + // Make sure the kernel path is valid kernelPath, err := clh.config.KernelAssetPath() if err != nil { return err } - // Create the VM config via the constructor to ensure default values are properly assigned - clh.vmconfig = *chclient.NewVmConfig(*chclient.NewKernelConfig(kernelPath)) + clh.vmconfig.Payload.SetKernel(kernelPath) if clh.config.ConfidentialGuest { if err := clh.enableProtection(); err != nil { @@ -505,7 +507,7 @@ func (clh *cloudHypervisor) CreateVM(ctx context.Context, id string, network Net // Followed by extra kernel parameters defined in the configuration file params = append(params, clh.config.KernelParams...) - clh.vmconfig.Cmdline = chclient.NewCmdLineConfig(kernelParamsToString(params)) + clh.vmconfig.Payload.SetCmdline(kernelParamsToString(params)) // set random device generator to hypervisor clh.vmconfig.Rng = chclient.NewRngConfig(clh.config.EntropySource) @@ -547,9 +549,7 @@ func (clh *cloudHypervisor) CreateVM(ctx context.Context, id string, network Net return err } - initrd := chclient.NewInitramfsConfig(initrdPath) - - clh.vmconfig.SetInitramfs(*initrd) + clh.vmconfig.Payload.SetInitramfs(initrdPath) } // Use serial port as the guest console only in debug mode, diff --git a/src/runtime/virtcontainers/clh_test.go b/src/runtime/virtcontainers/clh_test.go index bb4a04925b..58b1b7fe9a 100644 --- a/src/runtime/virtcontainers/clh_test.go +++ b/src/runtime/virtcontainers/clh_test.go @@ -557,7 +557,7 @@ func TestCloudHypervisorResizeMemory(t *testing.T) { clh := cloudHypervisor{} mockClient := &clhClientMock{} - mockClient.vmInfo.Config = *chclient.NewVmConfig(*chclient.NewKernelConfig("")) + mockClient.vmInfo.Config = *chclient.NewVmConfig(*chclient.NewPayloadConfig()) mockClient.vmInfo.Config.Memory = chclient.NewMemoryConfig(int64(utils.MemUnit(clhConfig.MemorySize) * utils.MiB)) mockClient.vmInfo.Config.Memory.HotplugSize = func(i int64) *int64 { return &i }(int64(40 * utils.GiB.ToBytes()))