From f9a04f3bc4a028e67c88ba9fbe25de99784493c3 Mon Sep 17 00:00:00 2001 From: Jan Safranek Date: Wed, 26 May 2021 20:45:56 +0200 Subject: [PATCH] Move error reporting to volume plugins Move reporting of GetReliableMountRefs error to the volume plugins that have more context about severity of the error. --- pkg/volume/fc/fc.go | 6 ++++++ pkg/volume/iscsi/iscsi.go | 6 ++++++ pkg/volume/util/util.go | 2 -- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/pkg/volume/fc/fc.go b/pkg/volume/fc/fc.go index 4422cf7102e..6cdfa925329 100644 --- a/pkg/volume/fc/fc.go +++ b/pkg/volume/fc/fc.go @@ -26,6 +26,7 @@ import ( "k8s.io/klog/v2" "k8s.io/mount-utils" utilexec "k8s.io/utils/exec" + "k8s.io/utils/io" utilstrings "k8s.io/utils/strings" v1 "k8s.io/api/core/v1" @@ -246,6 +247,11 @@ func (plugin *fcPlugin) ConstructVolumeSpec(volumeName, mountPath string) (*volu // The volume can then be mounted on several nodes, resulting in volume // corruption. paths, err := util.GetReliableMountRefs(mounter, mountPath) + if io.IsInconsistentReadError(err) { + klog.Errorf("Failed to read mount refs from /proc/mounts for %s: %s", mountPath, err) + klog.Errorf("Kubelet cannot unmount volume at %s, please unmount it manually", mountPath) + return nil, err + } if err != nil { return nil, err } diff --git a/pkg/volume/iscsi/iscsi.go b/pkg/volume/iscsi/iscsi.go index 6f7ec6ef42a..2e4c8873af5 100644 --- a/pkg/volume/iscsi/iscsi.go +++ b/pkg/volume/iscsi/iscsi.go @@ -27,6 +27,7 @@ import ( "k8s.io/klog/v2" "k8s.io/mount-utils" utilexec "k8s.io/utils/exec" + "k8s.io/utils/io" "k8s.io/utils/keymutex" utilstrings "k8s.io/utils/strings" @@ -224,6 +225,11 @@ func (plugin *iscsiPlugin) ConstructVolumeSpec(volumeName, mountPath string) (*v // The volume can then be mounted on several nodes, resulting in volume // corruption. paths, err := util.GetReliableMountRefs(mounter, mountPath) + if io.IsInconsistentReadError(err) { + klog.Errorf("Failed to read mount refs from /proc/mounts for %s: %s", mountPath, err) + klog.Errorf("Kubelet cannot unmount volume at %s, please unmount it and all mounts of the same device manually.", mountPath) + return nil, err + } if err != nil { return nil, err } diff --git a/pkg/volume/util/util.go b/pkg/volume/util/util.go index 83cb170cb6b..0c160ced095 100644 --- a/pkg/volume/util/util.go +++ b/pkg/volume/util/util.go @@ -754,8 +754,6 @@ func GetReliableMountRefs(mounter mount.Interface, mountPath string) ([]string, return true, nil }) if err == wait.ErrWaitTimeout { - klog.Errorf("Failed to read mount refs from /proc/mounts for %s: %s", mountPath, err) - klog.Errorf("Kubelet cannot unmount volume at %s, please unmount it manually", mountPath) return nil, lastErr } return paths, err