Bug 1312230

Summary: `oc import-image` command exit code should be 1 if import a non-existed image
Product: OKD Reporter: XiaochuanWang <xiaocwan>
Component: ocAssignee: Maciej Szulik <maszulik>
Status: CLOSED CURRENTRELEASE QA Contact: Wei Sun <wsun>
Severity: low Docs Contact:
Priority: unspecified    
Version: 3.xCC: aos-bugs, mmccomas
Target Milestone: ---   
Target Release: 3.x   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Cause: Lack of error checking upon image import. Consequence: The message printed to a user always stated the import was successful. Fix: Check image import errors and print message accordingly. Result: The message contains valid information whether import succeeded or encountered problems.
Story Points: ---
Clone Of: Environment:
Last Closed: 2016-12-09 21:53:06 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:

Description XiaochuanWang 2016-02-26 08:04:50 UTC
Description of problem:
When user import a non-existed image from public docker registory, the exit status code should be 1. But now it returns import successfully with information to let user pass repository authentication first.  At least "The import completed successfully." is incorrect.

Version-Release number of selected component (if applicable):
oc v1.1.3-282-gc423082
kubernetes v1.2.0-alpha.7-703-gbc4550d

How reproducible:
Always

Steps to Reproduce:
1. Create image stream with non-existed image from public docker registry and repo
    {
    "kind": "ImageStream",
    "apiVersion": "v1",
    "metadata": {
       "name": "python",
       "creationTimestamp": null
    },
    "spec": {
       "dockerImageRepository": "wsun/non-existen-image",
            "tags":[
                       { "name": "test",
                          "annotations":
                               { "description": "wsun tests" },
                           "from":
                            { 
                                "Kind": "DockerImage",
                                 "Name": "wsun/non-existen-image" 
                            }                
                         }
              ]
         }
}

2. Import the image. `oc import-image tc510524`

Actual results:
The exit code is 0 and returns as following:
# oc import-image tc510524 
The import completed successfully.

Name:            tc510524
Created:        4 minutes ago
Labels:            <none>
Annotations:        openshift.io/image.dockerRepositoryCheck=2016-02-26T07:06:18Z
Docker Pull Spec:    172.30.251.120:5000/gxrc9/tc510524

Tag    Spec            Created        PullSpec    Image
latest    aosqe/non-existen-image    4 minutes ago            import failed: you may not have access to the Docker image "aosqe/n...

Expected results:
Public image could be searched without authentication.
At least "The import completed successfully." is incorrect.

Comment 1 XiaochuanWang 2016-03-18 10:18:59 UTC
Could also use below template:
{

    "kind": "ImageStream",
    "apiVersion": "v1",
    "metadata": {
      "name": "pyfake",
      "creationTimestamp": null
    },
    "spec": {
       "dockerImageRepository": "wsun/non-existen-image",
           "tags":[
                      { "name": "3.3",
                         "annotations":
                              { "description": "wsun tests" },
                          "from":
                           {
                               "kind": "DockerImage",
                                "name": "wsun/pythonlol-33-centos"
                           }

                        }
             ]
       }

}

Comment 2 XiaochuanWang 2016-04-12 05:54:46 UTC
# oc import-image pyfake
The import completed successfully.

Name:			pyfake
Created:		3 minutes ago
Labels:			<none>
Annotations:		openshift.io/image.dockerRepositoryCheck=2016-04-12T05:49:45Z
Docker Pull Spec:	wsun/non-existen-image

Tag	Spec				Created		PullSpec	Image
latest	wsun/non-existen-image		2 minutes ago			import failed: Internal error occurred: Get https://registry-1.dock...
3.3	wsun/pythonlol-33-centos	3 minutes ago			import failed: Internal error occurred: Get https://registry-1.dock...


# oc get is pyfake -o yaml
apiVersion: v1
kind: ImageStream
metadata:
  annotations:
    openshift.io/image.dockerRepositoryCheck: 2016-04-12T05:49:45Z
  creationTimestamp: 2016-04-12T05:49:14Z
  generation: 3
  name: pyfake
  namespace: xiaocwan-t
  resourceVersion: "3005"
  selfLink: /oapi/v1/namespaces/xiaocwan-t/imagestreams/pyfake
  uid: 49f7cbc7-0072-11e6-b8ab-525400c289e6
spec:
  dockerImageRepository: wsun/non-existen-image
  tags:
  - annotations:
      description: wsun tests
    from:
      kind: DockerImage
      name: wsun/pythonlol-33-centos
    generation: 2
    importPolicy: {}
    name: "3.3"
  - annotations: null
    from:
      kind: DockerImage
      name: wsun/non-existen-image
    generation: 3
    importPolicy: {}
    name: latest
status:
  dockerImageRepository: wsun/non-existen-image
  tags:
  - conditions:
    - generation: 2
      lastTransitionTime: 2016-04-12T05:49:29Z
      message: 'Internal error occurred: Get https://registry-1.docker.io/v2/: net/http:
        request canceled while waiting for connection'
      reason: InternalError
      status: "False"
      type: ImportSuccess
    items: null
    tag: "3.3"
  - conditions:
    - generation: 3
      lastTransitionTime: 2016-04-12T05:49:45Z
      message: 'Internal error occurred: Get https://registry-1.docker.io/v2/: net/http:
        request canceled while waiting for connection'
      reason: InternalError
      status: "False"
      type: ImportSuccess
    items: null
    tag: latest

Comment 3 XiaochuanWang 2016-05-25 08:46:19 UTC
Tested on latest origin and still reproduced "The import completed successfully."
kubernetes v1.3.0-alpha.1-331-g0522e63
etcd 2.3.0
oc v1.3.0-alpha.0-669-g6e74aa4

Comment 4 Maciej Szulik 2016-09-08 12:08:17 UTC
We can't return 1, because most of the times we're importing multiple images at the time and it's hard to say what's the actual result should be in that case. Thus I've modified the output to reflect the actual status. See https://github.com/openshift/origin/pull/10847

Comment 5 openshift-github-bot 2016-09-30 03:52:41 UTC
Commits pushed to master at https://github.com/openshift/origin

https://github.com/openshift/origin/commit/584e1cb597b92cfff9ccc2a5ad9d4bdd47bd251f
Bug 1312230 - fix image import command to reflect the actual status

https://github.com/openshift/origin/commit/fc46190a9ef455888b5fcf8e3b24dac2651801cc
Merge pull request #10847 from soltysh/bug1312230

Merged by openshift-bot

Comment 6 XiaochuanWang 2016-10-08 02:32:49 UTC
verified on latest origin: openshift/oc v1.4.0-alpha.0+b1ed662

$ oc import-image pyfake
The import completed with errors.

Name:			pyfake
Namespace:		xiaocwan-t
Created:		35 seconds ago
Labels:			<none>
Annotations:		openshift.io/image.dockerRepositoryCheck=2016-10-08T02:31:12Z
Docker Pull Spec:	172.30.169.86:5000/xiaocwan-t/pyfake
Unique Images:		0
Tags:			2

latest
  tagged from wsun/non-existen-image

  ! error: Import failed (Unauthorized): you may not have access to the Docker image "wsun/non-existen-image"
      1 seconds ago

3.3
  tagged from wsun/pythonlol-33-centos

  wsun tests

  ! error: Import failed (Unauthorized): you may not have access to the Docker image "wsun/pythonlol-33-centos"
      33 seconds ago