Bug 1290023 - Return true exit code from oc exec
Return true exit code from oc exec
Status: CLOSED ERRATA
Product: OpenShift Container Platform
Classification: Red Hat
Component: Pod (Show other bugs)
3.1.0
All Linux
unspecified Severity medium
: ---
: ---
Assigned To: Stefan Schimanski
yapei
:
Depends On:
Blocks: 1353161 1496992
  Show dependency treegraph
 
Reported: 2015-12-09 09:15 EST by Mohamed Hamza Ben Mansour
Modified: 2017-09-28 17:56 EDT (History)
12 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 1496992 (view as bug list)
Environment:
Last Closed: 2017-01-18 07:38:39 EST
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Mohamed Hamza Ben Mansour 2015-12-09 09:15:43 EST
Description of problem:
When launching a oc exec with a command that returns a non zero code, we are unable to capture it since it is not returned by the oc exec command which return only a 1 exit code.


Version-Release number of selected component (if applicable):
3.x

How reproducible:
Always

Steps to Reproduce:
1. oc exec dummycomand
exec: "dummycommand": executable file not found in $PATH
error: Error executing remote command: Error executing command in container: Error executing in Docker Container: -1
2.  echo $?
1
3. dummycommand
4. echo $?
127

Actual results:


Expected results:
1. oc exec dummycomand
exec: "dummycommand": executable file not found in $PATH
error: Error executing remote command: Error executing command in container: Error executing in Docker Container: 127
2. echo $?
127




Additional info:
Comment 1 Clayton Coleman 2016-02-07 15:44:21 EST
This is a bug, does not have to be an RFE.  Impacts scriptability.
Comment 2 Andy Goldstein 2016-02-12 10:41:56 EST
Not a 3.2 blocker IMO
Comment 3 Stefan Schimanski 2016-05-27 10:29:02 EDT
Create an upstream issue: https://github.com/kubernetes/kubernetes/issues/26424
Comment 5 Stefan Schimanski 2016-10-26 03:08:16 EDT
https://github.com/kubernetes/kubernetes/issues/26541 has been merged in upstream during the 1.4 release cylce.
Comment 6 Troy Dawson 2016-10-28 15:51:30 EDT
This has been merged into ose and is in OSE v3.4.0.17 or newer.
Comment 8 XiaochuanWang 2016-11-03 02:53:04 EDT
Tested on latest OCP v3.4.0.19 and reproduced by original steps (error occurred on step 2)
# oc run dc --image=aosqe/hello-openshift (wait until the pod is ready and running)
1) Successful and code is passed correctly:
# oc exec dc-1-vo5vt ls
bin
...
# echo $?
0

2) Error code 127 can not be passed out from container:
# oc exec dc-1-vo5vt somecmd
exec: "somecmd": executable file not found in $PATH
error: error stream protocol error: invalid exit code value "-1"
# echo $?
1
# somecmd
bash: somecmd: command not found...
# echo $?
127

3) Container get the expected error code
# oc rsh dc-1-vo5vt
/ $ somecmd
/bin/sh: somecmd: not found
/ $ echo $?
127
Comment 9 Stefan Schimanski 2016-11-03 04:29:31 EDT
With kubectl 1.4.5:

# kubectl exec sleep-661823049-44uzt somecmd
rpc error: code = 2 desc = "oci runtime error: exec failed: exec: \"somecmd\": executable file not found in $PATH"%                                                                           # echo $?
126

# kubectl exec sleep-661823049-44uzt -- /bin/sh -c somecmd
/bin/sh: somecmd: not found
# echo $?
127

The 126 should be a 127 as well IMO.

Looks like "oc exec" behaves differently. Might be a rebase error.
Comment 10 Stefan Schimanski 2016-11-03 06:11:53 EDT
The 126 is what Docker report for failed exec commands.
Comment 11 Stefan Schimanski 2016-11-03 07:04:05 EDT
I was able to reproduce the "-1" of "oc exec somecmd" using upstream kube and upstream kubectl and Docker 1.10.3 on the nodes. 

It looks like the exit code return by the "exec start" command of the Docker API is "-1" for 1.10.3 and 126 for 1.12.1.
Comment 18 errata-xmlrpc 2017-01-18 07:38:39 EST
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2017:0066

Note You need to log in before you can comment on or make changes to this bug.