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:
The fix is in https://github.com/kubernetes/kubernetes/pull/95933 and is already present in 4.7 moving to modified. I'll open a clone for 4.6 backport.
Verified with the payload below and i do not see any error occurring and oc command finishes with empty result. [knarra@knarra openshift-client-linux-4.7.0-0.nightly-2021-02-02-094004]$ oc get clusterversion NAME VERSION AVAILABLE PROGRESSING SINCE STATUS version 4.7.0-0.nightly-2021-02-01-232332 True False 157m Cluster version is 4.7.0-0.nightly-2021-02-01-232332 [knarra@knarra openshift-client-linux-4.7.0-0.nightly-2021-02-02-094004]$ oc version -o yaml clientVersion: buildDate: "2021-02-01T22:03:31Z" compiler: gc gitCommit: 16402fe8dbc97e798e7ac577419db629887fe11d gitTreeState: clean gitVersion: 4.7.0-202102012119.p0-16402fe goVersion: go1.15.5 major: "" minor: "" platform: linux/amd64 serverVersion: buildDate: "2021-01-29T21:19:40Z" compiler: gc gitCommit: 3b90e69e112acdc11d13fcd9cae6aea58e02aa92 gitTreeState: clean gitVersion: v1.20.0+3b90e69 goVersion: go1.15.5 major: "1" minor: "20" platform: linux/amd64 [knarra@knarra openshift-client-linux-4.7.0-0.nightly-2021-02-02-094004]$ oc new-project knarra1 Now using project "knarra1" on server "https://api.knarrafeb02.qe.devcluster.openshift.com:6443". You can add applications to this project with the 'new-app' command. For example, try: oc new-app rails-postgresql-example to build a new example application in Ruby. Or use kubectl to deploy a simple Kubernetes application: kubectl create deployment hello-node --image=k8s.gcr.io/serve_hostname [knarra@knarra openshift-client-linux-4.7.0-0.nightly-2021-02-02-094004]$ oc get pod -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' [knarra@knarra openshift-client-linux-4.7.0-0.nightly-2021-02-02-094004]$ Based on the above moving bug to verified state.
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 (Moderate: OpenShift Container Platform 4.7.0 security, bug fix, and enhancement 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/RHSA-2020:5633