Bug 1289456 - "--sort-by" option does not take effect for oc get, oc run etc
"--sort-by" option does not take effect for oc get, oc run etc
Status: CLOSED CURRENTRELEASE
Product: OpenShift Origin
Classification: Red Hat
Component: Pod (Show other bugs)
3.x
Unspecified Unspecified
medium Severity low
: ---
: ---
Assigned To: Avesh Agarwal
Jianwei Hou
:
Depends On:
Blocks: 1332828
  Show dependency treegraph
 
Reported: 2015-12-08 02:50 EST by Xingxing Xia
Modified: 2016-09-19 09:49 EDT (History)
3 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 1332828 (view as bug list)
Environment:
Last Closed: 2016-09-19 09:49:46 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Xingxing Xia 2015-12-08 02:50:49 EST
Description of problem:
"--sort-by" option does not take effect for oc get. The result keeps the same when giving any value to this option.
oc new-build, oc get,oc label, oc expose, oc export,oc run,oc convert all have this option and issue.

Version-Release number of selected component (if applicable):
openshift/oc v1.1-366-g9db1116
kubernetes v1.1.0-origin-1107-g4c8e6f4

How reproducible:
Always

Steps to Reproduce:
1. Start openshift, oc login, create a project
2. Create a new app
$ oc new-app -f origin/examples/sample-app/application-template-stibuild.json
3. Check --sort-by with various kinds of value
$ oc get pod --sort-by="{medadata.creationTimestamp}"
$ oc get pod --sort-by="$%#@&&"

Actual results:
3. Regardless of the option value, the result is the same:
NAME               READY     STATUS    RESTARTS   AGE
database-1-wylo8   1/1       Running   0          37m
frontend-1-knv3g   1/1       Running   0         37m
frontend-1-x7ih5   1/1       Running   0         37m
ruby-sample-build-1-build   0/1       Completed   0         38m

Expected results:
3. Should recognize the option value and sort the output.

Additional info:
Comment 1 Avesh Agarwal 2016-01-27 14:38:13 EST
I have tested this on latest kubernetes and origin code bases today, it seems that creationTimestamp and "$%#@&&" are not a valid thing for sort-by, and it is consistent with both kube and origin. 

The link https://github.com/kubernetes/kubernetes/blob/master/docs/user-guide/kubectl-overview.md gives guidelines for how to use it sort-by.

By now, I do not see any issue with sort-by. Honestly I have not tried all sort of options with sort-by, but if you have something specific, please let me know, I will try them.

Note: there is a typo in the description: medadata->metadata 

To reproduce on origin (master and node on VM):
1. openshift start master --write-config=./openshift.local.config/master
2. oadm create-node-config --node-dir=./openshift.local.config/node-192.168.122.253 --node=192.168.122.253 --hostnames=192.168.122.253
3. openshift start master --config=./openshift.local.config/master/master-config.yaml
4. (In another terminal) openshift start node --config=./openshift.local.config/node-192.168.122.253/node-config.yaml 
5. (In another terminal) 

