Skip to content

Commit 6c9f522

Browse files
feat(monitor): support host-level hyperlight VMM and add E2E test
Signed-off-by: imshubham22apr-gif <imshubham.22apr@gmail.com>
1 parent 0670143 commit 6c9f522

4 files changed

Lines changed: 40 additions & 18 deletions

File tree

pkg/unikontainers/hypervisors/hyperlight.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
package hypervisors
1616

1717
import (
18-
"strings"
18+
"fmt"
1919

2020
"github.com/urunc-dev/urunc/pkg/unikontainers/types"
2121
)
2222

2323
const (
2424
HyperlightVmm VmmType = "hyperlight"
25-
HyperlightBinary string = ""
25+
HyperlightBinary string = "hyperlight-unikraft"
2626
)
2727

2828
type Hyperlight struct {
@@ -50,17 +50,20 @@ func (h *Hyperlight) Path() string {
5050
return h.binaryPath
5151
}
5252

53-
// Ok checks if the hyperlight binary is available.
54-
// Since hyperlight is embedded, we just return nil.
53+
// Ok checks if the hyperlight-unikraft binary is available.
54+
// Binary availability is already verified by getVMMPath via exec.LookPath.
5555
func (h *Hyperlight) Ok() error {
5656
return nil
5757
}
5858

59+
// BuildExecCmd constructs the hyperlight-unikraft command line.
5960
func (h *Hyperlight) BuildExecCmd(args types.ExecArgs, _ types.Unikernel) ([]string, error) {
60-
// Hyperlight is an embedded VMM, so we just run the unikernel directly.
61-
cmdArgs := []string{args.UnikernelPath}
62-
if args.Command != "" {
63-
cmdArgs = append(cmdArgs, strings.Split(args.Command, " ")...)
61+
cmdArgs := []string{h.binaryPath, args.UnikernelPath}
62+
if args.InitrdPath != "" {
63+
cmdArgs = append(cmdArgs, "--initrd", args.InitrdPath)
64+
}
65+
if args.MemSizeB > 0 {
66+
cmdArgs = append(cmdArgs, "--memory", fmt.Sprintf("%d", args.MemSizeB))
6467
}
6568
return cmdArgs, nil
6669
}

pkg/unikontainers/hypervisors/hyperlight_test.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,30 @@ import (
2222
)
2323

2424
func TestHyperlightBuildExecCmd(t *testing.T) {
25-
h := &Hyperlight{}
25+
h := &Hyperlight{
26+
binaryPath: "/usr/local/bin/hyperlight-unikraft",
27+
}
2628
args := types.ExecArgs{
2729
UnikernelPath: "/path/to/unikernel",
28-
Command: "arg1 arg2",
30+
InitrdPath: "/path/to/initrd",
31+
MemSizeB: 1024 * 1024 * 256,
2932
}
3033

3134
cmd, err := h.BuildExecCmd(args, nil)
3235
assert.NoError(t, err)
33-
assert.Equal(t, []string{"/path/to/unikernel", "arg1", "arg2"}, cmd)
36+
assert.Equal(t, []string{"/usr/local/bin/hyperlight-unikraft", "/path/to/unikernel", "--initrd", "/path/to/initrd", "--memory", "268435456"}, cmd)
3437
}
3538

36-
func TestHyperlightBuildExecCmdNoArgs(t *testing.T) {
37-
h := &Hyperlight{}
39+
func TestHyperlightBuildExecCmdNoInitrd(t *testing.T) {
40+
h := &Hyperlight{
41+
binaryPath: "/usr/local/bin/hyperlight-unikraft",
42+
}
3843
args := types.ExecArgs{
3944
UnikernelPath: "/path/to/unikernel",
40-
Command: "",
45+
MemSizeB: 1024 * 1024 * 256,
4146
}
4247

4348
cmd, err := h.BuildExecCmd(args, nil)
4449
assert.NoError(t, err)
45-
assert.Equal(t, []string{"/path/to/unikernel"}, cmd)
50+
assert.Equal(t, []string{"/usr/local/bin/hyperlight-unikraft", "/path/to/unikernel", "--memory", "268435456"}, cmd)
4651
}

pkg/unikontainers/hypervisors/vmm.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,6 @@ func NewVMM(vmmType VmmType, monitors map[string]types.MonitorConfig) (vmm types
104104
}
105105

106106
func getVMMPath(vmmType VmmType, binary string, monitors map[string]types.MonitorConfig) (string, error) {
107-
if vmmType == HyperlightVmm {
108-
return "", nil
109-
}
110107
if vmmPath := monitors[string(vmmType)].BinaryPath; vmmPath != "" {
111108
return vmmPath, nil
112109
}

tests/e2e/test_cases.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,23 @@ func ctrTestCases() []containerTestArgs {
597597
ExpectOut: "\"Unikraft\" \"FC\" \"urunc\"",
598598
TestFunc: matchTest,
599599
},
600+
{
601+
Image: "ghcr.io/hyperlight-dev/hello-hyperlight-unikraft:latest",
602+
Name: "Hyperlight-unikraft-hello",
603+
Devmapper: false,
604+
Seccomp: true,
605+
UID: 0,
606+
GID: 0,
607+
Groups: []int64{},
608+
Memory: "",
609+
Cli: "",
610+
Volumes: []containerVolume{},
611+
StaticNet: false,
612+
SideContainers: []string{},
613+
Skippable: false,
614+
ExpectOut: "Hello World!",
615+
TestFunc: matchTest,
616+
},
600617
{
601618
Image: "harbor.nbfc.io/nubificus/urunc/hello-env-qemu-unikraft-initrd:latest",
602619
Name: "Qemu-unikraft-environment-variables",

0 commit comments

Comments
 (0)