Merge pull request #67137 from juanvallejo/jvallejo/usability-fix-kube-get

Automatic merge from submit-queue (batch tested with PRs 67137, 67372, 67505, 67373, 67357). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

prevent "No resources found" output on forbidden error

**Release note**:
```release-note
NONE
```

This was originally fixed in https://github.com/kubernetes/kubernetes/pull/35115, but made its way back. Added a small test

cc @soltysh
pull/8/head
Kubernetes Submit Queue 2018-08-16 10:34:11 -07:00 committed by GitHub
commit d3a0bb6a84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 1 deletions

View File

@ -456,7 +456,7 @@ func (o *GetOptions) Run(f cmdutil.Factory, cmd *cobra.Command, args []string) e
} }
} }
w.Flush() w.Flush()
if nonEmptyObjCount == 0 && !o.IgnoreNotFound { if nonEmptyObjCount == 0 && !o.IgnoreNotFound && len(allErrs) == 0 {
fmt.Fprintln(o.ErrOut, "No resources found.") fmt.Fprintln(o.ErrOut, "No resources found.")
} }
return utilerrors.NewAggregate(allErrs) return utilerrors.NewAggregate(allErrs)

View File

@ -72,6 +72,10 @@ run_kubectl_get_tests() {
# Pre-condition: no pods exist # Pre-condition: no pods exist
kube::test::get_object_assert pods "{{range.items}}{{$id_field}}:{{end}}" '' kube::test::get_object_assert pods "{{range.items}}{{$id_field}}:{{end}}" ''
# Command # Command
output_message=$(! kubectl get foobar 2>&1 "${kube_flags[@]}")
# Post-condition: The text "No resources found" should not be part of the output when an error occurs
kube::test::if_has_not_string "${output_message}" 'No resources found'
# Command
output_message=$(kubectl get pods 2>&1 "${kube_flags[@]}") output_message=$(kubectl get pods 2>&1 "${kube_flags[@]}")
# Post-condition: The text "No resources found" should be part of the output # Post-condition: The text "No resources found" should be part of the output
kube::test::if_has_string "${output_message}" 'No resources found' kube::test::if_has_string "${output_message}" 'No resources found'