Bug 1900755

Summary: Wrong output when using jsonpath with "oc get".
Product: OpenShift Container Platform Reporter: Sergio G. <sgarciam>
Component: ocAssignee: Robin Cernin <rcernin>
Status: CLOSED NOTABUG QA Contact: zhou ying <yinzhou>
Severity: medium Docs Contact:
Priority: medium    
Version: 4.6.zCC: aos-bugs, fkrepins, jokerman, maszulik, mfojtik, rcernin
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2021-08-09 13:19:56 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 Sergio G. 2020-11-23 16:33:04 UTC
Description of problem:
When parsing a list with jsonpath a extra empty item is included.


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


How reproducible:
Always


Steps to Reproduce:
$ openshift-client-linux-4.6.4 get -n openshift-oauth-apiserver po -o jsonpath='{range .items[?(.status.phase=="Running")]}{.metadata.name}{" is Running\n"}'
apiserver-655f678dd-6s2lt is Running
apiserver-655f678dd-7krvg is Running
apiserver-655f678dd-pzvph is Running
 is Running

Expected results:
No last line with empty .metadata.name


Additional info:
This doesn't happen with 4.5 client:
$ openshift-client-linux-4.5.19 get -n openshift-oauth-apiserver po -o jsonpath='{range .items[?(.status.phase=="Running")]}{.metadata.name}{" is Running\n"}'
apiserver-655f678dd-6s2lt is Running
apiserver-655f678dd-7krvg is Running
apiserver-655f678dd-pzvph is Running


Confirmed every single 4.6.z version of oc and kubectl packed in the download tgz from mirror.openshift.com.


For more information, I've noticed that there's one dependency related with json that has been upgraded in the change from oc-4.5-kubernetes-1.18.8 to oc-4.6-kubernetes-1.19 in openshift/kubernetes-kubectl. The dependency is github.com/json-iterator/go which has been upgraded from rev v1.1.18 to v1.1.10. Not sure if the issue comes from there, but I haven't found any other hint in our code.

Comment 1 Maciej Szulik 2020-12-04 16:30:21 UTC
I’m adding UpcomingSprint, because I was occupied by fixing bugs with higher priority/severity, developing new features with higher priority, or developing new features to improve stability at a macro level. I will revisit this bug next sprint.

Comment 4 Maciej Szulik 2021-01-14 11:31:13 UTC
A(In reply to Robin Cernin from comment #2)
> I proposed a PR upstream https://github.com/kubernetes/kubernetes/pull/98057

Awesome, I'll have a look at it sometime soon-ish :-) Thanks!

Comment 13 Maciej Szulik 2021-04-29 12:21:39 UTC
I'm hoping to get to this sometime next week.

Comment 14 Robin Cernin 2021-06-03 00:48:08 UTC
Merged upstream in https://github.com/kubernetes/kubernetes/pull/98057

Comment 15 Maciej Szulik 2021-06-08 11:18:53 UTC
We should get it along with k8s 1.22 bump, in that case.

Comment 16 Filip Krepinsky 2021-08-05 16:54:28 UTC
the original problem doesn't seem like a bug because it is using incorrect jsonpath syntax. It is missing the {end} element. Please see https://kubernetes.io/docs/reference/kubectl/jsonpath/.

The fix for this however caused a bug in one of our tests: https://bugzilla.redhat.com/show_bug.cgi?id=1989505.

I have posted a PR for reverting the original fix: https://github.com/kubernetes/kubernetes/pull/104172

I propose closing this bug as not a bug.

Comment 17 Maciej Szulik 2021-08-09 13:19:56 UTC
Based on previous comment I'm closing this as not a bug. The original problem was that the jsonpath statement was missing {end}.