UPSTREAM: 59506: fix --watch on multiple requests
@@ -467,8 +467,25 @@ func (options *GetOptions) watch(f cmdutil.Factory, cmd *cobra.Command, args []s
if err != nil {
return err
}
- if len(infos) != 1 {
- return i18n.Errorf("watch is only supported on individual resources and resource collections - %d resources were found", len(infos))
+ if len(infos) > 1 {
+ gvk := infos[0].Mapping.GroupVersionKind
+ uniqueGVKs := 1
+
+ // If requesting a resource count greater than a request's --chunk-size,
+ // we will end up making multiple requests to the server, with each
+ // request producing its own "Info" object. Although overall we are
+ // dealing with a single resource type, we will end up with multiple
+ // infos returned by the builder. To handle this case, only fail if we
+ // have at least one info with a different GVK than the others.
+ for _, info := range infos {
+ if info.Mapping.GroupVersionKind != gvk {
+ uniqueGVKs++
+ }
+ }
+
+ if uniqueGVKs > 1 {
+ return i18n.Errorf("watch is only supported on individual resources and resource collections - %d resources were found", uniqueGVKs)
+ }
}
filterOpts := cmdutil.ExtractCmdPrintOptions(cmd, options.AllNamespaces)
@@ -577,7 +594,6 @@ func (options *GetOptions) printGeneric(printer printers.ResourcePrinter, r *res
var obj runtime.Object
if !singleItemImplied || len(infos) > 1 {
- // we have more than one item, so coerce all items into a list
// we have more than one item, so coerce all items into a list.
// we don't want an *unstructured.Unstructured list yet, as we
// may be dealing with non-unstructured objects. Compose all items
