some kubectl stdOut messages are sent to stdErr #1667
Labels
kind/bug
Categorizes issue or PR as related to a bug.
needs-triage
Indicates an issue or PR lacks a `triage/foo` label and requires one.
What happened
Attempted to use GNU/Bash command substitution to assign the output of a command to a variable:
This results in the message being printed to
stdErr
and nothing being assigned to the variableyo
.$
After redirecting
stdErr
back tostdOut
the issue is resolved:What you expected to happen:
The message to the user "No resources found in kube-public namespace." should be sent through
stdOut
.How to reproduce it (as minimally and precisely as possible):
See above.
Anything else we need to know?:
For reference, even given a similar command with a resulting failure, like searching for namespace
foo
(and there is no namespacefoo
) should even be sent tostdOut
(if there is a message) and accompanied by exitstatus:1
;kubectl
is telling the human something important.If there is nothing to share with the user (no messages printed to the terminal) then simple exit with
status:1
and move on.For Reference:
The most programmatically friendly thing to do is:
kubectl
messages (errors and everything) tostdOut
, andkubectl
has nothing to share with the human (rarely) THAT should exit withstatus:1
.Example
Given these conditions:
grep
will indicate success with a message and exit status:In this case the succeeding operation outputs a message to the user:
a2 b2 c2
.In this case there is nothing to share with the user; the purpose of the operation failed to return anything. But, given the exit status, we can make subsequent automation decisions on the exit status - simple.
Please see excerpts from our bible, The Linux Programming Interface. While this excerpt only explains the mechanics, the
grep
example supports historic implementation.I'd be interested in hearing from those with more gray hairs than me about the
whys
behind the historic bits.Environment:
kubectl version
):Client Version: v1.31.0
cat /etc/os-release
):macOS Sonoma/14.6.1
The text was updated successfully, but these errors were encountered: