Skip to content

Commit dbe85a3

Browse files
committed
Change mount mountPoint to string pointer
Signed-off-by: Anders F Björklund <[email protected]>
1 parent 3f414ac commit dbe85a3

File tree

7 files changed

+18
-16
lines changed

7 files changed

+18
-16
lines changed

examples/default.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ mounts:
5858
- location: "~"
5959
# Configure the mountPoint inside the guest.
6060
# 🟢 Builtin default: value of location
61-
mountPoint: ""
61+
mountPoint: null
6262
# CAUTION: `writable` SHOULD be false for the home directory.
6363
# Setting `writable` to true is possible, but untested and dangerous.
6464
# 🟢 Builtin default: false

pkg/cidata/cidata.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ func GenerateISO9660(instDir, name string, y *limayaml.LimaYAML, udpDNSLocalPort
201201
if err != nil {
202202
return err
203203
}
204-
mountPoint, err := localpathutil.Expand(f.MountPoint)
204+
mountPoint, err := localpathutil.Expand(*f.MountPoint)
205205
if err != nil {
206206
return err
207207
}

pkg/hostagent/mount.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func (a *HostAgent) setupMount(m limayaml.Mount) (*mount, error) {
3737
return nil, err
3838
}
3939

40-
mountPoint, err := localpathutil.Expand(m.MountPoint)
40+
mountPoint, err := localpathutil.Expand(*m.MountPoint)
4141
if err != nil {
4242
return nil, err
4343
}

pkg/limayaml/defaults.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -582,10 +582,12 @@ func FillDefault(y, d, o *LimaYAML, filePath string) {
582582
} else {
583583
logrus.WithError(err).Warnf("Couldn't process mount location %q as a template", mount.Location)
584584
}
585-
if out, err := executeGuestTemplate(mount.MountPoint, instDir, y.Param); err == nil {
586-
mount.MountPoint = out.String()
587-
} else {
588-
logrus.WithError(err).Warnf("Couldn't process mount point %q as a template", mount.MountPoint)
585+
if mount.MountPoint != nil {
586+
if out, err := executeGuestTemplate(*mount.MountPoint, instDir, y.Param); err == nil {
587+
mount.MountPoint = ptr.Of(out.String())
588+
} else {
589+
logrus.WithError(err).Warnf("Couldn't process mount point %q as a template", *mount.MountPoint)
590+
}
589591
}
590592
if i, ok := location[mount.Location]; ok {
591593
if mount.SSHFS.Cache != nil {
@@ -615,7 +617,7 @@ func FillDefault(y, d, o *LimaYAML, filePath string) {
615617
if mount.Writable != nil {
616618
mounts[i].Writable = mount.Writable
617619
}
618-
if mount.MountPoint != "" {
620+
if mount.MountPoint != nil {
619621
mounts[i].MountPoint = mount.MountPoint
620622
}
621623
} else {
@@ -658,8 +660,8 @@ func FillDefault(y, d, o *LimaYAML, filePath string) {
658660
mounts[i].NineP.Cache = ptr.Of(Default9pCacheForRO)
659661
}
660662
}
661-
if mount.MountPoint == "" {
662-
mounts[i].MountPoint = mount.Location
663+
if mount.MountPoint == nil {
664+
mounts[i].MountPoint = ptr.Of(mount.Location)
663665
}
664666
}
665667

pkg/limayaml/defaults_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func TestFillDefault(t *testing.T) {
131131
},
132132
Mounts: []Mount{
133133
{Location: "/tmp"},
134-
{Location: "{{.Dir}}/{{.Param.ONE}}", MountPoint: "/mnt/{{.Param.ONE}}"},
134+
{Location: "{{.Dir}}/{{.Param.ONE}}", MountPoint: ptr.Of("/mnt/{{.Param.ONE}}")},
135135
},
136136
MountType: ptr.Of(NINEP),
137137
Provision: []Provision{
@@ -204,7 +204,7 @@ func TestFillDefault(t *testing.T) {
204204
}
205205

206206
expect.Mounts = slices.Clone(y.Mounts)
207-
expect.Mounts[0].MountPoint = expect.Mounts[0].Location
207+
expect.Mounts[0].MountPoint = ptr.Of(expect.Mounts[0].Location)
208208
expect.Mounts[0].Writable = ptr.Of(false)
209209
expect.Mounts[0].SSHFS.Cache = ptr.Of(true)
210210
expect.Mounts[0].SSHFS.FollowSymlinks = ptr.Of(false)
@@ -216,7 +216,7 @@ func TestFillDefault(t *testing.T) {
216216
expect.Mounts[0].Virtiofs.QueueSize = nil
217217
// Only missing Mounts field is Writable, and the default value is also the null value: false
218218
expect.Mounts[1].Location = fmt.Sprintf("%s/%s", instDir, y.Param["ONE"])
219-
expect.Mounts[1].MountPoint = fmt.Sprintf("/mnt/%s", y.Param["ONE"])
219+
expect.Mounts[1].MountPoint = ptr.Of(fmt.Sprintf("/mnt/%s", y.Param["ONE"]))
220220
expect.Mounts[1].Writable = ptr.Of(false)
221221
expect.Mounts[1].SSHFS.Cache = ptr.Of(true)
222222
expect.Mounts[1].SSHFS.FollowSymlinks = ptr.Of(false)
@@ -427,7 +427,7 @@ func TestFillDefault(t *testing.T) {
427427
expect.Containerd.Archives = slices.Clone(d.Containerd.Archives)
428428
expect.Containerd.Archives[0].Arch = *d.Arch
429429
expect.Mounts = slices.Clone(d.Mounts)
430-
expect.Mounts[0].MountPoint = expect.Mounts[0].Location
430+
expect.Mounts[0].MountPoint = ptr.Of(expect.Mounts[0].Location)
431431
expect.Mounts[0].SSHFS.Cache = ptr.Of(true)
432432
expect.Mounts[0].SSHFS.FollowSymlinks = ptr.Of(false)
433433
expect.Mounts[0].SSHFS.SFTPDriver = ptr.Of("")

pkg/limayaml/limayaml.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ type Disk struct {
108108

109109
type Mount struct {
110110
Location string `yaml:"location" json:"location"` // REQUIRED
111-
MountPoint string `yaml:"mountPoint,omitempty" json:"mountPoint,omitempty"`
111+
MountPoint *string `yaml:"mountPoint,omitempty" json:"mountPoint,omitempty" jsonschema:"nullable"`
112112
Writable *bool `yaml:"writable,omitempty" json:"writable,omitempty" jsonschema:"nullable"`
113113
SSHFS SSHFS `yaml:"sshfs,omitempty" json:"sshfs,omitempty"`
114114
NineP NineP `yaml:"9p,omitempty" json:"9p,omitempty"`

pkg/limayaml/validate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ func ValidateParamIsUsed(y *LimaYAML) error {
451451
keyIsUsed = true
452452
break
453453
}
454-
if re.MatchString(p.MountPoint) {
454+
if p.MountPoint != nil && re.MatchString(*p.MountPoint) {
455455
keyIsUsed = true
456456
break
457457
}

0 commit comments

Comments
 (0)