rebase: k8s.io/mount-utils/IsNotMountPoint() is deprecated

IsNotMountPoint() is deprecated and Mounter.IsMountPoint() is
recommended to be used instead.

Reported-by: golangci/staticcheck
Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
Niels de Vos 2022-08-02 09:50:18 +02:00 committed by mergify[bot]
parent 10b2277330
commit 83df1eae53
2 changed files with 8 additions and 8 deletions

View File

@ -858,7 +858,7 @@ func (ns *NodeServer) NodeUnpublishVolume(
targetPath := req.GetTargetPath() targetPath := req.GetTargetPath()
// considering kubelet make sure node operations like unpublish/unstage...etc can not be called // considering kubelet make sure node operations like unpublish/unstage...etc can not be called
// at same time, an explicit locking at time of nodeunpublish is not required. // at same time, an explicit locking at time of nodeunpublish is not required.
notMnt, err := mount.IsNotMountPoint(ns.Mounter, targetPath) isMnt, err := ns.Mounter.IsMountPoint(targetPath)
if err != nil { if err != nil {
if os.IsNotExist(err) { if os.IsNotExist(err) {
// targetPath has already been deleted // targetPath has already been deleted
@ -869,7 +869,7 @@ func (ns *NodeServer) NodeUnpublishVolume(
return nil, status.Error(codes.NotFound, err.Error()) return nil, status.Error(codes.NotFound, err.Error())
} }
if notMnt { if !isMnt {
if err = os.RemoveAll(targetPath); err != nil { if err = os.RemoveAll(targetPath); err != nil {
return nil, status.Error(codes.Internal, err.Error()) return nil, status.Error(codes.Internal, err.Error())
} }
@ -925,15 +925,15 @@ func (ns *NodeServer) NodeUnstageVolume(
stagingParentPath := req.GetStagingTargetPath() stagingParentPath := req.GetStagingTargetPath()
stagingTargetPath := getStagingTargetPath(req) stagingTargetPath := getStagingTargetPath(req)
notMnt, err := mount.IsNotMountPoint(ns.Mounter, stagingTargetPath) isMnt, err := ns.Mounter.IsMountPoint(stagingTargetPath)
if err != nil { if err != nil {
if !os.IsNotExist(err) { if !os.IsNotExist(err) {
return nil, status.Error(codes.NotFound, err.Error()) return nil, status.Error(codes.NotFound, err.Error())
} }
// Continue on ENOENT errors as we may still have the image mapped // Continue on ENOENT errors as we may still have the image mapped
notMnt = true isMnt = false
} }
if !notMnt { if isMnt {
// Unmounting the image // Unmounting the image
err = ns.Mounter.Unmount(stagingTargetPath) err = ns.Mounter.Unmount(stagingTargetPath)
if err != nil { if err != nil {
@ -961,7 +961,7 @@ func (ns *NodeServer) NodeUnstageVolume(
log.UsefulLog(ctx, "failed to find image metadata: %v", err) log.UsefulLog(ctx, "failed to find image metadata: %v", err)
// It is an error if it was mounted, as we should have found the image metadata file with // It is an error if it was mounted, as we should have found the image metadata file with
// no errors // no errors
if !notMnt { if isMnt {
return nil, status.Error(codes.Internal, err.Error()) return nil, status.Error(codes.Internal, err.Error())
} }

View File

@ -554,12 +554,12 @@ func checkValidImageFeatures(imageFeatures string, ok bool) bool {
// isNotMountPoint checks whether MountPoint does not exists and // isNotMountPoint checks whether MountPoint does not exists and
// also discards error indicating mountPoint exists. // also discards error indicating mountPoint exists.
func isNotMountPoint(mounter mount.Interface, stagingTargetPath string) (bool, error) { func isNotMountPoint(mounter mount.Interface, stagingTargetPath string) (bool, error) {
isNotMnt, err := mount.IsNotMountPoint(mounter, stagingTargetPath) isMnt, err := mounter.IsMountPoint(stagingTargetPath)
if os.IsNotExist(err) { if os.IsNotExist(err) {
err = nil err = nil
} }
return isNotMnt, err return !isMnt, err
} }
// isCephMgrSupported determines if the cluster has support for MGR based operation // isCephMgrSupported determines if the cluster has support for MGR based operation