Skip to content

Commit f61ab4d

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

File tree

7 files changed

+18
-16
lines changed

7 files changed

+18
-16
lines changed

examples/default.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ mounts:
7070
- location: "~"
7171
# Configure the mountPoint inside the guest.
7272
# 🟢 Builtin default: value of location
73-
mountPoint: ""
73+
mountPoint: null
7474
# CAUTION: `writable` SHOULD be false for the home directory.
7575
# Setting `writable` to true is possible, but untested and dangerous.
7676
# 🟢 Builtin default: false

pkg/cidata/cidata.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ func GenerateISO9660(instDir, name string, instConfig *limayaml.LimaYAML, udpDNS
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

+1-1
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

+9-7
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

+4-4
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ type Disk struct {
118118

119119
type Mount struct {
120120
Location string `yaml:"location" json:"location"` // REQUIRED
121-
MountPoint string `yaml:"mountPoint,omitempty" json:"mountPoint,omitempty"`
121+
MountPoint *string `yaml:"mountPoint,omitempty" json:"mountPoint,omitempty" jsonschema:"nullable"`
122122
Writable *bool `yaml:"writable,omitempty" json:"writable,omitempty" jsonschema:"nullable"`
123123
SSHFS SSHFS `yaml:"sshfs,omitempty" json:"sshfs,omitempty"`
124124
NineP NineP `yaml:"9p,omitempty" json:"9p,omitempty"`

pkg/limayaml/validate.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ func ValidateParamIsUsed(y *LimaYAML) error {
481481
keyIsUsed = true
482482
break
483483
}
484-
if re.MatchString(p.MountPoint) {
484+
if p.MountPoint != nil && re.MatchString(*p.MountPoint) {
485485
keyIsUsed = true
486486
break
487487
}

0 commit comments

Comments
 (0)