mirror of
https://github.com/kubernetes/client-go.git
synced 2025-06-23 13:47:19 +00:00
client-go/metadata: use watchlist
Kubernetes-commit: 0912e400cda2dd6ef6950dea15b18f826777ac41
This commit is contained in:
parent
892e9b89df
commit
b42d55bc18
@ -33,6 +33,8 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
"k8s.io/apimachinery/pkg/watch"
|
"k8s.io/apimachinery/pkg/watch"
|
||||||
"k8s.io/client-go/rest"
|
"k8s.io/client-go/rest"
|
||||||
|
"k8s.io/client-go/util/consistencydetector"
|
||||||
|
"k8s.io/client-go/util/watchlist"
|
||||||
)
|
)
|
||||||
|
|
||||||
var deleteScheme = runtime.NewScheme()
|
var deleteScheme = runtime.NewScheme()
|
||||||
@ -218,7 +220,21 @@ func (c *client) Get(ctx context.Context, name string, opts metav1.GetOptions, s
|
|||||||
|
|
||||||
// List returns all resources within the specified scope (namespace or cluster).
|
// List returns all resources within the specified scope (namespace or cluster).
|
||||||
func (c *client) List(ctx context.Context, opts metav1.ListOptions) (*metav1.PartialObjectMetadataList, error) {
|
func (c *client) List(ctx context.Context, opts metav1.ListOptions) (*metav1.PartialObjectMetadataList, error) {
|
||||||
return c.list(ctx, opts)
|
if watchListOptions, hasWatchListOptionsPrepared, watchListOptionsErr := watchlist.PrepareWatchListOptionsFromListOptions(opts); watchListOptionsErr != nil {
|
||||||
|
klog.FromContext(ctx).Error(watchListOptionsErr, "Failed preparing watchlist options, falling back to the standard LIST semantics", "resource", c.resource)
|
||||||
|
} else if hasWatchListOptionsPrepared {
|
||||||
|
result, err := c.watchList(ctx, watchListOptions)
|
||||||
|
if err == nil {
|
||||||
|
consistencydetector.CheckWatchListFromCacheDataConsistencyIfRequested(ctx, fmt.Sprintf("watchlist request for %v", c.resource), c.list, opts, result)
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
klog.FromContext(ctx).Error(err, "The watchlist request ended with an error, falling back to the standard LIST semantics", "resource", c.resource)
|
||||||
|
}
|
||||||
|
result, err := c.list(ctx, opts)
|
||||||
|
if err == nil {
|
||||||
|
consistencydetector.CheckListFromCacheDataConsistencyIfRequested(ctx, fmt.Sprintf("list request for %v", c.resource), c.list, opts, result)
|
||||||
|
}
|
||||||
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *client) list(ctx context.Context, opts metav1.ListOptions) (*metav1.PartialObjectMetadataList, error) {
|
func (c *client) list(ctx context.Context, opts metav1.ListOptions) (*metav1.PartialObjectMetadataList, error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user