Skip to content

Don't generate null mounts cloud-config entry #3812

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

Merged
merged 1 commit into from
Aug 11, 2025
Merged
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: 1 addition & 1 deletion pkg/cidata/cidata.TEMPLATE.d/user-data
Original file line number Diff line number Diff line change
Expand Up @@ -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"))) }}
Copy link
Member

Choose a reason for hiding this comment

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

I know this is pre-existing code, but I wonder if the condition should just exclude reverse-sshfs in case we add more mount types in the future:

Suggested change
{{- if or .RosettaEnabled (and .Mounts (or (eq .MountType "9p") (eq .MountType "virtiofs"))) }}
{{- if or .RosettaEnabled (and .Mounts (ne .MountType "reverse-sshfs")) }}

mounts:
{{- if .RosettaEnabled }}{{/* Mount the rosetta volume before systemd-binfmt.service(8) starts */}}
- [vz-rosetta, /mnt/lima-rosetta, virtiofs, defaults, "0", "0"]
Expand Down
46 changes: 46 additions & 0 deletions pkg/cidata/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 [email protected]",
},
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 [email protected]",
},
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",
Expand Down