runtime: Enable ImageName annotation for remote hypervisor

Enables ImageName to support multiple VM images in remote hypervisor scenario

Fixes https://github.com/kata-containers/kata-containers/issues/10240

Signed-off-by: Ajay Victor <ajvictor@in.ibm.com>
This commit is contained in:
Ajay Victor 2024-09-03 23:36:45 +05:30
parent 1597f8ba00
commit a19f2eacec
4 changed files with 35 additions and 4 deletions

View File

@ -38,7 +38,7 @@ remote_hypervisor_timeout = 600
# Each member of the list is a regular expression, which is the base name
# of the annotation, e.g. "path" for io.katacontainers.config.hypervisor.path"
# Note: Remote hypervisor is only handling the following annotations
enable_annotations = ["machine_type", "default_memory", "default_vcpus"]
enable_annotations = ["machine_type", "default_memory", "default_vcpus", "image"]
# Optional space-separated list of options to pass to the guest kernel.
# For example, use `kernel_params = "vsyscall=emulate"` if you are having

View File

@ -77,6 +77,7 @@ func (rh *remoteHypervisor) CreateVM(ctx context.Context, id string, network Net
annotations[cri.SandboxName] = hypervisorConfig.SandboxName
annotations[cri.SandboxNamespace] = hypervisorConfig.SandboxNamespace
annotations[hypannotations.MachineType] = hypervisorConfig.HypervisorMachineType
annotations[hypannotations.ImagePath] = hypervisorConfig.ImagePath
annotations[hypannotations.DefaultVCPUs] = strconv.FormatUint(uint64(hypervisorConfig.NumVCPUs()), 10)
annotations[hypannotations.DefaultMemory] = strconv.FormatUint(uint64(hypervisorConfig.MemorySize), 10)
annotations[hypannotations.Initdata] = hypervisorConfig.Initdata

View File

@ -448,6 +448,17 @@ func createAssets(ctx context.Context, sandboxConfig *SandboxConfig) error {
defer span.End()
for _, name := range types.AssetTypes() {
annotation, _, err := name.Annotations()
if err != nil {
return err
}
// For remote hypervisor donot check for Absolute Path incase of ImagePath, as it denotes the name of the image.
if sandboxConfig.HypervisorType == RemoteHypervisor && annotation == annotations.ImagePath {
value := sandboxConfig.Annotations[annotation]
if value != "" {
sandboxConfig.HypervisorConfig.ImagePath = value
}
} else {
a, err := types.NewAsset(sandboxConfig.Annotations, name)
if err != nil {
return err
@ -457,6 +468,7 @@ func createAssets(ctx context.Context, sandboxConfig *SandboxConfig) error {
return err
}
}
}
_, imageErr := sandboxConfig.HypervisorConfig.assetPath(types.ImageAsset)
_, initrdErr := sandboxConfig.HypervisorConfig.assetPath(types.InitrdAsset)

View File

@ -771,6 +771,24 @@ func TestSandboxCreateAssets(t *testing.T) {
err = createAssets(context.Background(), config)
assert.Error(err, msg)
}
// Remote Hypervisor scenario for ImagePath
msg := "test[image]: imagePath"
imagePathData := &testData{
assetType: types.ImageAsset,
annotations: map[string]string{
annotations.ImagePath: "rhel9-os",
},
}
config := &SandboxConfig{
Annotations: imagePathData.annotations,
HypervisorConfig: hc,
HypervisorType: RemoteHypervisor,
}
err = createAssets(context.Background(), config)
assert.NoError(err, msg)
}
func testFindContainerFailure(t *testing.T, sandbox *Sandbox, cid string) {