Skip to content

Commit b204276

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

File tree

6 files changed

+17
-15
lines changed

6 files changed

+17
-15
lines changed

pkg/cidata/cidata.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ func templateArgs(bootScripts bool, instDir, name string, instConfig *limayaml.L
202202
if err != nil {
203203
return nil, err
204204
}
205-
mountPoint, err := localpathutil.Expand(f.MountPoint)
205+
mountPoint, err := localpathutil.Expand(*f.MountPoint)
206206
if err != nil {
207207
return nil, err
208208
}

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
@@ -619,10 +619,12 @@ func FillDefault(y, d, o *LimaYAML, filePath string) {
619619
} else {
620620
logrus.WithError(err).Warnf("Couldn't process mount location %q as a template", mount.Location)
621621
}
622-
if out, err := executeGuestTemplate(mount.MountPoint, instDir, y.Param); err == nil {
623-
mount.MountPoint = out.String()
624-
} else {
625-
logrus.WithError(err).Warnf("Couldn't process mount point %q as a template", mount.MountPoint)
622+
if mount.MountPoint != nil {
623+
if out, err := executeGuestTemplate(*mount.MountPoint, instDir, y.Param); err == nil {
624+
mount.MountPoint = ptr.Of(out.String())
625+
} else {
626+
logrus.WithError(err).Warnf("Couldn't process mount point %q as a template", *mount.MountPoint)
627+
}
626628
}
627629
if i, ok := location[mount.Location]; ok {
628630
if mount.SSHFS.Cache != nil {
@@ -652,7 +654,7 @@ func FillDefault(y, d, o *LimaYAML, filePath string) {
652654
if mount.Writable != nil {
653655
mounts[i].Writable = mount.Writable
654656
}
655-
if mount.MountPoint != "" {
657+
if mount.MountPoint != nil {
656658
mounts[i].MountPoint = mount.MountPoint
657659
}
658660
} else {
@@ -695,8 +697,8 @@ func FillDefault(y, d, o *LimaYAML, filePath string) {
695697
mounts[i].NineP.Cache = ptr.Of(Default9pCacheForRO)
696698
}
697699
}
698-
if mount.MountPoint == "" {
699-
mounts[i].MountPoint = mount.Location
700+
if mount.MountPoint == nil {
701+
mounts[i].MountPoint = ptr.Of(mount.Location)
700702
}
701703
}
702704

pkg/limayaml/defaults_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func TestFillDefault(t *testing.T) {
132132
},
133133
Mounts: []Mount{
134134
{Location: "/tmp"},
135-
{Location: "{{.Dir}}/{{.Param.ONE}}", MountPoint: "/mnt/{{.Param.ONE}}"},
135+
{Location: "{{.Dir}}/{{.Param.ONE}}", MountPoint: ptr.Of("/mnt/{{.Param.ONE}}")},
136136
},
137137
MountType: ptr.Of(NINEP),
138138
Provision: []Provision{
@@ -205,7 +205,7 @@ func TestFillDefault(t *testing.T) {
205205
}
206206

207207
expect.Mounts = slices.Clone(y.Mounts)
208-
expect.Mounts[0].MountPoint = expect.Mounts[0].Location
208+
expect.Mounts[0].MountPoint = ptr.Of(expect.Mounts[0].Location)
209209
expect.Mounts[0].Writable = ptr.Of(false)
210210
expect.Mounts[0].SSHFS.Cache = ptr.Of(true)
211211
expect.Mounts[0].SSHFS.FollowSymlinks = ptr.Of(false)
@@ -217,7 +217,7 @@ func TestFillDefault(t *testing.T) {
217217
expect.Mounts[0].Virtiofs.QueueSize = nil
218218
// Only missing Mounts field is Writable, and the default value is also the null value: false
219219
expect.Mounts[1].Location = fmt.Sprintf("%s/%s", instDir, y.Param["ONE"])
220-
expect.Mounts[1].MountPoint = fmt.Sprintf("/mnt/%s", y.Param["ONE"])
220+
expect.Mounts[1].MountPoint = ptr.Of(fmt.Sprintf("/mnt/%s", y.Param["ONE"]))
221221
expect.Mounts[1].Writable = ptr.Of(false)
222222
expect.Mounts[1].SSHFS.Cache = ptr.Of(true)
223223
expect.Mounts[1].SSHFS.FollowSymlinks = ptr.Of(false)
@@ -431,7 +431,7 @@ func TestFillDefault(t *testing.T) {
431431
expect.Containerd.Archives = slices.Clone(d.Containerd.Archives)
432432
expect.Containerd.Archives[0].Arch = *d.Arch
433433
expect.Mounts = slices.Clone(d.Mounts)
434-
expect.Mounts[0].MountPoint = expect.Mounts[0].Location
434+
expect.Mounts[0].MountPoint = ptr.Of(expect.Mounts[0].Location)
435435
expect.Mounts[0].SSHFS.Cache = ptr.Of(true)
436436
expect.Mounts[0].SSHFS.FollowSymlinks = ptr.Of(false)
437437
expect.Mounts[0].SSHFS.SFTPDriver = ptr.Of("")

pkg/limayaml/limayaml.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ type Disk struct {
120120

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

pkg/limayaml/validate.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ func ValidateParamIsUsed(y *LimaYAML) error {
487487
keyIsUsed = true
488488
break
489489
}
490-
if re.MatchString(p.MountPoint) {
490+
if p.MountPoint != nil && re.MatchString(*p.MountPoint) {
491491
keyIsUsed = true
492492
break
493493
}

0 commit comments

Comments
 (0)