mirror of
https://github.com/kubernetes/sample-controller.git
synced 2025-01-19 07:52:52 +08:00
make update
Kubernetes-commit: f62c80f965934eeeb2e028497bede7bcc632995d
This commit is contained in:
parent
0fe75b774b
commit
2c1742bca0
@ -27,6 +27,8 @@ import (
|
||||
watch "k8s.io/apimachinery/pkg/watch"
|
||||
rest "k8s.io/client-go/rest"
|
||||
consistencydetector "k8s.io/client-go/util/consistencydetector"
|
||||
watchlist "k8s.io/client-go/util/watchlist"
|
||||
"k8s.io/klog/v2"
|
||||
v1alpha1 "k8s.io/sample-controller/pkg/apis/samplecontroller/v1alpha1"
|
||||
scheme "k8s.io/sample-controller/pkg/generated/clientset/versioned/scheme"
|
||||
)
|
||||
@ -79,13 +81,22 @@ func (c *foos) Get(ctx context.Context, name string, options v1.GetOptions) (res
|
||||
}
|
||||
|
||||
// List takes label and field selectors, and returns the list of Foos that match those selectors.
|
||||
func (c *foos) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.FooList, err error) {
|
||||
defer func() {
|
||||
func (c *foos) List(ctx context.Context, opts v1.ListOptions) (*v1alpha1.FooList, error) {
|
||||
if watchListOptions, hasWatchListOptionsPrepared, watchListOptionsErr := watchlist.PrepareWatchListOptionsFromListOptions(opts); watchListOptionsErr != nil {
|
||||
klog.Warningf("Failed preparing watchlist options for foos, falling back to the standard LIST semantics, err = %v", watchListOptionsErr)
|
||||
} else if hasWatchListOptionsPrepared {
|
||||
result, err := c.watchList(ctx, watchListOptions)
|
||||
if err == nil {
|
||||
consistencydetector.CheckListFromCacheDataConsistencyIfRequested(ctx, "list request for foos", c.list, opts, result)
|
||||
consistencydetector.CheckWatchListFromCacheDataConsistencyIfRequested(ctx, "watchlist request for foos", c.list, opts, result)
|
||||
return result, nil
|
||||
}
|
||||
}()
|
||||
return c.list(ctx, opts)
|
||||
klog.Warningf("The watchlist request for foos ended with an error, falling back to the standard LIST semantics, err = %v", err)
|
||||
}
|
||||
result, err := c.list(ctx, opts)
|
||||
if err == nil {
|
||||
consistencydetector.CheckListFromCacheDataConsistencyIfRequested(ctx, "list request for foos", c.list, opts, result)
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
// list takes label and field selectors, and returns the list of Foos that match those selectors.
|
||||
@ -105,6 +116,23 @@ func (c *foos) list(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.
|
||||
return
|
||||
}
|
||||
|
||||
// watchList establishes a watch stream with the server and returns the list of Foos
|
||||
func (c *foos) watchList(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.FooList, err error) {
|
||||
var timeout time.Duration
|
||||
if opts.TimeoutSeconds != nil {
|
||||
timeout = time.Duration(*opts.TimeoutSeconds) * time.Second
|
||||
}
|
||||
result = &v1alpha1.FooList{}
|
||||
err = c.client.Get().
|
||||
Namespace(c.ns).
|
||||
Resource("foos").
|
||||
VersionedParams(&opts, scheme.ParameterCodec).
|
||||
Timeout(timeout).
|
||||
WatchList(ctx).
|
||||
Into(result)
|
||||
return
|
||||
}
|
||||
|
||||
// Watch returns a watch.Interface that watches the requested foos.
|
||||
func (c *foos) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) {
|
||||
var timeout time.Duration
|
||||
|
Loading…
Reference in New Issue
Block a user