mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 03:11:40 +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)
|
||||
return true, err
|
||||
}
|
||||
|
||||
args := []string{"--mount=/rootfs/proc/1/ns/mnt", "--", n.absHostPath("findmnt"), "-o", "target", "--noheadings", "--target", file}
|
||||
// Add --first-only option: since we are testing for the absense of a mountpoint, it is sufficient to get only
|
||||
// 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)
|
||||
|
||||
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.
|
||||
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 strOut == file {
|
||||
if mountTarget == file {
|
||||
glog.V(5).Infof("IsLikelyNotMountPoint: %s is a mount point", file)
|
||||
return false, nil
|
||||
}
|
||||
|
||||
glog.V(5).Infof("IsLikelyNotMountPoint: %s is not a mount point", file)
|
||||
return true, nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user