diff --git a/pkg/limayaml/defaults.go b/pkg/limayaml/defaults.go index cc97b73f0e2..b1d044993e9 100644 --- a/pkg/limayaml/defaults.go +++ b/pkg/limayaml/defaults.go @@ -88,6 +88,19 @@ func defaultContainerdArchives() []File { return containerd.Archives } +func defaultMounts() []Mount { + return []Mount{ + { + Location: "~", + Writable: ptr.Of(false), + }, + { + Location: "/tmp/lima", + Writable: ptr.Of(true), + }, + } +} + // FirstUsernetIndex gets the index of first usernet network under l.Network[]. Returns -1 if no usernet network found. func FirstUsernetIndex(l *LimaYAML) int { return slices.IndexFunc(l.Networks, func(network Network) bool { return networks.IsUsernet(network.Lima) }) @@ -647,6 +660,16 @@ func FillDefault(y, d, o *LimaYAML, filePath string) { } y.Mounts = mounts + mounts = []Mount{} + for _, mount := range y.Mounts { + if mount.Name == "default" { + mounts = append(mounts, defaultMounts()...) + continue + } + mounts = append(mounts, mount) + } + y.Mounts = mounts + for i := range y.Mounts { mount := &y.Mounts[i] if mount.SSHFS.Cache == nil { diff --git a/pkg/limayaml/limayaml.go b/pkg/limayaml/limayaml.go index c4d19fc9933..5fa138fb72d 100644 --- a/pkg/limayaml/limayaml.go +++ b/pkg/limayaml/limayaml.go @@ -122,6 +122,7 @@ type Disk struct { } type Mount struct { + Name string `yaml:"name,omitempty" json:"name,omitempty"` Location string `yaml:"location" json:"location"` // REQUIRED MountPoint string `yaml:"mountPoint,omitempty" json:"mountPoint,omitempty"` Writable *bool `yaml:"writable,omitempty" json:"writable,omitempty"` diff --git a/pkg/limayaml/load.go b/pkg/limayaml/load.go index 187b3c30772..e300dff1a0d 100644 --- a/pkg/limayaml/load.go +++ b/pkg/limayaml/load.go @@ -13,6 +13,15 @@ import ( "github.com/sirupsen/logrus" ) +func unmarshalMount(dst *Mount, b []byte) error { + var s string + if err := yaml.Unmarshal(b, &s); err == nil { + *dst = Mount{Name: s} + return nil + } + return yaml.Unmarshal(b, dst) +} + func unmarshalDisk(dst *Disk, b []byte) error { var s string if err := yaml.Unmarshal(b, &s); err == nil { @@ -32,6 +41,7 @@ func unmarshalImage(dst *Image, b []byte) error { } var customMarshalers = []yaml.DecodeOption{ + yaml.CustomUnmarshaler[Mount](unmarshalMount), yaml.CustomUnmarshaler[Disk](unmarshalDisk), yaml.CustomUnmarshaler[Image](unmarshalImage), } diff --git a/pkg/limayaml/validate.go b/pkg/limayaml/validate.go index f8516e7b9f9..709e19b8645 100644 --- a/pkg/limayaml/validate.go +++ b/pkg/limayaml/validate.go @@ -153,6 +153,13 @@ func Validate(y *LimaYAML, warn bool) error { reservedHome := fmt.Sprintf("/home/%s.linux", u.Username) for i, f := range y.Mounts { + if f.Name != "" { + if f.Name != "default" { + return fmt.Errorf("field `mounts[%d].name` refers to an unknown name: %q", + i, f.Name) + } + continue + } if !filepath.IsAbs(f.Location) && !strings.HasPrefix(f.Location, "~") { return fmt.Errorf("field `mounts[%d].location` must be an absolute path, got %q", i, f.Location)