Merge pull request #114736 from andyzhangx/fix-tryUnmount

fix: tryUnmount should respect mounter.withSafeNotMountedBehavior
This commit is contained in:
Kubernetes Prow Robot 2023-01-03 05:37:30 -08:00 committed by GitHub
commit 4e70155dbd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -383,7 +383,7 @@ func (mounter *Mounter) Unmount(target string) error {
// UnmountWithForce unmounts given target but will retry unmounting with force option // UnmountWithForce unmounts given target but will retry unmounting with force option
// after given timeout. // after given timeout.
func (mounter *Mounter) UnmountWithForce(target string, umountTimeout time.Duration) error { func (mounter *Mounter) UnmountWithForce(target string, umountTimeout time.Duration) error {
err := tryUnmount(target, umountTimeout) err := tryUnmount(mounter, target, umountTimeout)
if err != nil { if err != nil {
if err == context.DeadlineExceeded { if err == context.DeadlineExceeded {
klog.V(2).Infof("Timed out waiting for unmount of %s, trying with -f", target) klog.V(2).Infof("Timed out waiting for unmount of %s, trying with -f", target)
@ -775,7 +775,7 @@ func (mounter *Mounter) IsMountPoint(file string) (bool, error) {
} }
// tryUnmount calls plain "umount" and waits for unmountTimeout for it to finish. // tryUnmount calls plain "umount" and waits for unmountTimeout for it to finish.
func tryUnmount(path string, unmountTimeout time.Duration) error { func tryUnmount(mounter *Mounter, path string, unmountTimeout time.Duration) error {
klog.V(4).Infof("Unmounting %s", path) klog.V(4).Infof("Unmounting %s", path)
ctx, cancel := context.WithTimeout(context.Background(), unmountTimeout) ctx, cancel := context.WithTimeout(context.Background(), unmountTimeout)
defer cancel() defer cancel()
@ -790,6 +790,10 @@ func tryUnmount(path string, unmountTimeout time.Duration) error {
} }
if cmderr != nil { if cmderr != nil {
if mounter.withSafeNotMountedBehavior && strings.Contains(string(out), errNotMounted) {
klog.V(4).Infof("ignoring 'not mounted' error for %s", path)
return nil
}
return fmt.Errorf("unmount failed: %v\nUnmounting arguments: %s\nOutput: %s", cmderr, path, string(out)) return fmt.Errorf("unmount failed: %v\nUnmounting arguments: %s\nOutput: %s", cmderr, path, string(out))
} }
return nil return nil