mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-08 19:47:56 +00:00
add no resources found message to rollout-status command (#117884)
* add no resources found message to rollout-status command * return err if not nil before no resource message
This commit is contained in:
parent
626b2db1ca
commit
a5575425b0
@ -174,7 +174,9 @@ func (o *RolloutStatusOptions) Run() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return r.Visit(func(info *resource.Info, _ error) error {
|
resourceFound := false
|
||||||
|
err = r.Visit(func(info *resource.Info, _ error) error {
|
||||||
|
resourceFound = true
|
||||||
mapping := info.ResourceMapping()
|
mapping := info.ResourceMapping()
|
||||||
statusViewer, err := o.StatusViewerFn(mapping)
|
statusViewer, err := o.StatusViewerFn(mapping)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -228,4 +230,14 @@ func (o *RolloutStatusOptions) Run() error {
|
|||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !resourceFound {
|
||||||
|
fmt.Fprintf(o.ErrOut, "No resources found in %s namespace.\n", o.Namespace)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -258,3 +258,29 @@ func TestRolloutStatusWatchDisabledUnavailable(t *testing.T) {
|
|||||||
t.Errorf("expected output: %s, but got: %s", expectedMsg, buf.String())
|
t.Errorf("expected output: %s, but got: %s", expectedMsg, buf.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRolloutStatusEmptyList(t *testing.T) {
|
||||||
|
ns := scheme.Codecs.WithoutConversion()
|
||||||
|
tf := cmdtesting.NewTestFactory().WithNamespace("test")
|
||||||
|
tf.ClientConfigVal = cmdtesting.DefaultClientConfig()
|
||||||
|
|
||||||
|
info, _ := runtime.SerializerInfoForMediaType(ns.SupportedMediaTypes(), runtime.ContentTypeJSON)
|
||||||
|
encoder := ns.EncoderForVersion(info.Serializer, rolloutStatusGroupVersionEncoder)
|
||||||
|
tf.Client = &fake.RESTClient{
|
||||||
|
GroupVersion: rolloutStatusGroupVersionEncoder,
|
||||||
|
NegotiatedSerializer: ns,
|
||||||
|
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
||||||
|
dep := &appsv1.DeploymentList{}
|
||||||
|
body := io.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(encoder, dep))))
|
||||||
|
return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: body}, nil
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
streams, _, _, err := genericiooptions.NewTestIOStreams()
|
||||||
|
cmd := NewCmdRolloutStatus(tf, streams)
|
||||||
|
cmd.Run(cmd, []string{"deployment"})
|
||||||
|
|
||||||
|
expectedMsg := "No resources found in test namespace.\n"
|
||||||
|
if err.String() != expectedMsg {
|
||||||
|
t.Errorf("expected output: %s, but got: %s", expectedMsg, err.String())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user