Skip to content

Commit 221218d

Browse files
committed
Add feature to keep mounts with plain mode
Allows using e.g. virtiofs, without needing the guestagent. But only for default mounts, reverse-sshfs still needs it. Signed-off-by: Anders F Björklund <[email protected]>
1 parent d4056f9 commit 221218d

File tree

7 files changed

+32
-2
lines changed

7 files changed

+32
-2
lines changed

cmd/limactl/editflags/editflags.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ func RegisterCreate(cmd *cobra.Command, commentPrefix string) {
9292
})
9393

9494
flags.Bool("plain", false, commentPrefix+"Plain mode. Disables mounts, port forwarding, containerd, etc.")
95+
flags.Bool("plain-mounts", false, commentPrefix+"Keep any mounts, of the default type, in plain mode.")
9596
}
9697

9798
func defaultExprFunc(expr string) func(v *flag.Flag) (string, error) {
@@ -257,6 +258,7 @@ func YQExpressions(flags *flag.FlagSet, newInstance bool) ([]string, error) {
257258
{"disk", d(".disk= \"%sGiB\""), false, false},
258259
{"vm-type", d(".vmType = %q"), true, false},
259260
{"plain", d(".plain = %s"), true, false},
261+
{"plain-mounts", d(".plainMounts = %s"), true, false},
260262
}
261263
var exprs []string
262264
for _, def := range defs {

pkg/hostagent/hostagent.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,11 @@ func (a *HostAgent) Info(_ context.Context) (*hostagentapi.Info, error) {
420420

421421
func (a *HostAgent) startHostAgentRoutines(ctx context.Context) error {
422422
if *a.instConfig.Plain {
423-
logrus.Info("Running in plain mode. Mounts, port forwarding, containerd, etc. will be ignored. Guest agent will not be running.")
423+
if *a.instConfig.PlainMounts {
424+
logrus.Info("Running in plain mode, with mounts. Port forwarding, containerd, etc. will be ignored. Guest agent will not be running.")
425+
} else {
426+
logrus.Info("Running in plain mode. Mounts, port forwarding, containerd, etc. will be ignored. Guest agent will not be running.")
427+
}
424428
}
425429
a.onClose = append(a.onClose, func() error {
426430
logrus.Debugf("shutting down the SSH master")

pkg/limayaml/defaults.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -908,14 +908,26 @@ func FillDefault(y, d, o *LimaYAML, filePath string, warn bool) {
908908
y.Plain = ptr.Of(false)
909909
}
910910

911+
if y.PlainMounts == nil {
912+
y.PlainMounts = d.PlainMounts
913+
}
914+
if o.PlainMounts != nil {
915+
y.PlainMounts = o.PlainMounts
916+
}
917+
if y.PlainMounts == nil {
918+
y.PlainMounts = ptr.Of(false)
919+
}
920+
911921
fixUpForPlainMode(y)
912922
}
913923

914924
func fixUpForPlainMode(y *LimaYAML) {
915925
if !*y.Plain {
916926
return
917927
}
918-
y.Mounts = nil
928+
if !*y.PlainMounts {
929+
y.Mounts = nil
930+
}
919931
y.PortForwards = nil
920932
y.Containerd.System = ptr.Of(false)
921933
y.Containerd.User = ptr.Of(false)

pkg/limayaml/defaults_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ func TestFillDefault(t *testing.T) {
120120
},
121121
NestedVirtualization: ptr.Of(false),
122122
Plain: ptr.Of(false),
123+
PlainMounts: ptr.Of(false),
123124
User: User{
124125
Name: ptr.Of(user.Username),
125126
Comment: ptr.Of(user.Name),
@@ -508,6 +509,7 @@ func TestFillDefault(t *testing.T) {
508509
}
509510
}
510511
expect.Plain = ptr.Of(false)
512+
expect.PlainMounts = ptr.Of(false)
511513

512514
y = LimaYAML{}
513515
FillDefault(&y, &d, &LimaYAML{}, filePath, false)
@@ -751,6 +753,7 @@ func TestFillDefault(t *testing.T) {
751753
BinFmt: ptr.Of(false),
752754
}
753755
expect.Plain = ptr.Of(false)
756+
expect.PlainMounts = ptr.Of(false)
754757

755758
expect.NestedVirtualization = ptr.Of(false)
756759

pkg/limayaml/limayaml.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ type LimaYAML struct {
4949
CACertificates CACertificates `yaml:"caCerts,omitempty" json:"caCerts,omitempty"`
5050
Rosetta Rosetta `yaml:"rosetta,omitempty" json:"rosetta,omitempty"`
5151
Plain *bool `yaml:"plain,omitempty" json:"plain,omitempty" jsonschema:"nullable"`
52+
PlainMounts *bool `yaml:"plainMounts,omitempty" json:"plainMounts,omitempty" jsonschema:"nullable"`
5253
TimeZone *string `yaml:"timezone,omitempty" json:"timezone,omitempty" jsonschema:"nullable"`
5354
NestedVirtualization *bool `yaml:"nestedVirtualization,omitempty" json:"nestedVirtualization,omitempty" jsonschema:"nullable"`
5455
User User `yaml:"user,omitempty" json:"user,omitempty"`

pkg/limayaml/validate.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ func Validate(y *LimaYAML, warn bool) error {
181181
errs = errors.Join(errs, fmt.Errorf("field `mountType` must not be one of %v (`mountTypesUnsupported`), got %q", y.MountTypesUnsupported, *y.MountType))
182182
}
183183

184+
if *y.Plain && *y.PlainMounts && *y.MountType == REVSSHFS {
185+
errs = errors.Join(errs, fmt.Errorf("field `mountType` must not be %v in plain mode", *y.MountType))
186+
}
187+
184188
if warn && runtime.GOOS != "linux" {
185189
for i, mount := range y.Mounts {
186190
if mount.Virtiofs.QueueSize != nil {

templates/default.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,10 @@ guestInstallPrefix: null
555555
# 🟢 Builtin default: false
556556
plain: null
557557

558+
# Keep the mounts, in "plain" mode.
559+
# 🟢 Builtin default: false
560+
plainMounts: null
561+
558562
# When the "nestedVirtualization" feature is enabled:
559563
# - Allows running a VM inside the guest VM.
560564
# - The guest VM must configure QEMU with the `-cpu host` parameters to run a nested VM:

0 commit comments

Comments
 (0)