Bug 1708280

Summary: oc get panics when fed empty list and -o=name|json|yaml|??
Product: OpenShift Container Platform Reporter: Justin Pierce <jupierce>
Component: ocAssignee: Maciej Szulik <maszulik>
Status: CLOSED ERRATA QA Contact: zhou ying <yinzhou>
Severity: high Docs Contact:
Priority: unspecified    
Version: 4.1.0CC: aos-bugs, gblomqui, jokerman, mmccomas, xxia
Target Milestone: ---   
Target Release: 4.2.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Cause: Empty result list wasn't properly handled. Consequence: Invoking oc get with empty list would cause a panic. Fix: Properly handle the case with empty list. Result: oc get should not panic when dealing with empty list, but return a reasonable information about the list being empty.
Story Points: ---
Clone Of: Environment:
Last Closed: 2019-10-16 06:28:42 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:
Embargoed:

Description Justin Pierce 2019-05-09 14:07:36 UTC
Description of problem:

When `oc get -f emptylist.yaml -o=name` is provided an empty k8s List object, it panics.

panic: runtime error: index out of range

goroutine 1 [running]:
github.com/openshift/origin/vendor/k8s.io/kubernetes/pkg/kubectl/cmd/get.(*GetOptions).printGeneric(0xc4205575e0, 0xc42098ab80, 0x1, 0x1)
	/builddir/build/BUILD/openshift-git-0.509916c/_output/local/go/src/github.com/openshift/origin/vendor/k8s.io/kubernetes/pkg/kubectl/cmd/get/get.go:795 +0xf3b
github.com/openshift/origin/vendor/k8s.io/kubernetes/pkg/kubectl/cmd/get.(*GetOptions).Run(0xc4205575e0, 0x2d21240, 0xc42082a930, 0xc420962500, 0xc42150f9e0, 0x0, 0x3, 0x0, 0x0)
	/builddir/build/BUILD/openshift-git-0.509916c/_output/local/go/src/github.com/openshift/origin/vendor/k8s.io/kubernetes/pkg/kubectl/cmd/get/get.go:454 +0x1453
github.com/openshift/origin/vendor/k8s.io/kubernetes/pkg/kubectl/cmd/get.NewCmdGet.func1(0xc420962500, 0xc42150f9e0, 0x0, 0x3)
	/builddir/build/BUILD/openshift-git-0.509916c/_output/local/go/src/github.com/openshift/origin/vendor/k8s.io/kubernetes/pkg/kubectl/cmd/get/get.go:161 +0x115
github.com/openshift/origin/vendor/github.com/spf13/cobra.(*Command).execute(0xc420962500, 0xc42150f9b0, 0x3, 0x3, 0xc420962500, 0xc42150f9b0)
	/builddir/build/BUILD/openshift-git-0.509916c/_output/local/go/src/github.com/openshift/origin/vendor/github.com/spf13/cobra/command.go:760 +0x2c1
github.com/openshift/origin/vendor/github.com/spf13/cobra.(*Command).ExecuteC(0xc420643b80, 0xc421337df0, 0x13d57b9, 0xc420473e30)
	/builddir/build/BUILD/openshift-git-0.509916c/_output/local/go/src/github.com/openshift/origin/vendor/github.com/spf13/cobra/command.go:846 +0x30a
github.com/openshift/origin/vendor/github.com/spf13/cobra.(*Command).Execute(0xc420643b80, 0x2, 0xc420643b80)
	/builddir/build/BUILD/openshift-git-0.509916c/_output/local/go/src/github.com/openshift/origin/vendor/github.com/spf13/cobra/command.go:794 +0x2b
main.main()
	/builddir/build/BUILD/openshift-git-0.509916c/_output/local/go/src/github.com/openshift/origin/cmd/oc/oc.go:68 +0x554

-o=yaml and -o=json also panic.

Version-Release number of selected component (if applicable):
4.1.0-rc.0

How reproducible:
100%

Steps to Reproduce:
1. oc get pods -l doesnotexist=true -o=yaml > emptylist.yaml
2. oc get -f emptylist.yaml -o=name     # panic
3. oc get -f emptylist.yaml -o=json     # panic
4. oc get -f emptylist.yaml -o=yaml     # panic
5. cat emptylist.yaml | oc get -f - -o=name     # NO panic
6. oc get -f emptylist.yaml     # NO panic

Actual results:
The command line interface panics

Expected results:
A get on an empty list file should be consistent with input from stdin. No error / no results (or an empty list).

Additional info:
Preventing a panic here aids in programmatic use of the client binary. Several other variation behave as expected. Only a combination of -f <file> and -o seem to cause the problem.

Comment 2 Maciej Szulik 2019-05-09 17:20:36 UTC
Fix in https://github.com/openshift/origin/pull/22808

Comment 3 Maciej Szulik 2019-08-13 14:32:56 UTC
This is now addressed in:
- https://github.com/kubernetes/kubernetes/pull/77681
- https://github.com/openshift/kubernetes/pull/75
I'll open oc bump once the latter PR merges.

Comment 4 Maciej Szulik 2019-08-20 07:55:05 UTC
Merged in https://github.com/openshift/oc/pull/63 moving to qa.

Comment 5 Xingxing Xia 2019-08-21 04:53:22 UTC
Verified in oc extracted from:
oc adm release extract --command=oc registry.svc.ci.openshift.org/ocp/release:4.2.0-0.nightly-2019-08-21-040043
No panic now.

Comment 6 errata-xmlrpc 2019-10-16 06:28:42 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-2019:2922