Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kubectl get displays an empty list + returns an error when trying to get a nonexistent resource #28243

Closed
ncdc opened this issue Jun 29, 2016 · 17 comments
Labels
area/kubectl priority/critical-urgent Highest priority. Must be actively worked on as someone's top priority right now.

Comments

@ncdc
Copy link
Member

ncdc commented Jun 29, 2016

$ kubectl get pod/foo -o yaml
apiVersion: v1
items: []
kind: List
metadata: {}
pods "foo" not found

Prior to #23673 and #26686, we did not display the empty list; we only displayed the error. I'm guessing we don't want to display the empty list, do we?

@kubernetes/kubectl @kubernetes/rh-ux @kubernetes/rh-cluster-infra @smarterclayton @liggitt

@ncdc
Copy link
Member Author

ncdc commented Jun 29, 2016

cc @deads2k

@smarterclayton
Copy link
Contributor

We don't, asking for a singular resource is an error and should not print
the list.

On Jun 29, 2016, at 2:39 PM, Andy Goldstein notifications@github.com
wrote:

$ kubectl get pod/foo -o yaml
apiVersion: v1
items: []
kind: List
metadata: {}
pods "foo" not found

Prior to #23673 #23673 and
#26686 #26686, we did not
display the empty list; we only displayed the error. I'm guessing we don't
want to display the empty list, do we?

@kubernetes/kubectl https://github.com/orgs/kubernetes/teams/kubectl
@kubernetes/rh-ux https://github.com/orgs/kubernetes/teams/rh-ux
@kubernetes/rh-cluster-infra
https://github.com/orgs/kubernetes/teams/rh-cluster-infra @smarterclayton
https://github.com/smarterclayton @liggitt https://github.com/liggitt


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#28243, or mute the thread
https://github.com/notifications/unsubscribe/ABG_p7dVNXmxYfSc3QrQszTKpmerDMiqks5qQuYLgaJpZM4JBl_I
.

@ncdc
Copy link
Member Author

ncdc commented Jun 30, 2016

I have a local change that does this:

vagrant@f24:~/go/src/k8s.io/kubernetes (master) k get pod/foo -o yaml
Error from server: pods "foo" not found

vagrant@f24:~/go/src/k8s.io/kubernetes (master) k get pod/foo pod/bar -o yaml
apiVersion: v1
items: []
kind: List
metadata: {}
[pods "foo" not found, pods "bar" not found]

It still seems a little strange, if you ask me... Also, if you mix getting a pod that does exist with one that does not:

vagrant@f24:~/go/src/k8s.io/kubernetes (master) k get pod/date pod/no -a
NAME      READY     STATUS      RESTARTS   AGE
date      0/1       Completed   0          58s
pods "no" not found

vagrant@f24:~/go/src/k8s.io/kubernetes (master) echo $?
1

Is this acceptable?

@sttts
Copy link
Contributor

sttts commented Jun 30, 2016

IMO it's more natural to have no list for k get pod/foo pod/bar -o yaml.

Also the error message "pods not found" is strange.

@ncdc
Copy link
Member Author

ncdc commented Jun 30, 2016

Yeah, I think if you ask for a list of things and they're all 404, it probably makes sense to return no list. What about in my 2nd example, where you ask for 2 pods and it can only find 1?

Agreed about the error message, but let's leave that oddity for another issue if that's ok? 😄

@deads2k
Copy link
Contributor

deads2k commented Jun 30, 2016

It still seems a little strange, if you ask me...

I think its a little weird that asking for one resource by name and getting no results is different than asking for two resources by name and getting no results.

@sttts
Copy link
Contributor

sttts commented Jun 30, 2016

For the text output the behavior is certainly fine to print out 1 pod + 1 error.

@sttts
Copy link
Contributor

sttts commented Jun 30, 2016

An alternative to get it consistent: print an empty yaml list also for k get pod/foo -o yaml

@ncdc
Copy link
Member Author

ncdc commented Jun 30, 2016

An alternative to get it consistent: print an empty yaml list also for k get pod/foo -o yaml

That's what master currently does

@sttts
Copy link
Contributor

sttts commented Jun 30, 2016

Oh right, that's what this issue is all about :)

@deads2k
Copy link
Contributor

deads2k commented Jun 30, 2016

An alternative to get it consistent: print an empty yaml list also for k get pod/foo -o yaml

You could also go the other way and have no list output if you requested single resources that all 404.

Truth be told the empty list plus error plus non-zero return code doesn't bother me.

@akostadinov
Copy link

I think printing empty list when one resource was requested is a bad thing. It basically returns different data type than requested by user. In the one case it is a single resource and in the other case it is a list. A script can certainly handle that but it looks ugly and inconsistent to me.
Another thing is that returning different exit code depending on data format requested is also weird and can confuse scripts.
Lastly this is a breaking change for scripts from previous version. I think such changes need to be justified by some tangible improvements to user experience. And I don't see any improvement by this change in behavior.

IMO if specific resource is explicitly requested by user and is not found (regardless if user requested 2, 3 or more resources), then command should return an error exit code and a string of some sort containing "not found" (as before). Now if you list by label, it is perfectly fine to return success with empty list. That's like ls will list files in a directory and will return 0 when none files are in there. But if you do ls nonhere it will return an error. Also with multiple items:

$ ls pohvali asdff
ls: cannot access asdff: No such file or directory
pohvali
$ echo $?
2

-- my two cents

@bgrant0607
Copy link
Member

cc @metral @janetkuo @erictune

@bgrant0607 bgrant0607 added the priority/critical-urgent Highest priority. Must be actively worked on as someone's top priority right now. label Jun 30, 2016
@metral
Copy link
Contributor

metral commented Jun 30, 2016

There are currently 2 open PR's that resolve this issue: #28251 and #28294, where the latter has additional tests for test-cmd.sh.

Think we're just waiting on someone more informed to advise which route is preferred, and then merging that PR in

@ncdc
Copy link
Member Author

ncdc commented Jun 30, 2016

+1

@smarterclayton
Copy link
Contributor

"singular" is the signal that the user asked for a single item, so we should return an error (instead of displaying empty lists).

kubectl get pods/foo -> singular, error
kubectl get pods -> not singular, no error
kubectl get -f pod_with_one_item.yaml -> singular, error
kubectl get -f directory -> not singular
kubectl get -f list_with_many_items -> not singular

@akostadinov
Copy link

@smarterclayton , besides singular, we need to also account for "specific". I liked most the idea to be like ls. Show a list of items that were found but print on stderr error messages and return non-zero status.

k8s-github-robot pushed a commit that referenced this issue Jul 1, 2016
…luar

Automatic merge from submit-queue

kubectl: don't display an empty list when trying to get a single resource that isn't found

Return immediately when attempting to get a singular resource that isn't found, so that we avoid
printing out a List if the output format is something like json or yaml.

Before:

```
$ kubectl get pod/foo -o yaml
apiVersion: v1
items: []
kind: List
metadata: {}
pods "foo" not found
```

After:

```
$ kubectl get pod/foo -o yaml
pods "foo" not found
```

Fixes #28243 

@kubernetes/kubectl @kubernetes/rh-ux @smarterclayton @liggitt @deads2k @metral
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/kubectl priority/critical-urgent Highest priority. Must be actively worked on as someone's top priority right now.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants