Skip to content

Commit 36fcfde

Browse files
committed
Add "plain" mode (disables mounts, port forwarding, containerd, etc.)
```bash limactl start --plain ``` When the "plain" mode is enabled: - the YAML properties for mounts, port forwarding, containerd, etc. will be ignored - guest agent will not be running - dependency packages like sshfs will not be installed into the VM User-specified provisioning scripts will be still executed. Fixes issue 1739 Signed-off-by: Akihiro Suda <[email protected]>
1 parent 4cda9a0 commit 36fcfde

File tree

15 files changed

+105
-12
lines changed

15 files changed

+105
-12
lines changed

cmd/limactl/editflags/editflags.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ func RegisterCreate(cmd *cobra.Command, commentPrefix string) {
8888
_ = cmd.RegisterFlagCompletionFunc("vm-type", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
8989
return []string{"qemu", "vz"}, cobra.ShellCompDirectiveNoFileComp
9090
})
91+
92+
flags.Bool("plain", false, commentPrefix+"plain mode. Disable mounts, port forwarding, containerd, etc.")
9193
}
9294

9395
func defaultExprFunc(expr string) func(v *flag.Flag) (string, error) {
@@ -225,6 +227,7 @@ func YQExpressions(flags *flag.FlagSet, newInstance bool) ([]string, error) {
225227

226228
{"disk", d(".disk= \"%sGiB\""), true, false},
227229
{"vm-type", d(".vmType = %q"), true, false},
230+
{"plain", d(".plain = %s"), true, false},
228231
}
229232
var exprs []string
230233
for _, def := range defs {

examples/default.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,14 @@ hostResolver:
444444
# 🟢 Builtin default: /usr/local
445445
guestInstallPrefix: null
446446

447+
# When the "plain" mode is enabled:
448+
# - the YAML properties for mounts, port forwarding, containerd, etc. will be ignored
449+
# - guest agent will not be running
450+
# - dependency packages like sshfs will not be installed into the VM
451+
# User-specified provisioning scripts will be still executed.
452+
# 🟢 Builtin default: false
453+
plain: null
454+
447455
# ===================================================================== #
448456
# GLOBAL DEFAULTS AND OVERRIDES
449457
# ===================================================================== #

pkg/cidata/cidata.TEMPLATE.d/boot.sh

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,17 @@ CODE=0
3434
# has run because it might move the directories to /mnt/data on first boot. In that
3535
# case changes made on restart would be lost.
3636

37-
for f in "${LIMA_CIDATA_MNT}"/boot/*; do
38-
INFO "Executing $f"
39-
if ! "$f"; then
40-
WARNING "Failed to execute $f"
41-
CODE=1
42-
fi
43-
done
37+
if [ "$LIMA_CIDATA_PLAIN" = "1" ]; then
38+
INFO "Plain mode. Skipping to run boot scripts. Provisioning scripts will be still executed. Guest agent will not be running."
39+
else
40+
for f in "${LIMA_CIDATA_MNT}"/boot/*; do
41+
INFO "Executing $f"
42+
if ! "$f"; then
43+
WARNING "Failed to execute $f"
44+
CODE=1
45+
fi
46+
done
47+
fi
4448

4549
if [ -d "${LIMA_CIDATA_MNT}"/provision.system ]; then
4650
for f in "${LIMA_CIDATA_MNT}"/provision.system/*; do

pkg/cidata/cidata.TEMPLATE.d/lima.env

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,8 @@ LIMA_CIDATA_SKIP_DEFAULT_DEPENDENCY_RESOLUTION=
4141
{{- end}}
4242
LIMA_CIDATA_VMTYPE={{ .VMType }}
4343
LIMA_CIDATA_VSOCK_PORT={{ .VSockPort }}
44+
{{- if .Plain}}
45+
LIMA_CIDATA_PLAIN=1
46+
{{- else}}
47+
LIMA_CIDATA_PLAIN=
48+
{{- end}}

pkg/cidata/cidata.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ func GenerateISO9660(instDir, name string, y *limayaml.LimaYAML, udpDNSLocalPort
135135
RosettaBinFmt: *y.Rosetta.BinFmt,
136136
VMType: *y.VMType,
137137
VSockPort: vsockPort,
138+
Plain: *y.Plain,
138139
}
139140

140141
firstUsernetIndex := limayaml.FirstUsernetIndex(y)

pkg/cidata/template.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ type TemplateArgs struct {
8181
SkipDefaultDependencyResolution bool
8282
VMType string
8383
VSockPort int
84+
Plain bool
8485
}
8586

8687
func ValidateTemplateArgs(args TemplateArgs) error {

pkg/hostagent/hostagent.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,9 @@ func (a *HostAgent) Info(_ context.Context) (*hostagentapi.Info, error) {
427427
}
428428

429429
func (a *HostAgent) startHostAgentRoutines(ctx context.Context) error {
430+
if *a.y.Plain {
431+
logrus.Info("Running in plain mode. Mounts, port forwarding, containerd, etc. will be ignored. Guest agent will not be running.")
432+
}
430433
a.onClose = append(a.onClose, func() error {
431434
logrus.Debugf("shutting down the SSH master")
432435
if exitMasterErr := ssh.ExitMaster(a.instSSHAddress, a.sshLocalPort, a.sshConfig); exitMasterErr != nil {
@@ -451,7 +454,7 @@ sudo chown -R "${USER}" /run/host-services`
451454
errs = append(errs, fmt.Errorf("stdout=%q, stderr=%q: %w", stdout, stderr, err))
452455
}
453456
}
454-
if *a.y.MountType == limayaml.REVSSHFS {
457+
if *a.y.MountType == limayaml.REVSSHFS && !*a.y.Plain {
455458
mounts, err := a.setupMounts()
456459
if err != nil {
457460
errs = append(errs, err)
@@ -483,7 +486,9 @@ sudo chown -R "${USER}" /run/host-services`
483486
return errors.Join(unlockErrs...)
484487
})
485488
}
486-
go a.watchGuestAgentEvents(ctx)
489+
if !*a.y.Plain {
490+
go a.watchGuestAgentEvents(ctx)
491+
}
487492
if err := a.waitForRequirements("optional", a.optionalRequirements()); err != nil {
488493
errs = append(errs, err)
489494
}

pkg/hostagent/requirements.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ true
7171
Make sure that the YAML field "ssh.localPort" is not used by other processes on the host.
7272
If any private key under ~/.ssh is protected with a passphrase, you need to have ssh-agent to be running.
7373
`,
74-
},
74+
})
75+
if *a.y.Plain {
76+
return req
77+
}
78+
req = append(req,
7579
requirement{
7680
description: "user session is ready for ssh",
7781
script: `#!/bin/bash
@@ -156,7 +160,7 @@ A possible workaround is to run "lima-guestagent install-systemd" in the guest.
156160

157161
func (a *HostAgent) optionalRequirements() []requirement {
158162
req := make([]requirement, 0)
159-
if *a.y.Containerd.System || *a.y.Containerd.User {
163+
if (*a.y.Containerd.System || *a.y.Containerd.User) && !*a.y.Plain {
160164
req = append(req,
161165
requirement{
162166
description: "systemd must be available",

pkg/limayaml/defaults.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,30 @@ func FillDefault(y, d, o *LimaYAML, filePath string) {
665665
if y.Rosetta.BinFmt == nil {
666666
y.Rosetta.BinFmt = pointer.Bool(false)
667667
}
668+
669+
if y.Plain == nil {
670+
y.Plain = d.Plain
671+
}
672+
if o.Plain != nil {
673+
y.Plain = o.Plain
674+
}
675+
if y.Plain == nil {
676+
y.Plain = pointer.Bool(false)
677+
}
678+
679+
fixUpForPlainMode(y)
680+
}
681+
682+
func fixUpForPlainMode(y *LimaYAML) {
683+
if !*y.Plain {
684+
return
685+
}
686+
y.Mounts = nil
687+
y.PortForwards = nil
688+
y.Containerd.System = pointer.Bool(false)
689+
y.Containerd.User = pointer.Bool(false)
690+
y.Rosetta.BinFmt = pointer.Bool(false)
691+
y.Rosetta.Enabled = pointer.Bool(false)
668692
}
669693

670694
func executeGuestTemplate(format string) (bytes.Buffer, error) {

pkg/limayaml/defaults_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ func TestFillDefault(t *testing.T) {
105105
CACertificates: CACertificates{
106106
RemoveDefaults: pointer.Bool(false),
107107
},
108+
Plain: pointer.Bool(false),
108109
}
109110
if IsAccelOS() {
110111
if HasHostCPU() {
@@ -405,6 +406,7 @@ func TestFillDefault(t *testing.T) {
405406
BinFmt: pointer.Bool(true),
406407
}
407408
}
409+
expect.Plain = pointer.Bool(false)
408410

409411
y = LimaYAML{}
410412
FillDefault(&y, &d, &LimaYAML{}, filePath)
@@ -617,6 +619,7 @@ func TestFillDefault(t *testing.T) {
617619
Enabled: pointer.Bool(false),
618620
BinFmt: pointer.Bool(false),
619621
}
622+
expect.Plain = pointer.Bool(false)
620623

621624
FillDefault(&y, &d, &o, filePath)
622625
assert.DeepEqual(t, &y, &expect, opts...)

0 commit comments

Comments
 (0)