mirror of
https://github.com/optim-enterprises-bv/kubernetes.git
synced 2025-11-02 03:08:15 +00:00
Merge pull request #40551 from juanvallejo/jvallejo/only-output-no-resources-found-for-human-readable-printer
Automatic merge from submit-queue (batch tested with PRs 40691, 40551, 40683, 40700, 40702)
only output "No resources found." for human readable printers
**Release note**:
```release-note
release note none
```
This patch removes the message `No resources found` (currently printed through stderr) when printing through a generic / non-human-readable printer (json, yaml, jsonpath, custom-columns).
**Before***
```
$ kubectl get pods -o json
No resources found.
{
"apiVersion": "v1",
"items": [],
"kind": "List",
"metadata": {},
"resourceVersion": "",
"selfLink": ""
}
```
**After**
```
$ kubectl get pods -o json
{
"apiVersion": "v1",
"items": [],
"kind": "List",
"metadata": {},
"resourceVersion": "",
"selfLink": ""
}
```
cc @fabianofranz @stevekuznetsov
This commit is contained in:
@@ -1037,6 +1037,46 @@ run_kubectl_get_tests() {
|
||||
# Post-condition: POD abc should error since it doesn't exist
|
||||
kube::test::if_has_string "${output_message}" 'pods "abc" not found'
|
||||
|
||||
### Test retrieval of pods when none exist with non-human readable output format flag specified
|
||||
# Pre-condition: no pods exist
|
||||
kube::test::get_object_assert pods "{{range.items}}{{$id_field}}:{{end}}" ''
|
||||
# Command
|
||||
output_message=$(kubectl get pods 2>&1 "${kube_flags[@]}" -o json)
|
||||
# Post-condition: The text "No resources found" should not be part of the output
|
||||
kube::test::if_has_not_string "${output_message}" 'No resources found'
|
||||
# Command
|
||||
output_message=$(kubectl get pods 2>&1 "${kube_flags[@]}" -o yaml)
|
||||
# Post-condition: The text "No resources found" should not be part of the output
|
||||
kube::test::if_has_not_string "${output_message}" 'No resources found'
|
||||
# Command
|
||||
output_message=$(kubectl get pods 2>&1 "${kube_flags[@]}" -o name)
|
||||
# Post-condition: The text "No resources found" should not be part of the output
|
||||
kube::test::if_has_not_string "${output_message}" 'No resources found'
|
||||
# Command
|
||||
output_message=$(kubectl get pods 2>&1 "${kube_flags[@]}" -o jsonpath='{.items}')
|
||||
# Post-condition: The text "No resources found" should not be part of the output
|
||||
kube::test::if_has_not_string "${output_message}" 'No resources found'
|
||||
# Command
|
||||
output_message=$(kubectl get pods 2>&1 "${kube_flags[@]}" -o go-template='{{.items}}')
|
||||
# Post-condition: The text "No resources found" should not be part of the output
|
||||
kube::test::if_has_not_string "${output_message}" 'No resources found'
|
||||
# Command
|
||||
output_message=$(kubectl get pods 2>&1 "${kube_flags[@]}" -o custom-columns=NAME:.metadata.name)
|
||||
# Post-condition: The text "No resources found" should not be part of the output
|
||||
kube::test::if_has_not_string "${output_message}" 'No resources found'
|
||||
|
||||
### Test retrieval of pods when none exist, with human-readable output format flag specified
|
||||
# Pre-condition: no pods exist
|
||||
kube::test::get_object_assert pods "{{range.items}}{{$id_field}}:{{end}}" ''
|
||||
# Command
|
||||
output_message=$(kubectl get pods 2>&1 "${kube_flags[@]}")
|
||||
# Post-condition: The text "No resources found" should be part of the output
|
||||
kube::test::if_has_string "${output_message}" 'No resources found'
|
||||
# Command
|
||||
output_message=$(kubectl get pods 2>&1 "${kube_flags[@]}" -o wide)
|
||||
# Post-condition: The text "No resources found" should be part of the output
|
||||
kube::test::if_has_string "${output_message}" 'No resources found'
|
||||
|
||||
### Test retrieval of non-existing POD with json output flag specified
|
||||
# Pre-condition: no POD exists
|
||||
kube::test::get_object_assert pods "{{range.items}}{{$id_field}}:{{end}}" ''
|
||||
|
||||
Reference in New Issue
Block a user