Skip to content

Commit

Permalink
Change mount mountPoint to string pointer
Browse files Browse the repository at this point in the history
Signed-off-by: Anders F Björklund <[email protected]>
  • Loading branch information
afbjorklund committed Oct 9, 2024
1 parent 471c80c commit 297d3fd
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pkg/cidata/cidata.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func GenerateISO9660(instDir, name string, instConfig *limayaml.LimaYAML, udpDNS
if err != nil {
return err
}
mountPoint, err := localpathutil.Expand(f.MountPoint)
mountPoint, err := localpathutil.Expand(*f.MountPoint)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/hostagent/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (a *HostAgent) setupMount(m limayaml.Mount) (*mount, error) {
return nil, err
}

mountPoint, err := localpathutil.Expand(m.MountPoint)
mountPoint, err := localpathutil.Expand(*m.MountPoint)
if err != nil {
return nil, err
}
Expand Down
16 changes: 9 additions & 7 deletions pkg/limayaml/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -614,10 +614,12 @@ func FillDefault(y, d, o *LimaYAML, filePath string) {
} else {
logrus.WithError(err).Warnf("Couldn't process mount location %q as a template", mount.Location)
}
if out, err := executeGuestTemplate(mount.MountPoint, instDir, y.Param); err == nil {
mount.MountPoint = out.String()
} else {
logrus.WithError(err).Warnf("Couldn't process mount point %q as a template", mount.MountPoint)
if mount.MountPoint != nil {
if out, err := executeGuestTemplate(*mount.MountPoint, instDir, y.Param); err == nil {
mount.MountPoint = ptr.Of(out.String())
} else {
logrus.WithError(err).Warnf("Couldn't process mount point %q as a template", *mount.MountPoint)
}
}
if i, ok := location[mount.Location]; ok {
if mount.SSHFS.Cache != nil {
Expand Down Expand Up @@ -647,7 +649,7 @@ func FillDefault(y, d, o *LimaYAML, filePath string) {
if mount.Writable != nil {
mounts[i].Writable = mount.Writable
}
if mount.MountPoint != "" {
if mount.MountPoint != nil {
mounts[i].MountPoint = mount.MountPoint
}
} else {
Expand Down Expand Up @@ -690,8 +692,8 @@ func FillDefault(y, d, o *LimaYAML, filePath string) {
mounts[i].NineP.Cache = ptr.Of(Default9pCacheForRO)
}
}
if mount.MountPoint == "" {
mounts[i].MountPoint = mount.Location
if mount.MountPoint == nil {
mounts[i].MountPoint = ptr.Of(mount.Location)
}
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/limayaml/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func TestFillDefault(t *testing.T) {
},
Mounts: []Mount{
{Location: "/tmp"},
{Location: "{{.Dir}}/{{.Param.ONE}}", MountPoint: "/mnt/{{.Param.ONE}}"},
{Location: "{{.Dir}}/{{.Param.ONE}}", MountPoint: ptr.Of("/mnt/{{.Param.ONE}}")},
},
MountType: ptr.Of(NINEP),
Provision: []Provision{
Expand Down Expand Up @@ -204,7 +204,7 @@ func TestFillDefault(t *testing.T) {
}

expect.Mounts = slices.Clone(y.Mounts)
expect.Mounts[0].MountPoint = expect.Mounts[0].Location
expect.Mounts[0].MountPoint = ptr.Of(expect.Mounts[0].Location)
expect.Mounts[0].Writable = ptr.Of(false)
expect.Mounts[0].SSHFS.Cache = ptr.Of(true)
expect.Mounts[0].SSHFS.FollowSymlinks = ptr.Of(false)
Expand All @@ -216,7 +216,7 @@ func TestFillDefault(t *testing.T) {
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 = fmt.Sprintf("/mnt/%s", y.Param["ONE"])
expect.Mounts[1].MountPoint = ptr.Of(fmt.Sprintf("/mnt/%s", 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 @@ -427,7 +427,7 @@ func TestFillDefault(t *testing.T) {
expect.Containerd.Archives = slices.Clone(d.Containerd.Archives)
expect.Containerd.Archives[0].Arch = *d.Arch
expect.Mounts = slices.Clone(d.Mounts)
expect.Mounts[0].MountPoint = expect.Mounts[0].Location
expect.Mounts[0].MountPoint = ptr.Of(expect.Mounts[0].Location)
expect.Mounts[0].SSHFS.Cache = ptr.Of(true)
expect.Mounts[0].SSHFS.FollowSymlinks = ptr.Of(false)
expect.Mounts[0].SSHFS.SFTPDriver = ptr.Of("")
Expand Down
2 changes: 1 addition & 1 deletion pkg/limayaml/limayaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ type Disk struct {

type Mount struct {
Location string `yaml:"location" json:"location"` // REQUIRED
MountPoint string `yaml:"mountPoint,omitempty" json:"mountPoint,omitempty"`
MountPoint *string `yaml:"mountPoint,omitempty" json:"mountPoint,omitempty" jsonschema:"nullable"`
Writable *bool `yaml:"writable,omitempty" json:"writable,omitempty" jsonschema:"nullable"`
SSHFS SSHFS `yaml:"sshfs,omitempty" json:"sshfs,omitempty"`
NineP NineP `yaml:"9p,omitempty" json:"9p,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion pkg/limayaml/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ func ValidateParamIsUsed(y *LimaYAML) error {
keyIsUsed = true
break
}
if re.MatchString(p.MountPoint) {
if p.MountPoint != nil && re.MatchString(*p.MountPoint) {
keyIsUsed = true
break
}
Expand Down

0 comments on commit 297d3fd

Please sign in to comment.