mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 14:37:00 +00:00
Merge pull request #103537 from wojtek-t/pf_chunking_refactor
Avoid code duplication in watchcache
This commit is contained in:
commit
d7123a6524
@ -593,20 +593,27 @@ func (c *Cacher) Get(ctx context.Context, key string, opts storage.GetOptions, o
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetToList implements storage.Interface.
|
func shouldDelegateList(opts storage.ListOptions) bool {
|
||||||
func (c *Cacher) GetToList(ctx context.Context, key string, opts storage.ListOptions, listObj runtime.Object) error {
|
|
||||||
resourceVersion := opts.ResourceVersion
|
resourceVersion := opts.ResourceVersion
|
||||||
pred := opts.Predicate
|
pred := opts.Predicate
|
||||||
pagingEnabled := utilfeature.DefaultFeatureGate.Enabled(features.APIListChunking)
|
pagingEnabled := utilfeature.DefaultFeatureGate.Enabled(features.APIListChunking)
|
||||||
hasContinuation := pagingEnabled && len(pred.Continue) > 0
|
hasContinuation := pagingEnabled && len(pred.Continue) > 0
|
||||||
hasLimit := pagingEnabled && pred.Limit > 0 && resourceVersion != "0"
|
hasLimit := pagingEnabled && pred.Limit > 0 && resourceVersion != "0"
|
||||||
if resourceVersion == "" || hasContinuation || hasLimit || opts.ResourceVersionMatch == metav1.ResourceVersionMatchExact {
|
|
||||||
// If resourceVersion is not specified, serve it from underlying
|
// If resourceVersion is not specified, serve it from underlying
|
||||||
// storage (for backward compatibility). If a continuation is
|
// storage (for backward compatibility). If a continuation is
|
||||||
// requested, serve it from the underlying storage as well.
|
// requested, serve it from the underlying storage as well.
|
||||||
// Limits are only sent to storage when resourceVersion is non-zero
|
// Limits are only sent to storage when resourceVersion is non-zero
|
||||||
// since the watch cache isn't able to perform continuations, and
|
// since the watch cache isn't able to perform continuations, and
|
||||||
// limits are ignored when resource version is zero
|
// limits are ignored when resource version is zero
|
||||||
|
return resourceVersion == "" || hasContinuation || hasLimit || opts.ResourceVersionMatch == metav1.ResourceVersionMatchExact
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetToList implements storage.Interface.
|
||||||
|
func (c *Cacher) GetToList(ctx context.Context, key string, opts storage.ListOptions, listObj runtime.Object) error {
|
||||||
|
resourceVersion := opts.ResourceVersion
|
||||||
|
pred := opts.Predicate
|
||||||
|
if shouldDelegateList(opts) {
|
||||||
return c.storage.GetToList(ctx, key, opts, listObj)
|
return c.storage.GetToList(ctx, key, opts, listObj)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -671,16 +678,7 @@ func (c *Cacher) GetToList(ctx context.Context, key string, opts storage.ListOpt
|
|||||||
func (c *Cacher) List(ctx context.Context, key string, opts storage.ListOptions, listObj runtime.Object) error {
|
func (c *Cacher) List(ctx context.Context, key string, opts storage.ListOptions, listObj runtime.Object) error {
|
||||||
resourceVersion := opts.ResourceVersion
|
resourceVersion := opts.ResourceVersion
|
||||||
pred := opts.Predicate
|
pred := opts.Predicate
|
||||||
pagingEnabled := utilfeature.DefaultFeatureGate.Enabled(features.APIListChunking)
|
if shouldDelegateList(opts) {
|
||||||
hasContinuation := pagingEnabled && len(pred.Continue) > 0
|
|
||||||
hasLimit := pagingEnabled && pred.Limit > 0 && resourceVersion != "0"
|
|
||||||
if resourceVersion == "" || hasContinuation || hasLimit || opts.ResourceVersionMatch == metav1.ResourceVersionMatchExact {
|
|
||||||
// If resourceVersion is not specified, serve it from underlying
|
|
||||||
// storage (for backward compatibility). If a continuation is
|
|
||||||
// requested, serve it from the underlying storage as well.
|
|
||||||
// Limits are only sent to storage when resourceVersion is non-zero
|
|
||||||
// since the watch cache isn't able to perform continuations, and
|
|
||||||
// limits are ignored when resource version is zero.
|
|
||||||
return c.storage.List(ctx, key, opts, listObj)
|
return c.storage.List(ctx, key, opts, listObj)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user