Merge pull request #54556 from cofyc/fix_cmd_not_found

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

RBD Plugin: Fix bug in checking command not found error.

**What this PR does / why we need it**:

Fix bug in error checking logic. 

`Error()` method of command not found error returned from `command.Run/Output` is not "executable file not found in $PATH". Actually, it's `exec: "<command>": executable file not found in $PATH`.

I followed the logic in https://github.com/kubernetes/kubernetes/blob/v1.9.0-alpha.1/pkg/kubectl/cmd/util/editor/editor.go#L129 to detect command not found error.


**Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #

**Special notes for your reviewer**:

https://play.golang.org/p/yZJxtouUQL

**Release note**:

```release-note
NONE
```
This commit is contained in:
Kubernetes Submit Queue 2017-11-18 07:32:22 -08:00 committed by GitHub
commit a7e76475ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -27,6 +27,7 @@ import (
"io/ioutil"
"math/rand"
"os"
"os/exec"
"path"
"regexp"
"strings"
@ -43,7 +44,6 @@ import (
const (
imageWatcherStr = "watcher="
kubeLockMagic = "kubelet_lock_magic_"
rbdCmdErr = "executable file not found in $PATH"
)
var (
@ -121,8 +121,10 @@ func (util *RBDUtil) MakeGlobalPDName(rbd rbd) string {
}
func rbdErrors(runErr, resultErr error) error {
if runErr.Error() == rbdCmdErr {
return fmt.Errorf("rbd: rbd cmd not found")
if err, ok := runErr.(*exec.Error); ok {
if err.Err == exec.ErrNotFound {
return fmt.Errorf("rbd: rbd cmd not found")
}
}
return resultErr
}
@ -482,10 +484,12 @@ func (util *RBDUtil) rbdStatus(b *rbdMounter) (bool, string, error) {
break
}
if err.Error() == rbdCmdErr {
glog.Errorf("rbd cmd not found")
// fail fast if command not found
return false, output, err
if err, ok := err.(*exec.Error); ok {
if err.Err == exec.ErrNotFound {
glog.Errorf("rbd cmd not found")
// fail fast if command not found
return false, output, err
}
}
}