Skip to content

Commit bfa59fe

Browse files
authored
chapi: add nfs mount endpoint (#117)
* chapi: add nfs mount endpoint * Problem: * need capability in chapi to perform nfs mounts * Implementation: * add endpoint which performs just mount without device checking. * Testing: tested with nfs volumes using csi driver. * Review: gcostea, rkumar Signed-off-by: Shiva Krishna, Merla <[email protected]> * Update endpoint for darwin flavor as well to avoid linter errors Signed-off-by: Shiva Krishna, Merla <[email protected]>
1 parent 98ce168 commit bfa59fe

File tree

5 files changed

+50
-4
lines changed

5 files changed

+50
-4
lines changed

chapi/chapidriver.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type Driver interface {
1818
DeleteDevice(device *model.Device) error
1919
OfflineDevice(device *model.Device) error
2020
MountDevice(device *model.Device, mountPoint string, mountOptions []string, fsOpts *model.FilesystemOpts) (*model.Mount, error) // Idempotent
21+
MountNFSVolume(source string, target string, mountOptions []string) error // Idempotent
2122
BindMount(mountPoint string, newMountPoint string, rbind bool) error // Idempotent
2223
BindUnmount(mountPoint string) error // Idempotent
2324
UnmountDevice(device *model.Device, mountPoint string) (*model.Mount, error) // Idempotent

chapi/chapidriver_darwin.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func (driver *MacDriver) GetMountOptions(device *model.Device, mountPoint string
3333
}
3434

3535
// GetHostNetworks reports the networks on this host
36-
func (driver *MacDriver) GetHostNetworks() ([]*model.Network, error) {
36+
func (driver *MacDriver) GetHostNetworks() ([]*model.NetworkInterface, error) {
3737
return nil, fmt.Errorf("not implemented")
3838
}
3939

@@ -131,3 +131,8 @@ func (driver *MacDriver) BindUnmount(mountPoint string) error {
131131
func (driver *MacDriver) ExpandDevice(targetPath string, volAccessType model.VolumeAccessType) error {
132132
return fmt.Errorf("not implemented")
133133
}
134+
135+
// MountNFSVolume mounts NFS share onto given target path
136+
func (driver *MacDriver) MountNFSVolume(source string, targetPath string, mountOptions []string) error {
137+
return nil
138+
}

chapi/chapidriver_fake.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,8 @@ func (driver *FakeDriver) OfflineDevice(device *model.Device) error {
154154
func (driver *FakeDriver) ExpandDevice(targetPath string, volAccessType model.VolumeAccessType) error {
155155
return nil
156156
}
157+
158+
// MountNFSVolume mounts NFS share onto given target path
159+
func (driver *FakeDriver) MountNFSVolume(source string, targetPath string, mountOptions []string) error {
160+
return nil
161+
}

chapi/chapidriver_linux.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,17 @@ func (driver *LinuxDriver) GetMountsForDevice(device *model.Device) ([]*model.Mo
235235
return linux.GetMountPointsForDevices(devices)
236236
}
237237

238+
func (driver *LinuxDriver) MountNFSVolume(source string, targetPath string, mountOptions []string) error {
239+
log.Tracef(">>>>> MountNFSVolume called with source %s target %s options %v: ", source, targetPath, mountOptions)
240+
defer log.Trace("<<<<< MountNFSVolume")
241+
242+
err := linux.MountNFSShare(source, targetPath, mountOptions)
243+
if err != nil {
244+
return fmt.Errorf("Error mounting nfs share %s at %s, err %s", source, targetPath, err.Error())
245+
}
246+
return nil
247+
}
248+
238249
// MountDevice mounts the given device to the given mount point. This must be idempotent.
239250
func (driver *LinuxDriver) MountDevice(device *model.Device, mountPoint string, mountOptions []string, fsOpts *model.FilesystemOpts) (*model.Mount, error) {
240251
log.Tracef(">>>>> MountDevice, device: %+v, mountPoint: %s, mountOptions: %v, fsOpts: %+v", device, mountPoint, mountOptions, fsOpts)

linux/mount.go

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,28 @@ func MountDeviceWithFileSystem(devPath string, mountPoint string, options []stri
570570
return mount, nil
571571
}
572572

573+
func MountNFSShare(source string, targetPath string, options []string) error {
574+
log.Tracef(">>>>> MountNFSShare called with source %s target %s", source, targetPath)
575+
defer log.Tracef("<<<<< MountNFSShare")
576+
577+
args := []string{source, targetPath}
578+
optionArgs := []string{}
579+
if len(options) != 0 {
580+
optionArgs = append([]string{"-o"}, strings.Join(options, ","))
581+
}
582+
args = append(optionArgs, args...)
583+
_, _, err := util.ExecCommandOutput(mountCommand, args)
584+
if err != nil {
585+
return err
586+
}
587+
// verify that mount is successful
588+
err = verifyMount(source, targetPath)
589+
if err != nil {
590+
return err
591+
}
592+
return nil
593+
}
594+
573595
func performMount(devPath string, mountPoint string, options []string) (*model.Mount, error) {
574596
args := []string{devPath, mountPoint}
575597
optionArgs := []string{}
@@ -694,15 +716,17 @@ func verifyUnMount(mountPoint string) error {
694716
log.Tracef("%s is unmounted", mountPoint)
695717
return nil
696718
}
719+
697720
func verifyMount(devPath, mountPoint string) error {
698721
mountedDevice, err := GetDeviceFromMountPoint(mountPoint)
699722
if err != nil {
700723
return err
701724
}
702-
if mountedDevice != "" {
703-
log.Tracef("%s is mounted at %s", devPath, mountPoint)
725+
if mountedDevice == "" {
726+
return fmt.Errorf("device %s is not mounted at %s", devPath, mountPoint)
704727
}
705-
return err
728+
log.Tracef("%s is mounted at %s", devPath, mountPoint)
729+
return nil
706730
}
707731

708732
// GetFsType returns filesytem type for a given mount object

0 commit comments

Comments
 (0)