Skip to content

Commit

Permalink
Merge pull request #23 from liquidmetal-dev/volumes
Browse files Browse the repository at this point in the history
feat: add ability to specify additional volumes
  • Loading branch information
richardcase authored Dec 30, 2024
2 parents dec7556 + d55a501 commit 3a10934
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 5 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NIX_HARDENING_ENABLE=""
11 changes: 11 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

# Automatically sets up your devbox environment whenever you cd into this
# directory via our direnv integration:

eval "$(devbox generate direnv --print-envrc --env-file .env)"

# check out https://www.jetpack.io/devbox/docs/ide_configuration/direnv/
# for more details

export NIX_HARDENING_ENABLE=""
18 changes: 18 additions & 0 deletions devbox.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"$schema": "https://raw.githubusercontent.com/jetify-com/devbox/0.13.6/.schema/devbox.schema.json",
"packages": [
"[email protected]"
],
"shell": {
"env": {
"GOPATH": "$HOME/go/",
"PATH": "$PATH:$HOME/go/bin"
},
"init_hook": [
"export \"GOROOT=$(go env GOROOT)\""
],
"scripts": {
"run_test": "go run main.go"
}
}
}
53 changes: 53 additions & 0 deletions devbox.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"lockfile_version": "1",
"packages": {
"[email protected]": {
"last_modified": "2024-11-28T07:51:56Z",
"resolved": "github:NixOS/nixpkgs/226216574ada4c3ecefcbbec41f39ce4655f78ef#go_1_22",
"source": "devbox-search",
"version": "1.22.9",
"systems": {
"aarch64-darwin": {
"outputs": [
{
"name": "out",
"path": "/nix/store/4nf51i4ah186y2jy3fad2fyvpa49qx6q-go-1.22.9",
"default": true
}
],
"store_path": "/nix/store/4nf51i4ah186y2jy3fad2fyvpa49qx6q-go-1.22.9"
},
"aarch64-linux": {
"outputs": [
{
"name": "out",
"path": "/nix/store/8w8vzwgp55yl8j1ljgm4wzdgjkvkv5v3-go-1.22.9",
"default": true
}
],
"store_path": "/nix/store/8w8vzwgp55yl8j1ljgm4wzdgjkvkv5v3-go-1.22.9"
},
"x86_64-darwin": {
"outputs": [
{
"name": "out",
"path": "/nix/store/vlih7j78ki05i8nvzdsxvws7a7ksq04m-go-1.22.9",
"default": true
}
],
"store_path": "/nix/store/vlih7j78ki05i8nvzdsxvws7a7ksq04m-go-1.22.9"
},
"x86_64-linux": {
"outputs": [
{
"name": "out",
"path": "/nix/store/frc5188kgv3ws0n999c7cy5vi2f8k4jp-go-1.22.9",
"default": true
}
],
"store_path": "/nix/store/frc5188kgv3ws0n999c7cy5vi2f8k4jp-go-1.22.9"
}
}
}
}
}
7 changes: 7 additions & 0 deletions internal/cmd/microvm/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func newCreateCommand() *cli.Command {
createInput := &app.CreateInput{}
networkInterfaces := &cli.StringSlice{}
metadataFromFile := &cli.StringSlice{}
volumes := &cli.StringSlice{}

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

createInput.NetworkInterfaces = networkInterfaces.Value()
createInput.MetadataFromFile = metadataFromFile.Value()
createInput.Volumes = volumes.Value()

if err := a.Create(ctx.Context, createInput); err != nil {
return fmt.Errorf("creating microvm: %s", err)
Expand Down Expand Up @@ -151,6 +153,11 @@ func newCreateCommand() *cli.Command {
Usage: "set the cloud-init final message",
Destination: &createInput.Metadata.Message,
},
&cli.StringSliceFlag{
Name: "volume",
Usage: "attach an additional volume, The following format: name=containerimage=mountpoint",
Destination: volumes,
},
},
}

Expand Down
29 changes: 24 additions & 5 deletions pkg/app/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (a *app) addUserdata(spec *flintlocktypes.MicroVMSpec, input *CreateInput)
return nil
}

//TODO: this whole thing needs rewriting
// TODO: this whole thing needs rewriting
func (a *app) convertCreateInputToReq(input *CreateInput) (*flintlocktypes.MicroVMSpec, error) {
req := &flintlocktypes.MicroVMSpec{
Id: input.Name,
Expand All @@ -77,7 +77,7 @@ func (a *app) convertCreateInputToReq(input *CreateInput) (*flintlocktypes.Micro
Image: input.KernelImage,
AddNetworkConfig: input.KernelAddNetConf,
Filename: &input.KernelFileName,
//TODO: additional args
// TODO: additional args
},
RootVolume: &flintlocktypes.Volume{
Id: "root",
Expand All @@ -103,7 +103,7 @@ func (a *app) convertCreateInputToReq(input *CreateInput) (*flintlocktypes.Micro
metaFromFile := input.MetadataFromFile[i]
metaparts := strings.Split(metaFromFile, "=")
if len(metaparts) != 2 {
//TODO: proper error
// TODO: proper error
return nil, fmt.Errorf("metadata not in name=pathtofile format")
}
content, err := os.ReadFile(metaparts[1])
Expand All @@ -117,14 +117,14 @@ func (a *app) convertCreateInputToReq(input *CreateInput) (*flintlocktypes.Micro
netInt := input.NetworkInterfaces[i]
netParts := strings.Split(netInt, ":")
if len(netParts) < 1 || len(netParts) > 4 {
//TODO: proper error
// TODO: proper error
return nil, fmt.Errorf("network interfaces not in correct format, expect name:type:[macaddress]:[ipaddress]")
}

macAddress := ""
ipAddress := ""
name := netParts[0]
intType := netParts[1] //TODO: validate the types
intType := netParts[1] // TODO: validate the types

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

for i := range input.Volumes {
volume := input.Volumes[i]
volParts := strings.Split(volume, "=")
if len(volParts) != 3 {
// TODO: proper error
return nil, fmt.Errorf("volume not in correct format, expect name=containerimage=mountpoint")
}

apiVolume := &flintlocktypes.Volume{
Id: volParts[0],
IsReadOnly: false,
MountPoint: volParts[2],
Source: &flintlocktypes.VolumeSource{
ContainerSource: &volParts[1],
},
}
req.AdditionalVolumes = append(req.AdditionalVolumes, apiVolume)
}

return req, nil
}

Expand Down
1 change: 1 addition & 0 deletions pkg/app/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type CreateInput struct {
NetworkInterfaces []string
MetadataFromFile []string
Metadata Metadata
Volumes []string
}

type Metadata struct {
Expand Down

0 comments on commit 3a10934

Please sign in to comment.