From d26f0ca90f9e6327939d024f632f1511d4d86917 Mon Sep 17 00:00:00 2001 From: Arthur Sengileyev Date: Mon, 8 Jul 2024 18:52:50 +0300 Subject: [PATCH] Implement disable default mounts via command line Signed-off-by: Arthur Sengileyev --- pkg/machine/e2e/basic_test.go | 27 +++++++++++++++++++++++++++ pkg/machine/qemu/stubber.go | 10 +++++++--- pkg/machine/shim/volume.go | 3 +++ 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/pkg/machine/e2e/basic_test.go b/pkg/machine/e2e/basic_test.go index 79d97eaa12..daed59828f 100644 --- a/pkg/machine/e2e/basic_test.go +++ b/pkg/machine/e2e/basic_test.go @@ -117,6 +117,33 @@ var _ = Describe("run basic podman commands", func() { Expect(findmnt.outputToString()).To(ContainSubstring("virtiofs")) }) + It("Volume should be disabled by command line", func() { + skipIfWSL("Requires standard volume handling") + skipIfVmtype(define.AppleHvVirt, "Skipped on Apple platform") + skipIfVmtype(define.LibKrun, "Skipped on Apple platform") + + name := randomString() + i := new(initMachine).withImage(mb.imagePath).withNow() + + // Empty arg forces no volumes + i.withVolume("") + session, err := mb.setName(name).setCmd(i).run() + Expect(err).ToNot(HaveOccurred()) + Expect(session).To(Exit(0)) + + ssh9p := new(sshMachine).withSSHCommand([]string{"findmnt", "-no", "FSTYPE", "-t", "9p"}) + findmnt9p, err := mb.setName(name).setCmd(ssh9p).run() + Expect(err).ToNot(HaveOccurred()) + Expect(findmnt9p).To(Exit(0)) + Expect(findmnt9p.outputToString()).To(BeEmpty()) + + sshVirtiofs := new(sshMachine).withSSHCommand([]string{"findmnt", "-no", "FSTYPE", "-t", "virtiofs"}) + findmntVirtiofs, err := mb.setName(name).setCmd(sshVirtiofs).run() + Expect(err).ToNot(HaveOccurred()) + Expect(findmntVirtiofs).To(Exit(0)) + Expect(findmntVirtiofs.outputToString()).To(BeEmpty()) + }) + It("Podman ops with port forwarding and gvproxy", func() { name := randomString() i := new(initMachine) diff --git a/pkg/machine/qemu/stubber.go b/pkg/machine/qemu/stubber.go index 576d30bbcc..903d56c285 100644 --- a/pkg/machine/qemu/stubber.go +++ b/pkg/machine/qemu/stubber.go @@ -168,9 +168,13 @@ func (q *QEMUStubber) StartVM(mc *vmconfigs.MachineConfig) (func() error, func() if err != nil { return nil, nil, err } - spawner, err := newVirtiofsdSpawner(runtime) - if err != nil { - return nil, nil, err + + var spawner *virtiofsdSpawner + if len(mc.Mounts) > 0 { + spawner, err = newVirtiofsdSpawner(runtime) + if err != nil { + return nil, nil, err + } } for _, hostmnt := range mc.Mounts { diff --git a/pkg/machine/shim/volume.go b/pkg/machine/shim/volume.go index a145f58474..e67e577dbe 100644 --- a/pkg/machine/shim/volume.go +++ b/pkg/machine/shim/volume.go @@ -8,6 +8,9 @@ import ( func CmdLineVolumesToMounts(volumes []string, volumeType vmconfigs.VolumeMountType) []*vmconfigs.Mount { mounts := []*vmconfigs.Mount{} for i, volume := range volumes { + if volume == "" { + continue + } var mount vmconfigs.Mount tag, source, target, readOnly, _ := vmconfigs.SplitVolume(i, volume) switch volumeType {