Skip to content

Commit 3c5534f

Browse files
committed
Don't generate null mounts cloud-config entry
Signed-off-by: Anders F Björklund <[email protected]>
1 parent 02c4637 commit 3c5534f

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

pkg/cidata/cidata.TEMPLATE.d/user-data

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ package_upgrade: true
1111
package_reboot_if_required: true
1212
{{- end }}
1313

14-
{{- if or .RosettaEnabled (or (eq .MountType "9p") (eq .MountType "virtiofs")) }}
14+
{{- if or .RosettaEnabled (and .Mounts (or (eq .MountType "9p") (eq .MountType "virtiofs"))) }}
1515
mounts:
1616
{{- if .RosettaEnabled }}{{/* Mount the rosetta volume before systemd-binfmt.service(8) starts */}}
1717
- [vz-rosetta, /mnt/lima-rosetta, virtiofs, defaults, "0", "0"]

pkg/cidata/template_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ func TestConfig(t *testing.T) {
3030
assert.NilError(t, err)
3131
t.Log(string(config))
3232
assert.Assert(t, !strings.Contains(string(config), "ca_certs:"))
33+
assert.Assert(t, !strings.Contains(string(config), "mounts:"))
3334
}
3435

3536
func TestConfigCACerts(t *testing.T) {
@@ -54,6 +55,51 @@ func TestConfigCACerts(t *testing.T) {
5455
assert.Assert(t, strings.Contains(string(config), "ca_certs:"))
5556
}
5657

58+
var defaultMounts = []Mount{
59+
{MountPoint: "/home/foo.linux", Tag: "mount0", Type: "virtiofs", Options: "ro"},
60+
{MountPoint: "/tmp/lima", Tag: "mount1", Type: "virtiofs"},
61+
}
62+
63+
func TestConfigMounts(t *testing.T) {
64+
args := &TemplateArgs{
65+
Name: "default",
66+
User: "foo",
67+
UID: 501,
68+
Comment: "Foo",
69+
Home: "/home/foo.linux",
70+
Shell: "/bin/bash",
71+
SSHPubKeys: []string{
72+
"ssh-rsa dummy [email protected]",
73+
},
74+
MountType: "virtiofs", // override
75+
Mounts: defaultMounts,
76+
}
77+
config, err := ExecuteTemplateCloudConfig(args)
78+
assert.NilError(t, err)
79+
t.Log(string(config))
80+
assert.Assert(t, strings.Contains(string(config), "mounts:"))
81+
}
82+
83+
func TestConfigMountsNone(t *testing.T) {
84+
args := &TemplateArgs{
85+
Name: "default",
86+
User: "foo",
87+
UID: 501,
88+
Comment: "Foo",
89+
Home: "/home/foo.linux",
90+
Shell: "/bin/bash",
91+
SSHPubKeys: []string{
92+
"ssh-rsa dummy [email protected]",
93+
},
94+
MountType: "virtiofs", // override
95+
Mounts: []Mount{},
96+
}
97+
config, err := ExecuteTemplateCloudConfig(args)
98+
assert.NilError(t, err)
99+
t.Log(string(config))
100+
assert.Assert(t, !strings.Contains(string(config), "mounts:"))
101+
}
102+
57103
func TestTemplate(t *testing.T) {
58104
args := &TemplateArgs{
59105
Name: "default",

0 commit comments

Comments
 (0)