[root@localhost origin]# oc get pods --sort-by=.metadata.creationTimestamp  --config=./openshift.local.config/master/admin.kubeconfig 
F0127 14:29:14.925363    8841 sorting_printer.go:182] Field {.metadata.creationTimestamp} in &{{ } {bwide-pause-rc-tu940 bwide-pause-rc- default /api/v1/namespaces/default/pods/bwide-pause-rc-tu940 7cb06865-c52b-11e5-88d4-5254005eb708 243 0 2016-01-27 14:23:47 -0500 EST <nil> <nil> map[name:bwide-pause-ls] map[kubernetes.io/created-by:{"kind":"SerializedReference","apiVersion":"v1","reference":{"kind":"ReplicationController","namespace":"default","name":"bwide-pause-rc","uid":"7cafa9d5-c52b-11e5-88d4-5254005eb708","apiVersion":"v1","resourceVersion":"232"}}
 openshift.io/scc:restricted]} {[{default-token-sz7xs {<nil> <nil> <nil> <nil> <nil> 0xc820316f80 <nil> <nil> <nil> <nil> <nil> <nil> <nil> <nil> <nil> <nil>}}] [{bwide-pause-c gcr.io/google_containers/pause:2.0 [] []  [] [] {map[] map[]} [{default-token-sz7xs true /var/run/secrets/kubernetes.io/serviceaccount}] <nil> <nil> <nil> /dev/termination-log IfNotPresent 0xc82023d530 false false false}] Always 0xc820317470 <nil> ClusterFirst map[] default 192.168.122.253 0xc8200b6b80 [{default-dockercfg-gtsr8}]} {Running [{Ready True 0001-01-01 00:00:00 +0000 UTC 2016-01-27 14:23:52 -0500 EST  }]   192.168.122.253 172.17.0.2 2016-01-27 14:23:47 -0500 EST [{bwide-pause-c {<nil> 0xc820264960 <nil>} {<nil> <nil> <nil>} true 0 gcr.io/google_containers/pause:2.0 docker://9981ca1bbdb5f334706905879dbd73d0146fc9327fa30d4f2021cec660dd19fc docker://39a449c69b8bcb0f88d8acbb48ffef5319c1adc4f8e9946461701bc257a8cc46}]}} is an unsortable type: struct, err: unsortable type: struct

[root@localhost origin]# oc get pods --sort-by="$%#@&&"  --config=./openshift.local.config/master/admin.kubeconfig 
error: unrecognized character in action: U+0025 '%'
Comment 2 Avesh Agarwal 2016-01-27 14:48:54 EST
Please note that creationTimestamp is infact a valid metadata, but when I say it may not be valid for sort-by just because its behaviour is consistent with kube and origin. It could be argued that it should work same way as .metadata.name for example, but i am not sure if that is intended. For example oc get events --sort-by works for --sort-by=count but not for --sort-by=firstseen or lastseen. So may be sort-by is not intended (or implemented) to work with all fields or metadata types it seems to me.
Comment 3 Xingxing Xia 2016-01-29 04:08:37 EST
(In reply to Avesh Agarwal from comment #2)
> Please note that creationTimestamp is infact a valid metadata, but when I
> say it may not be valid for sort-by just because its behaviour is consistent
> with kube and origin. It could be argued that it should work same way as
> .metadata.name for example, but i am not sure if that is intended. For
> example oc get events --sort-by works for --sort-by=count but not for
> --sort-by=firstseen or lastseen. So may be sort-by is not intended (or
> implemented) to work with all fields or metadata types it seems to me.

1. At the time this bug was reported, using --sort-by="{medadata.creationTimestamp}" and --sort-by="$%#@&&", `oc get pod` did ran without error message and did not recognize them as invalid. Right now they are invalid, it may be due to the code is updated in the latest Origin version.

2. `oc get -h` shows the sort field must be an integer or a string. But it seems --sort-by only applies to OpenShift resource fields that are from kube. it cannot sort by OpenShift resource fields that are not from kube. e.g., pod/rc use Kube API, dc/bc use OpenShift API. The two get different results:
$ oc new-app -f origin/examples/sample-app/application-template-stibuild.json
$ oc scale dc database --replicas=3
$ oc get pod  --sort-by=".metadata.name"  # Works
NAME               READY     STATUS    RESTARTS   AGE
database-1-5f7yc   1/1       Running   0          29m
database-1-6uuv2   1/1       Running   0         46m
database-1-8qd84   1/1       Running   0         29m
frontend-1-8yi99   1/1       Running   0         45m
frontend-1-zit1v   1/1       Running   0         45m
$ oc get rc  --sort-by=".spec.replicas"   # Works

But:
$ oc get dc --sort-by=".metadata.name"   # Not work
error: metadata is not found
$ oc get bc --sort-by=".metadata.name"   # Not work
error: metadata is not found

3. --sort-by disturbs column indentation of the output:
$ oc run pod --image=docker.io/openshift/hello-openshift  --generator=run-pod/v1
$ oc run pod-longname --image=docker.io/openshift/hello-openshift  --generator=run-pod/v1
$ oc get pod   # Spaces indent well
NAME                        READY     STATUS      RESTARTS   AGE
pod                         1/1       Running     0          18s
pod-longname                1/1       Running     0          8s

$ oc get pod --sort-by=".metadata.name"   # Spaces not indent well
pod       1/1       Running   0         32s
pod-longname   1/1       Running   0         22s

Points 2 and 3 are problems.
Comment 4 Avesh Agarwal 2016-01-29 08:41:31 EST
I am aware of the 3rd problem, and will reproduce the 2nd one today. Thanks.
Comment 5 Avesh Agarwal 2016-02-08 02:59:48 EST
Sent following PR to fix sort-by indentation issue:
https://github.com/kubernetes/kubernetes/pull/20803
Comment 6 Avesh Agarwal 2016-02-22 13:20:18 EST
sent following PR to address metadata error issue:
https://github.com/kubernetes/kubernetes/pull/21694
Comment 7 Avesh Agarwal 2016-05-18 14:05:43 EDT
The changes (https://github.com/kubernetes/kubernetes/pull/21694) are in origin master now.
Comment 8 Xingxing Xia 2016-05-19 04:02:52 EDT
Verified with openshift v1.3.0-alpha.0-586-gcd9ea84

$ oc get dc --sort-by="{.metadata.resourceVersion}"
NAME       REVISION   REPLICAS   TRIGGERED BY
database   1          1          config
helloapp   1          1          config,image(helloapp:latest)
frontend   1          2          config,image(origin-ruby-sample:latest)

$ oc get dc database helloapp frontend -o yaml | grep 'resourceVersion: '
    resourceVersion: "502"
    resourceVersion: "580"
    resourceVersion: "634"

Points 2 and 3 in comment 3 are fixed. Thank you!

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