From 81bb30057d0f91ffac4ebda92b8e4b35ced82cdc Mon Sep 17 00:00:00 2001 From: juanvallejo Date: Wed, 7 Feb 2018 15:55:42 -0500 Subject: [PATCH] UPSTREAM: 59506: fix --watch on multiple requests --- .../pkg/kubectl/cmd/resource/get.go | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/vendor/k8s.io/kubernetes/pkg/kubectl/cmd/resource/get.go b/vendor/k8s.io/kubernetes/pkg/kubectl/cmd/resource/get.go index b3cd8eb25800..ff3e0687bc80 100644 --- a/vendor/k8s.io/kubernetes/pkg/kubectl/cmd/resource/get.go +++ b/vendor/k8s.io/kubernetes/pkg/kubectl/cmd/resource/get.go @@ -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 + infoCount := 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 { + infoCount++ + } + } + + if infoCount > 1 { + return i18n.Errorf("watch is only supported on individual resources and resource collections - %d resources were found", infoCount) + } } 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