Bug 1923054 - oc returns an error while using -o jsonpath when there is no resource found in the namespace
Summary: oc returns an error while using -o jsonpath when there is no resource found i...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: OpenShift Container Platform
Classification: Red Hat
Component: oc
Version: 4.6
Hardware: Unspecified
OS: Unspecified
medium
medium
Target Milestone: ---
: 4.6.z
Assignee: Maciej Szulik
QA Contact: RamaKasturi
URL:
Whiteboard:
Depends On: 1922573
Blocks:
TreeView+ depends on / blocked
 
Reported: 2021-02-01 10:50 UTC by Maciej Szulik
Modified: 2021-02-22 13:55 UTC (History)
5 users (show)

Fixed In Version:
Doc Type: No Doc Update
Doc Text:
Clone Of:
Environment:
Last Closed: 2021-02-22 13:54:57 UTC
Target Upstream Version:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Github openshift oc pull 724 0 None closed [release-4.6] Bug 1923054: Fix error in jsonpath when object is empty 2021-02-19 00:08:50 UTC
Red Hat Product Errata RHBA-2021:0510 0 None None None 2021-02-22 13:55:20 UTC

Description Maciej Szulik 2021-02-01 10:50:11 UTC
This bug was initially created as a copy of Bug #1922573

I am copying this bug because: 



Description of problem:
oc command returns the following error while using -o jsonpath when there is no resource found in the namespace.

$ oc version
Client Version: 4.6.8
Server Version: 4.6.8
Kubernetes Version: v1.19.0+7070803
$ oc get pods
No resources found in test namespace.
$ oc get pod -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}'
error: error executing jsonpath "{range .items[*]}{.metadata.name}{\"\\n\"}{end}": Error executing template: not in range, nothing to end. Printing more information for debugging the template:
        template was:
                {range .items[*]}{.metadata.name}{"\n"}{end}
        object given to jsonpath engine was:
                map[string]interface {}{"apiVersion":"v1", "items":[]interface {}{}, "kind":"List", "metadata":map[string]interface {}{"resourceVersion":"", "selfLink":""}}
$

The same error doesn't occur in the 4.5 oc CLI.

$ oc version
Client Version: 4.5.24
Server Version: 4.5.24
Kubernetes Version: v1.18.3+fa69cae
$ oc get pods
No resources found in test namespace.
$ oc get pod -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}'
$

And the 4.7 oc CLI neither.

$ ./oc version
Client Version: 4.7.0-fc.2
Server Version: 4.6.8
Kubernetes Version: v1.19.0+7070803
$ ./oc get pods
No resources found in test namespace.
$ ./oc get pod -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}'
$

It seems that this bug has been fixed in 4.7 and it would be necessary to back-port this fix to 4.6 too.

See also: https://github.com/kubernetes/kubernetes/issues/95882

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


How reproducible:
Always

Steps to Reproduce:
1. Create a new project

$ oc new-project test

2. run oc command with -o jsonpath

$ oc get pod -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}'

Actual results:
Error occurs.

Expected results:
oc command finished with empty result and no error occurs.

Additional info:

Comment 1 Maciej Szulik 2021-02-05 14:05:38 UTC
PR in the queue.

Comment 2 zhou ying 2021-02-07 05:48:51 UTC
Make the oc with the related PR , the issue has fixed:

[root@dhcp-140-138 oc]# ./oc version 
Client Version: 4.6.0-20210207
Server Version: 4.7.0-0.nightly-2021-02-03-165316
Kubernetes Version: v1.20.0+e761892
[root@dhcp-140-138 oc]# ./oc get pod -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}'
[root@dhcp-140-138 oc]# echo $?
0


Compared with the oc without the pr , could still reproduce the issue:
[root@dhcp-140-138 oc]# oc version --client
Client Version: 4.6.0-202102050644.p0-e12ee36
[root@dhcp-140-138 oc]# oc get pod -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}'
error: error executing jsonpath "{range .items[*]}{.metadata.name}{\"\\n\"}{end}": Error executing template: not in range, nothing to end. Printing more information for debugging the template:
	template was:
		{range .items[*]}{.metadata.name}{"\n"}{end}
	object given to jsonpath engine was:
		map[string]interface {}{"apiVersion":"v1", "items":[]interface {}{}, "kind":"List", "metadata":map[string]interface {}{"resourceVersion":"", "selfLink":""}}

Comment 4 RamaKasturi 2021-02-12 18:05:07 UTC
Verified with the latest payload below and i see that the issue has fixed.

[knarra@knarra openshift-client-linux-4.6.0-0.nightly-2021-02-12-054943]$ ./oc version -o yaml
clientVersion:
  buildDate: "2021-02-12T03:16:13Z"
  compiler: gc
  gitCommit: aaa9ca377e9816a2501ce3f5dda3f889618b6a37
  gitTreeState: clean
  gitVersion: 4.6.0-202102120217.p0-aaa9ca3
  goVersion: go1.15.5
  major: ""
  minor: ""
  platform: linux/amd64
openshiftVersion: 4.6.0-0.nightly-2021-02-12-073026
releaseClientVersion: 4.6.0-0.nightly-2021-02-12-054943
serverVersion:
  buildDate: "2021-02-11T22:10:37Z"
  compiler: gc
  gitCommit: f173eb4a83e55734ee6808a1ed7674be9a4cd0bf
  gitTreeState: clean
  gitVersion: v1.19.0+f173eb4
  goVersion: go1.15.5
  major: "1"
  minor: "19"
  platform: linux/amd64

[knarra@knarra openshift-client-linux-4.6.0-0.nightly-2021-02-12-054943]$ ./oc get pod -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}'
[knarra@knarra openshift-client-linux-4.6.0-0.nightly-2021-02-12-054943]$ 

with older version of oc(4.6.8), the issue is reproducible:
============================================================
[knarra@knarra openshift-client-linux-4.6.8]$ ./oc get pod -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}'
error: error executing jsonpath "{range .items[*]}{.metadata.name}{\"\\n\"}{end}": Error executing template: not in range, nothing to end. Printing more information for debugging the template:
	template was:
		{range .items[*]}{.metadata.name}{"\n"}{end}
	object given to jsonpath engine was:
		map[string]interface {}{"apiVersion":"v1", "items":[]interface {}{}, "kind":"List", "metadata":map[string]interface {}{"resourceVersion":"", "selfLink":""}}

Based on the above moving bug to verified state.

Comment 7 errata-xmlrpc 2021-02-22 13:54:57 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 (OpenShift Container Platform 4.6.18 bug fix update), 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-2021:0510


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