Bug 1708280 - oc get panics when fed empty list and -o=name|json|yaml|??
Summary: oc get panics when fed empty list and -o=name|json|yaml|??
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: OpenShift Container Platform
Classification: Red Hat
Component: oc
Version: 4.1.0
Hardware: Unspecified
OS: Unspecified
unspecified
high
Target Milestone: ---
: 4.2.0
Assignee: Maciej Szulik
QA Contact: zhou ying
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2019-05-09 14:07 UTC by Justin Pierce
Modified: 2019-10-16 06:28 UTC (History)
5 users (show)

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.
Clone Of:
Environment:
Last Closed: 2019-10-16 06:28:42 UTC
Target Upstream Version:


Attachments (Terms of Use)


Links
System ID Priority Status Summary Last Updated
Github openshift origin pull 22808 None None None 2019-07-31 14:14:33 UTC
Red Hat Product Errata RHBA-2019:2922 None None None 2019-10-16 06:28:57 UTC

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


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