@@ -16,7 +16,7 @@ const (
16
16
// RunCommand wraps a k8s exec to deal with the no child process error. Same as exec.CombinedOutput.
17
17
// On error, the output is included so callers don't need to echo it again.
18
18
19
- func RunCommand (pipeCmd string , pipeCmdArg string , cmd1 string , execCmdArgs ... string ) ([]byte , error ) {
19
+ func RunCommand (pipeCmd string , pipeCmdArg [] string , cmd1 string , execCmdArgs ... string ) ([]byte , error ) {
20
20
execCmd1 := exec .Command (cmd1 , execCmdArgs ... )
21
21
22
22
if pipeCmd != "" {
@@ -47,9 +47,9 @@ func checkError(err error, execCmd exec.Cmd) error {
47
47
}
48
48
return err
49
49
}
50
- func execPipeCommand (pipeCmd string , pipeCmdArg string , execCmd1 * exec.Cmd ) ([]byte , error ) {
50
+ func execPipeCommand (pipeCmd string , pipeCmdArg [] string , execCmd1 * exec.Cmd ) ([]byte , error ) {
51
51
52
- execPipeCmd := exec .Command (pipeCmd , pipeCmdArg )
52
+ execPipeCmd := exec .Command (pipeCmd , pipeCmdArg ... )
53
53
stdoutPipe , err := execCmd1 .StdoutPipe ()
54
54
if err != nil {
55
55
klog .Errorf ("failed command %v: got error:%v" , execCmd1 , err )
@@ -63,8 +63,12 @@ func execPipeCommand(pipeCmd string, pipeCmdArg string, execCmd1 *exec.Cmd) ([]b
63
63
execPipeCmd .Stdin = stdoutPipe
64
64
output , err := execPipeCmd .CombinedOutput ()
65
65
if err != nil {
66
+ // Some commands (such as grep) will return an error with exit status of 1
67
+ if len (output ) == 0 && err .(* exec.ExitError ).ExitCode () == 1 {
68
+ return output , nil
69
+ }
66
70
err = checkError (err , * execPipeCmd )
67
- return nil , fmt .Errorf ("%s failed: %w; output: %s" , pipeCmd , err , string (output ))
71
+ return nil , fmt .Errorf ("%s failed: %w; output: %s" , execPipeCmd , err , string (output ))
68
72
}
69
73
70
74
return output , nil
0 commit comments