Skip to content

Commit f76cd2f

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 3fea800 commit f76cd2f

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

pkg/limayaml/defaults.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ func FillDefault(y, d, o *LimaYAML, filePath string, warn bool) {
738738
location := make(map[string]int)
739739
for _, mount := range slices.Concat(d.Mounts, y.Mounts, o.Mounts) {
740740
if out, err := executeHostTemplate(mount.Location, instDir, y.Param); err == nil {
741-
mount.Location = out.String()
741+
mount.Location = filepath.Clean(out.String())
742742
} else {
743743
logrus.WithError(err).Warnf("Couldn't process mount location %q as a template", mount.Location)
744744
}
@@ -963,6 +963,7 @@ func executeHostTemplate(format, instDir string, param map[string]string) (bytes
963963
"User": currentUser.Username,
964964
"Home": userHomeDir,
965965
"Param": param,
966+
"Temp": os.TempDir(),
966967

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

pkg/limayaml/defaults_test.go

Lines changed: 3 additions & 4 deletions
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,10 +147,8 @@ func TestFillDefault(t *testing.T) {
146147
},
147148
},
148149
Mounts: []Mount{
149-
// Location will be passed through localpathutil.Expand() which will normalize the name
150-
// (add a drive letter). So we must start with a valid local path to match it again later.
151150
{Location: filepath.Clean(t.TempDir())},
152-
{Location: "{{.Dir}}/{{.Param.ONE}}", MountPoint: ptr.Of("/mnt/{{.Param.ONE}}")},
151+
{Location: filepath.Clean("{{.Dir}}/{{.Param.ONE}}"), MountPoint: ptr.Of("/mnt/{{.Param.ONE}}")},
153152
},
154153
MountType: ptr.Of(NINEP),
155154
Provision: []Provision{
@@ -240,7 +239,7 @@ func TestFillDefault(t *testing.T) {
240239
expect.Mounts[0].Virtiofs.QueueSize = nil
241240
// Only missing Mounts field is Writable, and the default value is also the null value: false
242241
expect.Mounts[1].Location = filepath.Join(instDir, y.Param["ONE"])
243-
expect.Mounts[1].MountPoint = ptr.Of(fmt.Sprintf("/mnt/%s", y.Param["ONE"]))
242+
expect.Mounts[1].MountPoint = ptr.Of(path.Join("/mnt", y.Param["ONE"]))
244243
expect.Mounts[1].Writable = ptr.Of(false)
245244
expect.Mounts[1].SSHFS.Cache = ptr.Of(true)
246245
expect.Mounts[1].SSHFS.FollowSymlinks = ptr.Of(false)

templates/_default/mounts.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
mounts:
22
- location: "~"
3-
- location: "/tmp/lima"
3+
4+
- location: "{{.Temp}}/lima"
5+
mountPoint: /tmp/lima
46
writable: true

0 commit comments

Comments
 (0)