diff --git a/test/cmd/get.sh b/test/cmd/get.sh index b654b5a32a64..5af21eca10b3 100755 --- a/test/cmd/get.sh +++ b/test/cmd/get.sh @@ -37,5 +37,11 @@ os::cmd::expect_success_and_not_text 'oc get users test-user-1' "customlabel=tru # test structured and unstructured resources print generically without panic os::cmd::expect_success_and_text 'oc get projectrequests -o yaml' 'status: Success' os::cmd::expect_success_and_text 'oc get projectrequests,svc,pod -o yaml' 'kind: List' +# test --wacth does not result in an error when a resource list is served in multiple chunks +os::cmd::expect_success 'oc create cm cmone' +os::cmd::expect_success 'oc create cm cmtwo' +os::cmd::expect_success 'oc create cm cmthree' +os::cmd::expect_success_and_not_text 'oc get configmap --chunk-size=1 --watch --request-timeout=1s' 'watch is only supported on individual resources' +os::cmd::expect_success_and_not_text 'oc get configmap --chunk-size=1 --watch-only --request-timeout=1s' 'watch is only supported on individual resources' echo "oc get: ok" os::test::junit::declare_suite_end 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..8ae84655e1d7 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 + 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