mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
Merge pull request #27054 from jingxu97/bug-volume
Automatic merge from submit-queue Fix bug in isLikelyNotMountPoint function In nsenter_mount.go/isLikelyNotMountPoint function, the returned output from findmnt command misses the last letter. Modify the code to use String.contains instead of string matching. fixes #26421 fixes #25056 fixes #22911
This commit is contained in:
commit
6b14e0f226
@ -175,8 +175,11 @@ func (n *NsenterMounter) IsLikelyNotMountPoint(file string) (bool, error) {
|
|||||||
glog.V(5).Infof("findmnt: directory %s does not exist", file)
|
glog.V(5).Infof("findmnt: directory %s does not exist", file)
|
||||||
return true, err
|
return true, err
|
||||||
}
|
}
|
||||||
|
// Add --first-only option: since we are testing for the absense of a mountpoint, it is sufficient to get only
|
||||||
args := []string{"--mount=/rootfs/proc/1/ns/mnt", "--", n.absHostPath("findmnt"), "-o", "target", "--noheadings", "--target", file}
|
// the first of multiple possible mountpoints using --first-only.
|
||||||
|
// Also add fstype output to make sure that the output of target file will give the full path
|
||||||
|
// TODO: Need more refactoring for this function. Track the solution with issue #26996
|
||||||
|
args := []string{"--mount=/rootfs/proc/1/ns/mnt", "--", n.absHostPath("findmnt"), "-o", "target,fstype", "--noheadings", "--first-only", "--target", file}
|
||||||
glog.V(5).Infof("findmnt command: %v %v", nsenterPath, args)
|
glog.V(5).Infof("findmnt command: %v %v", nsenterPath, args)
|
||||||
|
|
||||||
exec := exec.New()
|
exec := exec.New()
|
||||||
@ -188,13 +191,15 @@ func (n *NsenterMounter) IsLikelyNotMountPoint(file string) (bool, error) {
|
|||||||
// It's safer to assume that it's not a mount point.
|
// It's safer to assume that it's not a mount point.
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
strOut := strings.TrimSuffix(string(out), "\n")
|
mountTarget := strings.Split(string(out), " ")[0]
|
||||||
|
mountTarget = strings.TrimSuffix(mountTarget, "\n")
|
||||||
|
glog.V(5).Infof("IsLikelyNotMountPoint findmnt output for path %s: %v:", file, mountTarget)
|
||||||
|
|
||||||
glog.V(5).Infof("IsLikelyNotMountPoint findmnt output for path %s: %v", file, strOut)
|
if mountTarget == file {
|
||||||
if strOut == file {
|
glog.V(5).Infof("IsLikelyNotMountPoint: %s is a mount point", file)
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
glog.V(5).Infof("IsLikelyNotMountPoint: %s is not a mount point", file)
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user