Note: This is a beta release of Red Hat Bugzilla 5.0. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Also email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback here.
Bug 1694236 - oc import-image returning 0 even when the process fails
Summary: oc import-image returning 0 even when the process fails
Keywords:
Status: NEW
Alias: None
Product: OpenShift Container Platform
Classification: Red Hat
Component: RFE
Version: 3.9.0
Hardware: x86_64
OS: Linux
unspecified
low
Target Milestone: ---
: ---
Assignee: Ben Parees
QA Contact: Xiaoli Tian
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2019-03-29 20:40 UTC by Miguel Figueiredo Nunes
Modified: 2019-04-09 13:39 UTC (History)
6 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2019-04-02 15:44:38 UTC
Target Upstream Version:


Attachments (Terms of Use)

Description Miguel Figueiredo Nunes 2019-03-29 20:40:14 UTC
Description of problem:
oc import-image returns 0 even when the process fails 

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


How reproducible:
Attempt to import an image from a registry that doesn't exist still returns ok even when the process fails

Steps to Reproduce:
1. import the image with oc import-image <image-name>:<tag>
2. The process reports failure internally but still returns 0 in the terminal

Actual results:

user@node: /tmp > oc import-image <image>:<tag>
The import completed with errors.

Name:                   <image>
Namespace:              test
Created:                3 weeks ago
Labels:                 app=test-app
Annotations:            openshift.io/image.dockerRepositoryCheck=yyyy-mm-ddTHH:MM:ssZ
Docker Pull Spec:       docker-registry.default.svc:5000/test/<image>
Image Lookup:           local=false
Unique Images:          1
Tags:                   2

<tag>
  tagged from <external-registry>/<image>:<tag>

  ! error: Import failed (NotFound): dockerimage.image.openshift.io "<external-registry>/<image>:<tag>" not found
      Less than a second ago

<tag>
  no spec tag

  * <external-registry>/<image>@sha256:deadbeef0000001111112222233333444444
      3 weeks ago

error: tag <tag> failed: dockerimage.image.openshift.io "<external>registry>/<image>:<tag>" not found

user@node: /tmp > echo $?
0


Expected results:
echo $? not returning 0

Additional info:

Comment 1 Oleg Bulatov 2019-04-02 15:44:38 UTC
This works as intended.

`oc import-image` creates an ImageStreamImport object, and shows the response back to the user. In the example, the image stream import object has been successfully created, and as a result the exit status is 0.

The import status available as a condition on the image stream object. This object is printed by `oc import-image -o json` or it can be obtained by a subsequent `oc get`.

Comment 2 Seb de Calignon 2019-04-03 15:20:19 UTC
Hello,
Just want to mention that as a oc user, this doesn't work as expected.
oc import-image objective is to "Import the latest image information from a tag in a Docker registry"

When the image can not be pulled, the import of the latest information fails.

If we use curl as an example: curl to a non responsive URL, the return code is different from 0.

We asked for this because it would be easier for Continuous Integration to have a user oriented return code.
Regards
Sebastien

Comment 3 Oleg Bulatov 2019-04-04 12:18:16 UTC
curl is a good example:

$ curl -v https://httpbin.org/basic-auth/admin/qwerty ; echo rc=$?
...
< HTTP/1.1 401 UNAUTHORIZED
...
rc=0

It also doesn't consider getting HTTP errors from a server as a problem. It also has problems handling multiple endpoints:

$ curl --connect-timeout 2 http://192.0.2.1/ https://httpbin.org/uuid ; echo rc=$?
curl: (28) Connection timed out after 2002 milliseconds
{
  "uuid": "6f28963e-d7e9-4a54-878b-19a9bd0b0c65"
}
rc=0

To workaround this it has --fail-early and --fail (-f):

$ curl --fail-early --connect-timeout 2 http://192.0.2.1/ https://httpbin.org/uuid ; echo rc=$?
curl: (28) Connection timed out after 2001 milliseconds
rc=28
$ curl -f https://httpbin.org/basic-auth/admin/qwerty ; echo rc=$?
curl: (22) The requested URL returned error: 401 UNAUTHORIZED
rc=22

And when we cannot create an ImageStreamImport object or we have problems with the master API we also have a non-zero exit status:

$ oc import-image nginx:non-existent ; echo rc=$?
error: the tag "non-existent" does not exist on the image stream - choose an existing tag to import or use the 'tag' command to create a new tag
rc=1

So we may introduce an option with a similar semantic for `oc import-image`, it indeed should be useful for scripting. But it should be an RFE and we may do it for 4.2.

Comment 4 Miguel Figueiredo Nunes 2019-04-09 13:39:13 UTC
Oleg,

Can you open this RFE?
If it should be me, let me know and I'll get the necessary information and open it.


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