Skip to content

Add feature to keep mounts with plain mode #3748

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/limactl/editflags/editflags.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func RegisterCreate(cmd *cobra.Command, commentPrefix string) {
})

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

func defaultExprFunc(expr string) func(v *flag.Flag) (string, error) {
Expand Down Expand Up @@ -257,6 +258,7 @@ func YQExpressions(flags *flag.FlagSet, newInstance bool) ([]string, error) {
{"disk", d(".disk= \"%sGiB\""), false, false},
{"vm-type", d(".vmType = %q"), true, false},
{"plain", d(".plain = %s"), true, false},
{"plain-mounts", d(".plainMounts = %s"), true, false},
}
var exprs []string
for _, def := range defs {
Expand Down
6 changes: 5 additions & 1 deletion pkg/hostagent/hostagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,11 @@ func (a *HostAgent) Info(_ context.Context) (*hostagentapi.Info, error) {

func (a *HostAgent) startHostAgentRoutines(ctx context.Context) error {
if *a.instConfig.Plain {
logrus.Info("Running in plain mode. Mounts, port forwarding, containerd, etc. will be ignored. Guest agent will not be running.")
if *a.instConfig.PlainMounts {
logrus.Info("Running in plain mode, with mounts. Port forwarding, containerd, etc. will be ignored. Guest agent will not be running.")
} else {
logrus.Info("Running in plain mode. Mounts, port forwarding, containerd, etc. will be ignored. Guest agent will not be running.")
}
}
a.onClose = append(a.onClose, func() error {
logrus.Debugf("shutting down the SSH master")
Expand Down
14 changes: 13 additions & 1 deletion pkg/limayaml/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -908,14 +908,26 @@ func FillDefault(y, d, o *LimaYAML, filePath string, warn bool) {
y.Plain = ptr.Of(false)
}

if y.PlainMounts == nil {
y.PlainMounts = d.PlainMounts
}
if o.PlainMounts != nil {
y.PlainMounts = o.PlainMounts
}
if y.PlainMounts == nil {
y.PlainMounts = ptr.Of(false)
}

fixUpForPlainMode(y)
}

func fixUpForPlainMode(y *LimaYAML) {
if !*y.Plain {
return
}
y.Mounts = nil
if !*y.PlainMounts {
y.Mounts = nil
}
y.PortForwards = nil
y.Containerd.System = ptr.Of(false)
y.Containerd.User = ptr.Of(false)
Expand Down
3 changes: 3 additions & 0 deletions pkg/limayaml/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ func TestFillDefault(t *testing.T) {
},
NestedVirtualization: ptr.Of(false),
Plain: ptr.Of(false),
PlainMounts: ptr.Of(false),
User: User{
Name: ptr.Of(user.Username),
Comment: ptr.Of(user.Name),
Expand Down Expand Up @@ -508,6 +509,7 @@ func TestFillDefault(t *testing.T) {
}
}
expect.Plain = ptr.Of(false)
expect.PlainMounts = ptr.Of(false)

y = LimaYAML{}
FillDefault(&y, &d, &LimaYAML{}, filePath, false)
Expand Down Expand Up @@ -751,6 +753,7 @@ func TestFillDefault(t *testing.T) {
BinFmt: ptr.Of(false),
}
expect.Plain = ptr.Of(false)
expect.PlainMounts = ptr.Of(false)

expect.NestedVirtualization = ptr.Of(false)

Expand Down
1 change: 1 addition & 0 deletions pkg/limayaml/limayaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type LimaYAML struct {
CACertificates CACertificates `yaml:"caCerts,omitempty" json:"caCerts,omitempty"`
Rosetta Rosetta `yaml:"rosetta,omitempty" json:"rosetta,omitempty"`
Plain *bool `yaml:"plain,omitempty" json:"plain,omitempty" jsonschema:"nullable"`
PlainMounts *bool `yaml:"plainMounts,omitempty" json:"plainMounts,omitempty" jsonschema:"nullable"`
TimeZone *string `yaml:"timezone,omitempty" json:"timezone,omitempty" jsonschema:"nullable"`
NestedVirtualization *bool `yaml:"nestedVirtualization,omitempty" json:"nestedVirtualization,omitempty" jsonschema:"nullable"`
User User `yaml:"user,omitempty" json:"user,omitempty"`
Expand Down
4 changes: 4 additions & 0 deletions pkg/limayaml/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ func Validate(y *LimaYAML, warn bool) error {
errs = errors.Join(errs, fmt.Errorf("field `mountType` must not be one of %v (`mountTypesUnsupported`), got %q", y.MountTypesUnsupported, *y.MountType))
}

if *y.Plain && *y.PlainMounts && *y.MountType == REVSSHFS {
errs = errors.Join(errs, fmt.Errorf("field `mountType` must not be %v in plain mode", *y.MountType))
}

if warn && runtime.GOOS != "linux" {
for i, mount := range y.Mounts {
if mount.Virtiofs.QueueSize != nil {
Expand Down
4 changes: 4 additions & 0 deletions templates/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,10 @@ guestInstallPrefix: null
# 🟢 Builtin default: false
plain: null

# Keep the mounts, in "plain" mode.
# 🟢 Builtin default: false
plainMounts: null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fear the explosion of plainFoo, plainBar, plainFooBar properties.

Can we rather introduce guestAgent.enabled: false that will just disable the guest agent without affecting mounts

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ask was only to be able to do virtiofs mounts with vz, without the guestagent (which is doable with this)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But currently this is not related to the guestagent at all, just that enabling Plain will wipe out the Mounts


# When the "nestedVirtualization" feature is enabled:
# - Allows running a VM inside the guest VM.
# - The guest VM must configure QEMU with the `-cpu host` parameters to run a nested VM:
Expand Down
Loading