Skip to content

Add {{.Temp}} variable to host templates #3318

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
3 changes: 2 additions & 1 deletion pkg/limayaml/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ func FillDefault(y, d, o *LimaYAML, filePath string, warn bool) {
location := make(map[string]int)
for _, mount := range slices.Concat(d.Mounts, y.Mounts, o.Mounts) {
if out, err := executeHostTemplate(mount.Location, instDir, y.Param); err == nil {
mount.Location = out.String()
mount.Location = filepath.Clean(out.String())
} else {
logrus.WithError(err).Warnf("Couldn't process mount location %q as a template", mount.Location)
}
Expand Down Expand Up @@ -927,6 +927,7 @@ func executeHostTemplate(format, instDir string, param map[string]string) (bytes
"User": currentUser.Username,
"Home": userHomeDir,
"Param": param,
"Temp": os.TempDir(),

"Instance": filepath.Base(instDir), // DEPRECATED, use `{{.Name}}`
"LimaHome": limaHome, // DEPRECATED, use `{{.Dir}}` instead of `{{.LimaHome}}/{{.Instance}}`
Expand Down
13 changes: 7 additions & 6 deletions pkg/limayaml/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"net"
"os"
"path"
"path/filepath"
"runtime"
"slices"
Expand Down Expand Up @@ -146,8 +147,8 @@ func TestFillDefault(t *testing.T) {
},
},
Mounts: []Mount{
{Location: "/tmp"},
{Location: "{{.Dir}}/{{.Param.ONE}}", MountPoint: ptr.Of("/mnt/{{.Param.ONE}}")},
{Location: filepath.Clean(os.TempDir())},
{Location: filepath.Clean("{{.Dir}}/{{.Param.ONE}}"), MountPoint: ptr.Of("/mnt/{{.Param.ONE}}")},
},
MountType: ptr.Of(NINEP),
Provision: []Provision{
Expand Down Expand Up @@ -231,8 +232,8 @@ func TestFillDefault(t *testing.T) {
expect.Mounts[0].NineP.Cache = ptr.Of(Default9pCacheForRO)
expect.Mounts[0].Virtiofs.QueueSize = nil
// Only missing Mounts field is Writable, and the default value is also the null value: false
expect.Mounts[1].Location = fmt.Sprintf("%s/%s", instDir, y.Param["ONE"])
expect.Mounts[1].MountPoint = ptr.Of(fmt.Sprintf("/mnt/%s", y.Param["ONE"]))
expect.Mounts[1].Location = filepath.Join(instDir, y.Param["ONE"])
expect.Mounts[1].MountPoint = ptr.Of(path.Join("/mnt", y.Param["ONE"]))
expect.Mounts[1].Writable = ptr.Of(false)
expect.Mounts[1].SSHFS.Cache = ptr.Of(true)
expect.Mounts[1].SSHFS.FollowSymlinks = ptr.Of(false)
Expand Down Expand Up @@ -385,7 +386,7 @@ func TestFillDefault(t *testing.T) {

Mounts: []Mount{
{
Location: "/var/log",
Location: filepath.Clean("/var/log"),
Writable: ptr.Of(false),
},
},
Expand Down Expand Up @@ -593,7 +594,7 @@ func TestFillDefault(t *testing.T) {

Mounts: []Mount{
{
Location: "/var/log",
Location: filepath.Clean("/var/log"),
Writable: ptr.Of(true),
SSHFS: SSHFS{
Cache: ptr.Of(false),
Expand Down
3 changes: 2 additions & 1 deletion templates/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ mounts:
# See https://www.kernel.org/doc/Documentation/filesystems/9p.txt
# 🟢 Builtin default: "fscache" for non-writable mounts, "mmap" for writable mounts
cache: null
- location: "/tmp/lima"
- location: "{{.Temp}}/lima"
mountPoint: /tmp/lima
# 🟢 Builtin default: false
# 🔵 This file: true (only for "/tmp/lima")
writable: true
Expand Down
Loading