diff --git a/pkg/cidata/cidata.TEMPLATE.d/user-data b/pkg/cidata/cidata.TEMPLATE.d/user-data index 3842f8d46e9..e2e13045396 100644 --- a/pkg/cidata/cidata.TEMPLATE.d/user-data +++ b/pkg/cidata/cidata.TEMPLATE.d/user-data @@ -11,7 +11,7 @@ package_upgrade: true package_reboot_if_required: true {{- end }} -{{- if or .RosettaEnabled (or (eq .MountType "9p") (eq .MountType "virtiofs")) }} +{{- if or .RosettaEnabled (and .Mounts (or (eq .MountType "9p") (eq .MountType "virtiofs"))) }} mounts: {{- if .RosettaEnabled }}{{/* Mount the rosetta volume before systemd-binfmt.service(8) starts */}} - [vz-rosetta, /mnt/lima-rosetta, virtiofs, defaults, "0", "0"] diff --git a/pkg/cidata/template_test.go b/pkg/cidata/template_test.go index 31f7b2df77d..fc2482b91f9 100644 --- a/pkg/cidata/template_test.go +++ b/pkg/cidata/template_test.go @@ -30,6 +30,7 @@ func TestConfig(t *testing.T) { assert.NilError(t, err) t.Log(string(config)) assert.Assert(t, !strings.Contains(string(config), "ca_certs:")) + assert.Assert(t, !strings.Contains(string(config), "mounts:")) } func TestConfigCACerts(t *testing.T) { @@ -54,6 +55,51 @@ func TestConfigCACerts(t *testing.T) { assert.Assert(t, strings.Contains(string(config), "ca_certs:")) } +var defaultMounts = []Mount{ + {MountPoint: "/home/foo.linux", Tag: "mount0", Type: "virtiofs", Options: "ro"}, + {MountPoint: "/tmp/lima", Tag: "mount1", Type: "virtiofs"}, +} + +func TestConfigMounts(t *testing.T) { + args := &TemplateArgs{ + Name: "default", + User: "foo", + UID: 501, + Comment: "Foo", + Home: "/home/foo.linux", + Shell: "/bin/bash", + SSHPubKeys: []string{ + "ssh-rsa dummy foo@example.com", + }, + MountType: "virtiofs", // override + Mounts: defaultMounts, + } + config, err := ExecuteTemplateCloudConfig(args) + assert.NilError(t, err) + t.Log(string(config)) + assert.Assert(t, strings.Contains(string(config), "mounts:")) +} + +func TestConfigMountsNone(t *testing.T) { + args := &TemplateArgs{ + Name: "default", + User: "foo", + UID: 501, + Comment: "Foo", + Home: "/home/foo.linux", + Shell: "/bin/bash", + SSHPubKeys: []string{ + "ssh-rsa dummy foo@example.com", + }, + MountType: "virtiofs", // override + Mounts: []Mount{}, + } + config, err := ExecuteTemplateCloudConfig(args) + assert.NilError(t, err) + t.Log(string(config)) + assert.Assert(t, !strings.Contains(string(config), "mounts:")) +} + func TestTemplate(t *testing.T) { args := &TemplateArgs{ Name: "default",