Enable paging for all list watchers

pull/6/head
Clayton Coleman 2017-07-17 22:53:14 -04:00
parent fb68d1d3a7
commit 500b130ff0
No known key found for this signature in database
GPG Key ID: 3D16906B4F1C5CB3
3 changed files with 12 additions and 2 deletions

View File

@ -104,6 +104,7 @@ func TestListWatchesCanList(t *testing.T) {
defer server.Close()
client := clientset.NewForConfigOrDie(&restclient.Config{Host: server.URL, ContentConfig: restclient.ContentConfig{GroupVersion: &api.Registry.GroupOrDie(v1.GroupName).GroupVersion}})
lw := NewListWatchFromClient(client.Core().RESTClient(), item.resource, item.namespace, item.fieldSelector)
lw.DisablePaging = true
// This test merely tests that the correct request is made.
lw.List(metav1.ListOptions{})
handler.ValidateRequest(t, item.location, "GET", nil)

View File

@ -63,6 +63,7 @@ go_library(
],
deps = [
"//vendor/github.com/golang/glog:go_default_library",
"//vendor/golang.org/x/net/context:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/meta:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
@ -79,6 +80,7 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/watch:go_default_library",
"//vendor/k8s.io/client-go/kubernetes/scheme:go_default_library",
"//vendor/k8s.io/client-go/rest:go_default_library",
"//vendor/k8s.io/client-go/tools/pager:go_default_library",
],
)

View File

@ -19,12 +19,15 @@ package cache
import (
"time"
"golang.org/x/net/context"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/watch"
restclient "k8s.io/client-go/rest"
"k8s.io/client-go/tools/pager"
)
// ListerWatcher is any object that knows how to perform an initial list and start a watch on a resource.
@ -46,8 +49,9 @@ type WatchFunc func(options metav1.ListOptions) (watch.Interface, error)
// It is a convenience function for users of NewReflector, etc.
// ListFunc and WatchFunc must not be nil
type ListWatch struct {
ListFunc ListFunc
WatchFunc WatchFunc
ListFunc ListFunc
WatchFunc WatchFunc
DisablePaging bool
}
// Getter interface knows how to access Get method from RESTClient.
@ -87,6 +91,9 @@ func timeoutFromListOptions(options metav1.ListOptions) time.Duration {
// List a set of apiserver resources
func (lw *ListWatch) List(options metav1.ListOptions) (runtime.Object, error) {
if !lw.DisablePaging {
return pager.New(pager.SimplePageFunc(lw.ListFunc)).List(context.TODO(), options)
}
return lw.ListFunc(options)
}