Skip to content

Commit 3a10934

Browse files
authored
Merge pull request #23 from liquidmetal-dev/volumes
feat: add ability to specify additional volumes
2 parents dec7556 + d55a501 commit 3a10934

File tree

7 files changed

+115
-5
lines changed

7 files changed

+115
-5
lines changed

.env

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
NIX_HARDENING_ENABLE=""

.envrc

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
# Automatically sets up your devbox environment whenever you cd into this
4+
# directory via our direnv integration:
5+
6+
eval "$(devbox generate direnv --print-envrc --env-file .env)"
7+
8+
# check out https://www.jetpack.io/devbox/docs/ide_configuration/direnv/
9+
# for more details
10+
11+
export NIX_HARDENING_ENABLE=""

devbox.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/jetify-com/devbox/0.13.6/.schema/devbox.schema.json",
3+
"packages": [
4+
5+
],
6+
"shell": {
7+
"env": {
8+
"GOPATH": "$HOME/go/",
9+
"PATH": "$PATH:$HOME/go/bin"
10+
},
11+
"init_hook": [
12+
"export \"GOROOT=$(go env GOROOT)\""
13+
],
14+
"scripts": {
15+
"run_test": "go run main.go"
16+
}
17+
}
18+
}

devbox.lock

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"lockfile_version": "1",
3+
"packages": {
4+
5+
"last_modified": "2024-11-28T07:51:56Z",
6+
"resolved": "github:NixOS/nixpkgs/226216574ada4c3ecefcbbec41f39ce4655f78ef#go_1_22",
7+
"source": "devbox-search",
8+
"version": "1.22.9",
9+
"systems": {
10+
"aarch64-darwin": {
11+
"outputs": [
12+
{
13+
"name": "out",
14+
"path": "/nix/store/4nf51i4ah186y2jy3fad2fyvpa49qx6q-go-1.22.9",
15+
"default": true
16+
}
17+
],
18+
"store_path": "/nix/store/4nf51i4ah186y2jy3fad2fyvpa49qx6q-go-1.22.9"
19+
},
20+
"aarch64-linux": {
21+
"outputs": [
22+
{
23+
"name": "out",
24+
"path": "/nix/store/8w8vzwgp55yl8j1ljgm4wzdgjkvkv5v3-go-1.22.9",
25+
"default": true
26+
}
27+
],
28+
"store_path": "/nix/store/8w8vzwgp55yl8j1ljgm4wzdgjkvkv5v3-go-1.22.9"
29+
},
30+
"x86_64-darwin": {
31+
"outputs": [
32+
{
33+
"name": "out",
34+
"path": "/nix/store/vlih7j78ki05i8nvzdsxvws7a7ksq04m-go-1.22.9",
35+
"default": true
36+
}
37+
],
38+
"store_path": "/nix/store/vlih7j78ki05i8nvzdsxvws7a7ksq04m-go-1.22.9"
39+
},
40+
"x86_64-linux": {
41+
"outputs": [
42+
{
43+
"name": "out",
44+
"path": "/nix/store/frc5188kgv3ws0n999c7cy5vi2f8k4jp-go-1.22.9",
45+
"default": true
46+
}
47+
],
48+
"store_path": "/nix/store/frc5188kgv3ws0n999c7cy5vi2f8k4jp-go-1.22.9"
49+
}
50+
}
51+
}
52+
}
53+
}

internal/cmd/microvm/create.go

