Commit fdb3b2af authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #48578 from fabianofranz/run_output_message_on_container_error

Automatic merge from submit-queue (batch tested with PRs 48578, 48895, 48958) run must output message on container error **What this PR does / why we need it**: `kubectl run` must output a message (instead of just exiting with an error code) on container error. **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes https://github.com/openshift/origin/issues/15031 found in OpenShift **Release note**: ```release-note NONE ```
parents 2610b9cf f623b9b4
...@@ -362,7 +362,7 @@ func RunRun(f cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer, cmd *c ...@@ -362,7 +362,7 @@ func RunRun(f cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer, cmd *c
return unknownRcErr return unknownRcErr
} }
return uexec.CodeExitError{ return uexec.CodeExitError{
Err: fmt.Errorf("pod %s/%s terminated", pod.Namespace, pod.Name), Err: fmt.Errorf("pod %s/%s terminated (%s)\n%s", pod.Namespace, pod.Name, pod.Status.ContainerStatuses[0].State.Terminated.Reason, pod.Status.ContainerStatuses[0].State.Terminated.Message),
Code: int(rc), Code: int(rc),
} }
default: default:
......
...@@ -166,8 +166,7 @@ func checkErr(err error, handleErr func(string, int)) { ...@@ -166,8 +166,7 @@ func checkErr(err error, handleErr func(string, int)) {
case utilerrors.Aggregate: case utilerrors.Aggregate:
handleErr(MultipleErrors(``, err.Errors()), DefaultErrorExitCode) handleErr(MultipleErrors(``, err.Errors()), DefaultErrorExitCode)
case utilexec.ExitError: case utilexec.ExitError:
// do not print anything, only terminate with given error handleErr(err.Error(), err.ExitStatus())
handleErr("", err.ExitStatus())
default: // for any other error type default: // for any other error type
msg, ok := StandardErrorMessage(err) msg, ok := StandardErrorMessage(err)
if !ok { if !ok {
......
...@@ -267,7 +267,7 @@ func TestCheckExitError(t *testing.T) { ...@@ -267,7 +267,7 @@ func TestCheckExitError(t *testing.T) {
testCheckError(t, []checkErrTestCase{ testCheckError(t, []checkErrTestCase{
{ {
uexec.CodeExitError{Err: fmt.Errorf("pod foo/bar terminated"), Code: 42}, uexec.CodeExitError{Err: fmt.Errorf("pod foo/bar terminated"), Code: 42},
"", "pod foo/bar terminated",
42, 42,
}, },
}) })
......
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