Skip to content

Commit

Permalink
Merge pull request kubernetes#18514 from juanvallejo/jvallejo/handle-…
Browse files Browse the repository at this point in the history
…watch-multiple-reqs

Automatic merge from submit-queue.

UPSTREAM: 59506: fix watch on multiple reqs

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1537789

`oc get <resource> --watch` only supports watching a single resource kind at a time.
This check fails if more than one resource `Info` is returned.

When dealing with large quantities of a single resource kind, or an amount that exceeds the value of `--chunk-size`, more than one request is made to the server causing a resource `Info` to be created for each of the requests, ultimately causing the above check to fail even though we are dealing with the same type of resource.

This patch modifies that check to take into account the GVKs of all infos returned, and only fail if at least one differs.

cc @deads2k @jeremyeder

Origin-commit: 48d2a6d1900fb16a35fb7ff47d3750f8021b9ef3
  • Loading branch information
k8s-publishing-bot committed Feb 27, 2018
2 parents 99cf124 + 47a2c3d commit 6f1d5a7
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions pkg/kubectl/cmd/resource/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6f1d5a7

Please sign in to comment.