kubectl get all has lots of blank lines to stderr

Created on 3 Feb 2019  路  14Comments  路  Source: kubernetes/kubectl

kubectl get all will dump a list of known resources to the screen, to stdout. However, it will also print a bunch of blank lines to stderr for no apparent reason :-)
See this:

$ kubectl get all > out 2> err
$ wc out err
   97   424 10355 out
   14     0    14 err
  111   424 10369 total
[master]root@docker:~/knative/helloworld$ cat err














$

In this case it printed 14 blank lines. This is problematic because when I try to script things I now can't just grab stdout (when there are no errors) I now need to do something with stderr even though there are no errors. If we really want blank lines in the output between the resources then send it to stdout instead.

arekubectl kinbug prioritP2 sicli

Most helpful comment

@guymguym @duglin sure I'll also add a fix for the issue of showing blank lines after a section of data even when there is no data in the section to this PR

All 14 comments

/sig cli
/area kubectl
/kindbug
/priority P2

/kind bug

There is a TODO (https://github.com/kubernetes/kubernetes/blob/master/pkg/kubectl/cmd/get/get.go#L541) which I think will fix this, however I'm not sure about the impact.
-o==0 and -o=="wide" are "human readable" and not intended for scripting. For machine readable format, just append -o json or -o yaml :)

Alternatively, setting --no-headers will remove the line breaks for the time being.

Hope that helps

yes that TODO is 100% correct :-)

And while I mentioned scripting I didn't really mean "scripting to parse the output for machine usage" as much as I meant I have demo scripts that run commands and grab output for displaying it later, and having 1/2 the output go to stdout and 1/2 go to stderr (when there is no error) is problematic. Or even just to "grep-out" lines that I don't want to show people. The point is that people expect all non-errors to go to stdout - and that includes blank lines.

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

/remove-lifecycle stale

/assign

I would be ok hiding the blank lines if you specify --no-headers, but if you're getting headers back you already need to handle eliminating those and so an empty line is just another awk away.

Hey @taragu @smarterclayton
This is my output of running get all in my terminal:

> kubectl get all









No resources found.

Seems pretty clear that this is not a reasonable human readable cli output, regardless of scripting and automating, right?
And this is a new issue on 1.15. It wasn't the case for 1.14.
Thanks!

@guymguym I agree that the output you show above is an issue in the sense that we show blank lines after a section of data even when there is no data in the section, which leads to extra blanks lines. And that can be easily fixed with an "if" around the println. However, this issue isn't about that. This one is more about the fact that the blank lines go to stderr instead of stdout.

So, if you run the same command again when you do have resources, but send the output to a file ($ kubectl get all > saved.output), then you'll get the same odd UX you show above, of a ton of blank lines going to the screen. Net: there are two issues, but I was just talking about the 2nd.

@taragu would you want to submit a fix for the first?

@duglin Two issues on two adjacent lines of code - I was just deduping for less small nitty issues :) Thanks

@guymguym ah - yes, merging the other fix into the existing PR would, of course, work too! :-)

As long as it doesn't double the review time LOL

@guymguym @duglin sure I'll also add a fix for the issue of showing blank lines after a section of data even when there is no data in the section to this PR

Was this page helpful?
0 / 5 - 0 ratings