From df0077f362f34f1b274f905c90622405de5df8a6 Mon Sep 17 00:00:00 2001 From: juanvallejo Date: Wed, 8 Aug 2018 10:26:20 -0400 Subject: [PATCH] prevent "No resources found" output on forbidden error --- pkg/kubectl/cmd/get/get.go | 2 +- test/cmd/get.sh | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/kubectl/cmd/get/get.go b/pkg/kubectl/cmd/get/get.go index f28db78081..eccfaffcfe 100644 --- a/pkg/kubectl/cmd/get/get.go +++ b/pkg/kubectl/cmd/get/get.go @@ -454,7 +454,7 @@ func (o *GetOptions) Run(f cmdutil.Factory, cmd *cobra.Command, args []string) e } } w.Flush() - if nonEmptyObjCount == 0 && !o.IgnoreNotFound { + if nonEmptyObjCount == 0 && !o.IgnoreNotFound && len(allErrs) == 0 { fmt.Fprintln(o.ErrOut, "No resources found.") } return utilerrors.NewAggregate(allErrs) diff --git a/test/cmd/get.sh b/test/cmd/get.sh index 0e7f8018ad..e42b0ea27f 100755 --- a/test/cmd/get.sh +++ b/test/cmd/get.sh @@ -72,6 +72,10 @@ run_kubectl_get_tests() { # Pre-condition: no pods exist kube::test::get_object_assert pods "{{range.items}}{{$id_field}}:{{end}}" '' # 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[@]}") # Post-condition: The text "No resources found" should be part of the output kube::test::if_has_string "${output_message}" 'No resources found'