mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 02:41:25 +00:00
Change not found output when getting non namespaced resources
Signed-off-by: Riccardo Piccoli <riccardo.piccoli@gmail.com>
This commit is contained in:
parent
5ea2d69ccd
commit
818f011a2e
@ -529,6 +529,7 @@ func (o *GetOptions) Run(f cmdutil.Factory, cmd *cobra.Command, args []string) e
|
||||
separatorWriter := &separatorWriterWrapper{Delegate: trackingWriter}
|
||||
|
||||
w := printers.GetNewTabWriter(separatorWriter)
|
||||
allResourcesNamespaced := !o.AllNamespaces
|
||||
for ix := range objs {
|
||||
var mapping *meta.RESTMapping
|
||||
var info *resource.Info
|
||||
@ -540,6 +541,7 @@ func (o *GetOptions) Run(f cmdutil.Factory, cmd *cobra.Command, args []string) e
|
||||
mapping = info.Mapping
|
||||
}
|
||||
|
||||
allResourcesNamespaced = allResourcesNamespaced && info.Namespaced()
|
||||
printWithNamespace := o.AllNamespaces
|
||||
|
||||
if mapping != nil && mapping.Scope.Name() == meta.RESTScopeNameRoot {
|
||||
@ -583,7 +585,7 @@ func (o *GetOptions) Run(f cmdutil.Factory, cmd *cobra.Command, args []string) e
|
||||
w.Flush()
|
||||
if trackingWriter.Written == 0 && !o.IgnoreNotFound && len(allErrs) == 0 {
|
||||
// if we wrote no output, and had no errors, and are not ignoring NotFound, be sure we output something
|
||||
if !o.AllNamespaces {
|
||||
if allResourcesNamespaced {
|
||||
fmt.Fprintln(o.ErrOut, fmt.Sprintf("No resources found in %s namespace.", o.Namespace))
|
||||
} else {
|
||||
fmt.Fprintln(o.ErrOut, fmt.Sprintf("No resources found"))
|
||||
|
@ -591,6 +591,32 @@ func TestNoBlankLinesForGetAll(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNotFoundMessageForGetNonNamespacedResources(t *testing.T) {
|
||||
tf := cmdtesting.NewTestFactory().WithNamespace("test")
|
||||
defer tf.Cleanup()
|
||||
|
||||
codec := scheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
|
||||
tf.UnstructuredClient = &fake.RESTClient{
|
||||
NegotiatedSerializer: resource.UnstructuredPlusDefaultContentConfig().NegotiatedSerializer,
|
||||
Resp: &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: emptyTableObjBody(codec)},
|
||||
}
|
||||
|
||||
streams, _, buf, errbuf := genericclioptions.NewTestIOStreams()
|
||||
cmd := NewCmdGet("kubectl", tf, streams)
|
||||
cmd.SetOutput(buf)
|
||||
cmd.Run(cmd, []string{"persistentvolumes"})
|
||||
|
||||
expected := ``
|
||||
if e, a := expected, buf.String(); e != a {
|
||||
t.Errorf("expected\n%v\ngot\n%v", e, a)
|
||||
}
|
||||
expectedErr := `No resources found
|
||||
`
|
||||
if e, a := expectedErr, errbuf.String(); e != a {
|
||||
t.Errorf("expectedErr\n%v\ngot\n%v", e, a)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetObjectsShowLabels(t *testing.T) {
|
||||
pods, _, _ := cmdtesting.TestData()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user