+7
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func newCreateCommand() *cli.Command {
2323
createInput := &app.CreateInput{}
2424
networkInterfaces := &cli.StringSlice{}
2525
metadataFromFile := &cli.StringSlice{}
26+
volumes := &cli.StringSlice{}
2627

2728
cmd := &cli.Command{
2829
Name: "create",
@@ -43,6 +44,7 @@ func newCreateCommand() *cli.Command {
4344

4445
createInput.NetworkInterfaces = networkInterfaces.Value()
4546
createInput.MetadataFromFile = metadataFromFile.Value()
47+
createInput.Volumes = volumes.Value()
4648

4749
if err := a.Create(ctx.Context, createInput); err != nil {
4850
return fmt.Errorf("creating microvm: %s", err)
@@ -151,6 +153,11 @@ func newCreateCommand() *cli.Command {
151153
Usage: "set the cloud-init final message",
152154
Destination: &createInput.Metadata.Message,
153155
},
156+
&cli.StringSliceFlag{
157+
Name: "volume",
158+
Usage: "attach an additional volume, The following format: name=containerimage=mountpoint",
159+
Destination: volumes,
160+
},
154161
},
155162
}
156163

pkg/app/create.go

+24-5
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func (a *app) addUserdata(spec *flintlocktypes.MicroVMSpec, input *CreateInput)
6363
return nil
6464
}
6565

66-
//TODO: this whole thing needs rewriting
66+
// TODO: this whole thing needs rewriting
6767
func (a *app) convertCreateInputToReq(input *CreateInput) (*flintlocktypes.MicroVMSpec, error) {
6868
req := &flintlocktypes.MicroVMSpec{
6969
Id: input.Name,
@@ -77,7 +77,7 @@ func (a *app) convertCreateInputToReq(input *CreateInput) (*flintlocktypes.Micro
7777
Image: input.KernelImage,
7878
AddNetworkConfig: input.KernelAddNetConf,
7979
Filename: &input.KernelFileName,
80-
//TODO: additional args
80+
// TODO: additional args
8181
},
8282
RootVolume: &flintlocktypes.Volume{
8383
Id: "root",
@@ -103,7 +103,7 @@ func (a *app) convertCreateInputToReq(input *CreateInput) (*flintlocktypes.Micro
103103
metaFromFile := input.MetadataFromFile[i]
104104
metaparts := strings.Split(metaFromFile, "=")
105105
if len(metaparts) != 2 {
106-
//TODO: proper error
106+
// TODO: proper error
107107
return nil, fmt.Errorf("metadata not in name=pathtofile format")
108108
}
109109
content, err := os.ReadFile(metaparts[1])
@@ -117,14 +117,14 @@ func (a *app) convertCreateInputToReq(input *CreateInput) (*flintlocktypes.Micro
117117
netInt := input.NetworkInterfaces[i]
118118
netParts := strings.Split(netInt, ":")
119119
if len(netParts) < 1 || len(netParts) > 4 {
120-
//TODO: proper error
120+
// TODO: proper error
121121
return nil, fmt.Errorf("network interfaces not in correct format, expect name:type:[macaddress]:[ipaddress]")
122122
}
123123

124124
macAddress := ""
125125
ipAddress := ""
126126
name := netParts[0]
127-
intType := netParts[1] //TODO: validate the types
127+
intType := netParts[1] // TODO: validate the types
128128

129129
if name == "eth0" {
130130
return nil, fmt.Errorf("you cannot use eth0 as the name of the interface as this is reserved")
@@ -165,6 +165,25 @@ func (a *app) convertCreateInputToReq(input *CreateInput) (*flintlocktypes.Micro
165165
req.Interfaces = append(req.Interfaces, apiIface)
166166
}
167167

168+
for i := range input.Volumes {
169+
volume := input.Volumes[i]
170+
volParts := strings.Split(volume, "=")
171+
if len(volParts) != 3 {
172+
// TODO: proper error
173+
return nil, fmt.Errorf("volume not in correct format, expect name=containerimage=mountpoint")
174+
}
175+
176+
apiVolume := &flintlocktypes.Volume{
177+
Id: volParts[0],
178+
IsReadOnly: false,
179+
MountPoint: volParts[2],
180+
Source: &flintlocktypes.VolumeSource{
181+
ContainerSource: &volParts[1],
182+
},
183+
}
184+
req.AdditionalVolumes = append(req.AdditionalVolumes, apiVolume)
185+
}
186+
168187
return req, nil
169188
}
170189

pkg/app/types.go

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type CreateInput struct {
1616
NetworkInterfaces []string
1717
MetadataFromFile []string
1818
Metadata Metadata
19+
Volumes []string
1920
}
2021

2122
type Metadata struct {

0 commit comments

Comments
 (0)