Skip to content

Commit 3a96401

Browse files
authored
Merge pull request #26 from liquidmetal-dev/virtiofs
feat: add virtiosfs support
2 parents 8ac4111 + f05c7d9 commit 3a96401

File tree

6 files changed

+56
-29
lines changed

6 files changed

+56
-29
lines changed

go.mod

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
module github.com/liquidmetal-dev/fl
22

3-
go 1.22
3+
go 1.23
4+
5+
toolchain go1.23.4
6+
7+
replace (
8+
github.com/liquidmetal-dev/flintlock/api => ../flintlock/api
9+
github.com/liquidmetal-dev/flintlock/client => ../flintlock/client
10+
)
411

512
require (
613
github.com/liquidmetal-dev/flintlock/api v0.0.0-20241227150005-3cc8809bcb11

go.sum

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
1818
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
1919
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
2020
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
21-
github.com/liquidmetal-dev/flintlock/api v0.0.0-20241227150005-3cc8809bcb11 h1:Aa29z3oh3SSAqs10mgvWmlVmB17XRNLO4p56vuap4gg=
22-
github.com/liquidmetal-dev/flintlock/api v0.0.0-20241227150005-3cc8809bcb11/go.mod h1:Qi6hJN8sd6OvEw6eNGiBR3EFaUbOJYUOCeQa6OeEQxU=
23-
github.com/liquidmetal-dev/flintlock/client v0.0.0-20241227150005-3cc8809bcb11 h1:2C6y1bwLlLjUOEP9+z72UUUddtWq4u4dTZl7CDALd7k=
24-
github.com/liquidmetal-dev/flintlock/client v0.0.0-20241227150005-3cc8809bcb11/go.mod h1:jOUkt2HCTDPa52jW7s1Jq4zGgRgGJO7scFGXMDrMX8M=
2521
github.com/moby/moby v27.4.1+incompatible h1:z6detzbcLRt7U+w4ovHV+8oYpJfpHKTmUbFWPG6cudA=
2622
github.com/moby/moby v27.4.1+incompatible/go.mod h1:fDXVQ6+S340veQPv35CzDahGBmHsiclFwfEygB/TWMc=
2723
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

internal/cmd/microvm/create.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func newCreateCommand() *cli.Command {
2323
createInput := &app.CreateInput{}
2424
networkInterfaces := &cli.StringSlice{}
2525
metadataFromFile := &cli.StringSlice{}
26-
volumes := &cli.StringSlice{}
26+
containerVolumes := &cli.StringSlice{}
2727

2828
cmd := &cli.Command{
2929
Name: "create",
@@ -44,7 +44,7 @@ func newCreateCommand() *cli.Command {
4444

4545
createInput.NetworkInterfaces = networkInterfaces.Value()
4646
createInput.MetadataFromFile = metadataFromFile.Value()
47-
createInput.Volumes = volumes.Value()
47+
createInput.AdditionalContainerVolumes = containerVolumes.Value()
4848

4949
if err := a.Create(ctx.Context, createInput); err != nil {
5050
return fmt.Errorf("creating microvm: %s", err)
@@ -154,9 +154,14 @@ func newCreateCommand() *cli.Command {
154154
Destination: &createInput.Metadata.Message,
155155
},
156156
&cli.StringSliceFlag{
157-
Name: "volume",
158-
Usage: "attach an additional volume, The following format: name=containerimage=mountpoint",
159-
Destination: volumes,
157+
Name: "container-volume",
158+
Usage: "attach additional volumes using a container image, The following format: name=containerimage=mountpoint",
159+
Destination: containerVolumes,
160+
},
161+
&cli.StringFlag{
162+
Name: "virtiofs-volume",
163+
Usage: "attach an additional volume using virtiofs, use the following format: name=localpath=mountpoint",
164+
Destination: &createInput.AdditionalVirtioFSVolume,
160165
},
161166
},
162167
}

pkg/app/create.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import (
1616
"github.com/liquidmetal-dev/flintlock/client/cloudinit/userdata"
1717
)
1818

19+
var rootVolume = "/"
20+
1921
func (a *app) Create(ctx context.Context, input *CreateInput) error {
2022
a.logger.Debug("creating a microvm")
2123

@@ -166,8 +168,8 @@ func (a *app) convertCreateInputToReq(input *CreateInput) (*flintlocktypes.Micro
166168
req.Interfaces = append(req.Interfaces, apiIface)
167169
}
168170

169-
for i := range input.Volumes {
170-
volume := input.Volumes[i]
171+
for i := range input.AdditionalContainerVolumes {
172+
volume := input.AdditionalContainerVolumes[i]
171173
volParts := strings.Split(volume, "=")
172174
if len(volParts) != 3 {
173175
// TODO: proper error
@@ -184,6 +186,23 @@ func (a *app) convertCreateInputToReq(input *CreateInput) (*flintlocktypes.Micro
184186
}
185187
req.AdditionalVolumes = append(req.AdditionalVolumes, apiVolume)
186188
}
189+
if input.AdditionalVirtioFSVolume != "" {
190+
volParts := strings.Split(input.AdditionalVirtioFSVolume, "=")
191+
if len(volParts) != 3 {
192+
// TODO: proper error
193+
return nil, fmt.Errorf("volume not in correct format, expect name=localpath=mountpoint")
194+
}
195+
196+
apiVolume := &flintlocktypes.Volume{
197+
Id: volParts[0],
198+
IsReadOnly: false,
199+
MountPoint: &volParts[2],
200+
Source: &flintlocktypes.VolumeSource{
201+
VirtiofsSource: &volParts[1],
202+
},
203+
}
204+
req.AdditionalVolumes = append(req.AdditionalVolumes, apiVolume)
205+
}
187206

188207
return req, nil
189208
}

pkg/app/delete.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,4 @@ func (a *app) Delete(ctx context.Context, input *DeleteInput) error {
2727
a.logger.Infow("deleted microvm", "uid", input.UID, "host", input.Host)
2828

2929
return nil
30-
3130
}

pkg/app/types.go

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
package app
22

33
type CreateInput struct {
4-
Host string
5-
Name string
6-
NameAutogenerate bool
7-
Namespace string
8-
VCPU int
9-
MemoryInMb int
10-
KernelImage string
11-
KernelAddNetConf bool
12-
KernelFileName string
13-
RootImage string
14-
InitrdImage string
15-
InitrdFilename string
16-
NetworkInterfaces []string
17-
MetadataFromFile []string
18-
Metadata Metadata
19-
Volumes []string
4+
Host string
5+
Name string
6+
NameAutogenerate bool
7+
Namespace string
8+
VCPU int
9+
MemoryInMb int
10+
KernelImage string
11+
KernelAddNetConf bool
12+
KernelFileName string
13+
RootImage string
14+
InitrdImage string
15+
InitrdFilename string
16+
NetworkInterfaces []string
17+
MetadataFromFile []string
18+
Metadata Metadata
19+
AdditionalContainerVolumes []string
20+
AdditionalVirtioFSVolume string
2021
}
2122

2223
type Metadata struct {

0 commit comments

Comments
 (0)