Skip to content

Commit

Permalink
Merge pull request #10274 from ajaypvictor/remote_image-os_types
Browse files Browse the repository at this point in the history
runtime: Enable Image annotation for remote hypervisor
  • Loading branch information
fidencio authored Sep 19, 2024
2 parents 3d5f48e + a19f2ea commit 4d11fec
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/runtime/config/configuration-remote.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/runtime/virtcontainers/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 15 additions & 3 deletions src/runtime/virtcontainers/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,13 +448,25 @@ func createAssets(ctx context.Context, sandboxConfig *SandboxConfig) error {
defer span.End()

for _, name := range types.AssetTypes() {
a, err := types.NewAsset(sandboxConfig.Annotations, name)
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
}

if err := sandboxConfig.HypervisorConfig.AddCustomAsset(a); err != nil {
return err
if err := sandboxConfig.HypervisorConfig.AddCustomAsset(a); err != nil {
return err
}
}
}

Expand Down
18 changes: 18 additions & 0 deletions src/runtime/virtcontainers/sandbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 4d11fec

Please sign in to comment.