Unverified Commit a7e76475 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

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 ```
parents 842518d3 ff639e80
...@@ -27,6 +27,7 @@ import ( ...@@ -27,6 +27,7 @@ import (
"io/ioutil" "io/ioutil"
"math/rand" "math/rand"
"os" "os"
"os/exec"
"path" "path"
"regexp" "regexp"
"strings" "strings"
...@@ -43,7 +44,6 @@ import ( ...@@ -43,7 +44,6 @@ import (
const ( const (
imageWatcherStr = "watcher=" imageWatcherStr = "watcher="
kubeLockMagic = "kubelet_lock_magic_" kubeLockMagic = "kubelet_lock_magic_"
rbdCmdErr = "executable file not found in $PATH"
) )
var ( var (
...@@ -121,8 +121,10 @@ func (util *RBDUtil) MakeGlobalPDName(rbd rbd) string { ...@@ -121,8 +121,10 @@ func (util *RBDUtil) MakeGlobalPDName(rbd rbd) string {
} }
func rbdErrors(runErr, resultErr error) error { func rbdErrors(runErr, resultErr error) error {
if runErr.Error() == rbdCmdErr { if err, ok := runErr.(*exec.Error); ok {
return fmt.Errorf("rbd: rbd cmd not found") if err.Err == exec.ErrNotFound {
return fmt.Errorf("rbd: rbd cmd not found")
}
} }
return resultErr return resultErr
} }
...@@ -482,10 +484,12 @@ func (util *RBDUtil) rbdStatus(b *rbdMounter) (bool, string, error) { ...@@ -482,10 +484,12 @@ func (util *RBDUtil) rbdStatus(b *rbdMounter) (bool, string, error) {
break break
} }
if err.Error() == rbdCmdErr { if err, ok := err.(*exec.Error); ok {
glog.Errorf("rbd cmd not found") if err.Err == exec.ErrNotFound {
// fail fast if command not found glog.Errorf("rbd cmd not found")
return false, output, err // fail fast if command not found
return false, output, err
}
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment