Open
Description
What happened:
kubectl get exit code does not match what the --help
description says will happen.
kubectl get -h
...
--ignore-not-found=false:
If the requested object does not exist the command will return exit code 0.
$ kubectl get pod --ignore-not-found=true ; echo "==>exit code=$?"
==>exit code=0
$ kubectl get pod --ignore-not-found=false ; echo "==>exit code=$?"
No resources found in default namespace.
==>exit code=0
$ kubectl get pod -l foo=bar --ignore-not-found=true ; echo "==>exit code=$?"
==>exit code=0
$ kubectl get pod -l foo=bar --ignore-not-found=false ; echo "==>exit code=$?"
No resources found in default namespace.
==>exit code=0
$ kubectl get pod foo --ignore-not-found=true ; echo "==>exit code=$?"
==>exit code=0
$ kubectl get pod foo --ignore-not-found=false ; echo "==>exit code=$?"
Error from server (NotFound): pods "foo" not found
==>exit code=1
What you expected to happen:
The requested object does not exist (there are no pods). And yet, --ignore-not-found=false
still results in an exit code of 0. Although --ignore-not-found
does change the stdout behavior (error messages are printed out or not), the exit code doesn't match expectations of the documentation regarding the exit code.
How to reproduce it (as minimally and precisely as possible):
See above. Just don't have any pods in the default namespace.
Environment:
kubectl version v1.29.1