Skip to content

Commit a7c45e7

Browse files
feat(monitor): add initial support for embedded hyperlight VMM (#140)
1 parent 67cd349 commit a7c45e7

3 files changed

Lines changed: 126 additions & 0 deletions

File tree

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright (c) 2023-2026, Nubificus LTD
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package hypervisors
16+
17+
import (
18+
"strings"
19+
20+
"github.com/urunc-dev/urunc/pkg/unikontainers/types"
21+
)
22+
23+
const (
24+
HyperlightVmm VmmType = "hyperlight"
25+
HyperlightBinary string = ""
26+
)
27+
28+
type Hyperlight struct {
29+
binaryPath string
30+
binary string
31+
}
32+
33+
// Stop kills the hyperlight process
34+
func (h *Hyperlight) Stop(pid int) error {
35+
return killProcess(pid)
36+
}
37+
38+
// UsesKVM returns a bool value depending on if the monitor uses KVM
39+
func (h *Hyperlight) UsesKVM() bool {
40+
return true
41+
}
42+
43+
// SupportsSharedfs returns a bool value depending on the monitor support for shared-fs
44+
func (h *Hyperlight) SupportsSharedfs(_ string) bool {
45+
return false
46+
}
47+
48+
// Path returns the path to the hyperlight binary.
49+
func (h *Hyperlight) Path() string {
50+
return h.binaryPath
51+
}
52+
53+
// Ok checks if the hyperlight binary is available.
54+
// Since hyperlight is embedded, we just return nil.
55+
func (h *Hyperlight) Ok() error {
56+
return nil
57+
}
58+
59+
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, " ")...)
64+
}
65+
return cmdArgs, nil
66+
}
67+
68+
// PreExec performs pre-execution setup. Hyperlight has no special pre-exec requirements.
69+
func (h *Hyperlight) PreExec(_ types.ExecArgs) error {
70+
return nil
71+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright (c) 2023-2026, Nubificus LTD
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package hypervisors
16+
17+
import (
18+
"testing"
19+
20+
"github.com/stretchr/testify/assert"
21+
"github.com/urunc-dev/urunc/pkg/unikontainers/types"
22+
)
23+
24+
func TestHyperlightBuildExecCmd(t *testing.T) {
25+
h := &Hyperlight{}
26+
args := types.ExecArgs{
27+
UnikernelPath: "/path/to/unikernel",
28+
Command: "arg1 arg2",
29+
}
30+
31+
cmd, err := h.BuildExecCmd(args, nil)
32+
assert.NoError(t, err)
33+
assert.Equal(t, []string{"/path/to/unikernel", "arg1", "arg2"}, cmd)
34+
}
35+
36+
func TestHyperlightBuildExecCmdNoArgs(t *testing.T) {
37+
h := &Hyperlight{}
38+
args := types.ExecArgs{
39+
UnikernelPath: "/path/to/unikernel",
40+
Command: "",
41+
}
42+
43+
cmd, err := h.BuildExecCmd(args, nil)
44+
assert.NoError(t, err)
45+
assert.Equal(t, []string{"/path/to/unikernel"}, cmd)
46+
}

pkg/unikontainers/hypervisors/vmm.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ var vmmFactories = map[VmmType]VMMFactory{
6666
return &CloudHypervisor{binary: binary, binaryPath: binaryPath}
6767
},
6868
},
69+
HyperlightVmm: {
70+
binary: HyperlightBinary,
71+
createFunc: func(binary, binaryPath string, _ bool) types.VMM {
72+
return &Hyperlight{binary: binary, binaryPath: binaryPath}
73+
},
74+
},
6975
}
7076

7177
func NewVMM(vmmType VmmType, monitors map[string]types.MonitorConfig) (vmm types.VMM, err error) {
@@ -98,6 +104,9 @@ func NewVMM(vmmType VmmType, monitors map[string]types.MonitorConfig) (vmm types
98104
}
99105

100106
func getVMMPath(vmmType VmmType, binary string, monitors map[string]types.MonitorConfig) (string, error) {
107+
if vmmType == HyperlightVmm {
108+
return "", nil
109+
}
101110
if vmmPath := monitors[string(vmmType)].BinaryPath; vmmPath != "" {
102111
return vmmPath, nil
103112
}

0 commit comments

Comments
 (0)