Bug 1290023 - Return true exit code from oc exec
Summary: Return true exit code from oc exec
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: OpenShift Container Platform
Classification: Red Hat
Component: Node
Version: 3.1.0
Hardware: All
OS: Linux
unspecified
medium
Target Milestone: ---
: ---
Assignee: Stefan Schimanski
QA Contact: Yadan Pei
URL:
Whiteboard:
Depends On:
Blocks: 1353161 1496992
TreeView+ depends on / blocked
 
Reported: 2015-12-09 14:15 UTC by Mohamed Hamza Ben Mansour
Modified: 2017-09-28 21:56 UTC (History)
12 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
: 1496992 (view as bug list)
Environment:
Last Closed: 2017-01-18 12:38:39 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2017:0066 0 normal SHIPPED_LIVE Red Hat OpenShift Container Platform 3.4 RPM Release Advisory 2017-01-18 17:23:26 UTC

Description Mohamed Hamza Ben Mansour 2015-12-09 14:15:43 UTC
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 20:44:21 UTC
This is a bug, does not have to be an RFE.  Impacts scriptability.

Comment 2 Andy Goldstein 2016-02-12 15:41:56 UTC
Not a 3.2 blocker IMO

Comment 3 Stefan Schimanski 2016-05-27 14:29:02 UTC
Create an upstream issue: https://github.com/kubernetes/kubernetes/issues/26424

Comment 5 Stefan Schimanski 2016-10-26 07:08:16 UTC
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 19:51:30 UTC
This has been merged into ose and is in OSE v3.4.0.17 or newer.

Comment 8 XiaochuanWang 2016-11-03 06:53:04 UTC
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 08:29:31 UTC
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 10:11:53 UTC
The 126 is what Docker report for failed exec commands.

Comment 11 Stefan Schimanski 2016-11-03 11:04:05 UTC
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 12:38:39 UTC
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.