Skip to content

Commit 89857c8

Browse files
committed
Add {{.Temp}} variable to host templates
Allows writing the temp mount as mounts: - location: "{{.Temp}}/lima" mountPoint: /tmp/lima Note that on macOS this would use $TMPDIR and not /tmp, so would be a change in behaviour. It would not affect existing instances though. Signed-off-by: Jan Dubois <[email protected]>
1 parent 88f350b commit 89857c8

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

Diff for: pkg/limayaml/defaults.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ func FillDefault(y, d, o *LimaYAML, filePath string, warn bool) {
703703
location := make(map[string]int)
704704
for _, mount := range slices.Concat(d.Mounts, y.Mounts, o.Mounts) {
705705
if out, err := executeHostTemplate(mount.Location, instDir, y.Param); err == nil {
706-
mount.Location = out.String()
706+
mount.Location = filepath.Clean(out.String())
707707
} else {
708708
logrus.WithError(err).Warnf("Couldn't process mount location %q as a template", mount.Location)
709709
}
@@ -927,6 +927,7 @@ func executeHostTemplate(format, instDir string, param map[string]string) (bytes
927927
"User": currentUser.Username,
928928
"Home": userHomeDir,
929929
"Param": param,
930+
"Temp": os.TempDir(),
930931

931932
"Instance": filepath.Base(instDir), // DEPRECATED, use `{{.Name}}`
932933
"LimaHome": limaHome, // DEPRECATED, use `{{.Dir}}` instead of `{{.LimaHome}}/{{.Instance}}`

Diff for: pkg/limayaml/defaults_test.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"net"
99
"os"
10+
"path"
1011
"path/filepath"
1112
"runtime"
1213
"slices"
@@ -146,8 +147,8 @@ func TestFillDefault(t *testing.T) {
146147
},
147148
},
148149
Mounts: []Mount{
149-
{Location: "/tmp"},
150-
{Location: "{{.Dir}}/{{.Param.ONE}}", MountPoint: ptr.Of("/mnt/{{.Param.ONE}}")},
150+
{Location: os.TempDir()},
151+
{Location: filepath.Clean("{{.Dir}}/{{.Param.ONE}}"), MountPoint: ptr.Of("/mnt/{{.Param.ONE}}")},
151152
},
152153
MountType: ptr.Of(NINEP),
153154
Provision: []Provision{
@@ -231,8 +232,8 @@ func TestFillDefault(t *testing.T) {
231232
expect.Mounts[0].NineP.Cache = ptr.Of(Default9pCacheForRO)
232233
expect.Mounts[0].Virtiofs.QueueSize = nil
233234
// Only missing Mounts field is Writable, and the default value is also the null value: false
234-
expect.Mounts[1].Location = fmt.Sprintf("%s/%s", instDir, y.Param["ONE"])
235-
expect.Mounts[1].MountPoint = ptr.Of(fmt.Sprintf("/mnt/%s", y.Param["ONE"]))
235+
expect.Mounts[1].Location = filepath.Join(instDir, y.Param["ONE"])
236+
expect.Mounts[1].MountPoint = ptr.Of(path.Join("/mnt", y.Param["ONE"]))
236237
expect.Mounts[1].Writable = ptr.Of(false)
237238
expect.Mounts[1].SSHFS.Cache = ptr.Of(true)
238239
expect.Mounts[1].SSHFS.FollowSymlinks = ptr.Of(false)
@@ -385,7 +386,7 @@ func TestFillDefault(t *testing.T) {
385386

386387
Mounts: []Mount{
387388
{
388-
Location: "/var/log",
389+
Location: filepath.Clean("/var/log"),
389390
Writable: ptr.Of(false),
390391
},
391392
},
@@ -593,7 +594,7 @@ func TestFillDefault(t *testing.T) {
593594

594595
Mounts: []Mount{
595596
{
596-
Location: "/var/log",
597+
Location: filepath.Clean("/var/log"),
597598
Writable: ptr.Of(true),
598599
SSHFS: SSHFS{
599600
Cache: ptr.Of(false),

Diff for: templates/default.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ mounts:
9999
# See https://www.kernel.org/doc/Documentation/filesystems/9p.txt
100100
# 🟢 Builtin default: "fscache" for non-writable mounts, "mmap" for writable mounts
101101
cache: null
102-
- location: "/tmp/lima"
102+
- location: "{{.Temp}}/lima"
103+
mountPoint: /tmp/lima
103104
# 🟢 Builtin default: false
104105
# 🔵 This file: true (only for "/tmp/lima")
105106
writable: true

0 commit comments

Comments
 (0)