From 01b6fc78cdc464e30060af55b90bd26fd01143d0 Mon Sep 17 00:00:00 2001 From: zhangningmin Date: Wed, 28 Jun 2017 10:22:13 +0800 Subject: [PATCH] Improve the warning message if the rbd command is not found. --- pkg/volume/rbd/rbd_util.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/pkg/volume/rbd/rbd_util.go b/pkg/volume/rbd/rbd_util.go index 3ad12361752..1b88cb642aa 100644 --- a/pkg/volume/rbd/rbd_util.go +++ b/pkg/volume/rbd/rbd_util.go @@ -44,6 +44,7 @@ import ( const ( imageWatcherStr = "watcher=" kubeLockMagic = "kubelet_lock_magic_" + rbdCmdErr = "executable file not found in $PATH" ) // search /sys/bus for rbd device that matches given pool and image @@ -103,6 +104,12 @@ type RBDUtil struct{} func (util *RBDUtil) MakeGlobalPDName(rbd rbd) string { return makePDNameInternal(rbd.plugin.host, rbd.Pool, rbd.Image) } +func rbdErrors(runErr, resultErr error) error { + if runErr.Error() == rbdCmdErr { + return fmt.Errorf("rbd: rbd cmd not found") + } + return resultErr +} func (util *RBDUtil) rbdLock(b rbdMounter, lock bool) error { var err error @@ -269,7 +276,7 @@ func (util *RBDUtil) AttachDisk(b rbdMounter) error { // fence off other mappers if err = util.fencing(b); err != nil { - return fmt.Errorf("rbd: image %s is locked by other nodes", b.Image) + return rbdErrors(err, fmt.Errorf("rbd: failed to lock image %s (maybe locked by other nodes), error %v", b.Image, err)) } // rbd lock remove needs ceph and image config // but kubelet doesn't get them from apiserver during teardown @@ -327,7 +334,7 @@ func (util *RBDUtil) DetachDisk(c rbdUnmounter, mntPath string) error { // rbd unmap _, err = c.plugin.execCommand("rbd", []string{"unmap", device}) if err != nil { - return fmt.Errorf("rbd: failed to unmap device %s:Error: %v", device, err) + return rbdErrors(err, fmt.Errorf("rbd: failed to unmap device %s:Error: %v", device, err)) } // load ceph and image/pool info to remove fencing @@ -435,8 +442,12 @@ func (util *RBDUtil) rbdStatus(b *rbdMounter) (bool, error) { output = string(cmd) if err != nil { - // ignore error code, just checkout output for watcher string - glog.Warningf("failed to execute rbd status on mon %s", mon) + if err.Error() == rbdCmdErr { + glog.Errorf("rbd cmd not found") + } else { + // ignore error code, just checkout output for watcher string + glog.Warningf("failed to execute rbd status on mon %s", mon) + } } if strings.Contains(output, imageWatcherStr) {