Bug 1579515

Summary: Unexpected error when sort-by and -o yaml provided
Product: OpenShift Container Platform Reporter: Clayton Coleman <ccoleman>
Component: ocAssignee: Maciej Szulik <maszulik>
Status: CLOSED ERRATA QA Contact: zhou ying <yinzhou>
Severity: low Docs Contact:
Priority: unspecified    
Version: 3.10.0CC: aos-bugs, jokerman, maszulik, mmccomas
Target Milestone: ---   
Target Release: 3.10.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: No Doc Update
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2019-04-09 23:40:43 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 Clayton Coleman 2018-05-17 20:14:10 UTC
I got an error when running oc get events in 3.10 against a 3.10 server:

$ oc get events --all-namespaces --sort-by '{.metadata.creationTimestamp}' -o json
error: unexpected path string, expected a 'name1.name2' or '.name1.name2' or '{name1.name2}' or '{.name1.name2}'

Unexpected.

Comment 1 Juan Vallejo 2018-05-17 21:47:33 UTC
Moving severity to low, as the workaround for this is to not wrap the jsonpath in "{ }".

This is caused in origin because the "SortingPrinter" is instantiated with the user-specified key already wrapped in braces [1]. So the value `--sort-by {.metadata.name}` ends up being parsed as `{{.metadata.name}}`.

I have opened a PR upstream that restores expected behavior [2].

1. https://github.com/openshift/origin/blob/master/vendor/k8s.io/kubernetes/pkg/kubectl/cmd/util/printing.go#L231

2. https://github.com/kubernetes/kubernetes/pull/64001

Comment 2 Juan Vallejo 2018-05-18 20:48:01 UTC
Origin PR: https://github.com/openshift/origin/pull/19777

Comment 4 Maciej Szulik 2019-02-27 21:51:10 UTC
Fix landed in 3.10, moving to qa.

Comment 5 zhou ying 2019-02-28 05:34:34 UTC
The issue has fixed with ocp 3.10:
[root@qe-yinzhou-310-master-etcd-1 ~]# oc version
oc v3.10.118
kubernetes v1.10.0+b81c8f8
features: Basic-Auth GSSAPI Kerberos SPNEGO

Server https://qe-yinzhou-310-master-etcd-1:8443
openshift v3.10.118
kubernetes v1.10.0+b81c8f8
[root@qe-yinzhou-310-master-etcd-1 ~]# oc get events --all-namespaces --sort-by '{.metadata.creationTimestamp}'  -o json
{
    "apiVersion": "v1",
    "items": [
        {
            "apiVersion": "v1",
            "count": 1,
            "eventTime": null,
            "firstTimestamp": "2019-02-28T03:39:10Z",
            "involvedObject": {
                "apiVersion": "v1",
                "fieldPath": "spec.containers{sync}",
                "kind": "Pod",
                "name": "sync-k2pbr",
                "namespace": "openshift-node",
                "resourceVersion": "1501",
                "uid": "687f168f-3b0a-11e9-9d88-fa163e5976d9"
            },
            "kind": "Event",
......

Comment 7 errata-xmlrpc 2019-04-09 23:40:43 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:0620