mirror of
https://github.com/kubernetes/client-go.git
synced 2025-07-21 10:30:24 +00:00
Enable paging for all list watchers
Kubernetes-commit: 500b130ff0a2c744b21cfb8e6d09e94b707dec61
This commit is contained in:
parent
7b48f37a96
commit
2b76a1826e
2
tools/cache/BUILD
vendored
2
tools/cache/BUILD
vendored
@ -63,6 +63,7 @@ go_library(
|
|||||||
],
|
],
|
||||||
deps = [
|
deps = [
|
||||||
"//vendor/github.com/golang/glog:go_default_library",
|
"//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/errors:go_default_library",
|
||||||
"//vendor/k8s.io/apimachinery/pkg/api/meta:go_default_library",
|
"//vendor/k8s.io/apimachinery/pkg/api/meta:go_default_library",
|
||||||
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1: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/apimachinery/pkg/watch:go_default_library",
|
||||||
"//vendor/k8s.io/client-go/kubernetes/scheme: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/rest:go_default_library",
|
||||||
|
"//vendor/k8s.io/client-go/tools/pager:go_default_library",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
11
tools/cache/listwatch.go
vendored
11
tools/cache/listwatch.go
vendored
@ -19,12 +19,15 @@ package cache
|
|||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"golang.org/x/net/context"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/api/meta"
|
"k8s.io/apimachinery/pkg/api/meta"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/fields"
|
"k8s.io/apimachinery/pkg/fields"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/apimachinery/pkg/watch"
|
"k8s.io/apimachinery/pkg/watch"
|
||||||
restclient "k8s.io/client-go/rest"
|
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.
|
// 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.
|
// It is a convenience function for users of NewReflector, etc.
|
||||||
// ListFunc and WatchFunc must not be nil
|
// ListFunc and WatchFunc must not be nil
|
||||||
type ListWatch struct {
|
type ListWatch struct {
|
||||||
ListFunc ListFunc
|
ListFunc ListFunc
|
||||||
WatchFunc WatchFunc
|
WatchFunc WatchFunc
|
||||||
|
DisablePaging bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getter interface knows how to access Get method from RESTClient.
|
// 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
|
// List a set of apiserver resources
|
||||||
func (lw *ListWatch) List(options metav1.ListOptions) (runtime.Object, error) {
|
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)
|
return lw.ListFunc(options)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user