mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-04 09:49:50 +00:00
Merge pull request #129439 from serathius/refactor-delegate-2
Refactor shouldDelegateList
This commit is contained in:
commit
20e1944f88
@ -785,22 +785,30 @@ func (c *Cacher) Get(ctx context.Context, key string, opts storage.GetOptions, o
|
|||||||
//
|
//
|
||||||
// staging/src/k8s.io/apiserver/pkg/util/flowcontrol/request/list_work_estimator.go
|
// staging/src/k8s.io/apiserver/pkg/util/flowcontrol/request/list_work_estimator.go
|
||||||
func shouldDelegateList(opts storage.ListOptions) bool {
|
func shouldDelegateList(opts storage.ListOptions) bool {
|
||||||
resourceVersion := opts.ResourceVersion
|
// see https://kubernetes.io/docs/reference/using-api/api-concepts/#semantics-for-get-and-list
|
||||||
pred := opts.Predicate
|
switch opts.ResourceVersionMatch {
|
||||||
match := opts.ResourceVersionMatch
|
case metav1.ResourceVersionMatchExact:
|
||||||
|
return true
|
||||||
|
case metav1.ResourceVersionMatchNotOlderThan:
|
||||||
|
case "":
|
||||||
|
// Legacy exact match
|
||||||
|
if opts.Predicate.Limit > 0 && len(opts.ResourceVersion) > 0 && opts.ResourceVersion != "0" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
// Continue
|
||||||
|
if len(opts.Predicate.Continue) > 0 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
// Consistent Read
|
||||||
|
if opts.ResourceVersion == "" {
|
||||||
consistentListFromCacheEnabled := utilfeature.DefaultFeatureGate.Enabled(features.ConsistentListFromCache)
|
consistentListFromCacheEnabled := utilfeature.DefaultFeatureGate.Enabled(features.ConsistentListFromCache)
|
||||||
requestWatchProgressSupported := etcdfeature.DefaultFeatureSupportChecker.Supports(storage.RequestWatchProgress)
|
requestWatchProgressSupported := etcdfeature.DefaultFeatureSupportChecker.Supports(storage.RequestWatchProgress)
|
||||||
|
return !consistentListFromCacheEnabled || !requestWatchProgressSupported
|
||||||
// Serve consistent reads from storage if ConsistentListFromCache is disabled
|
}
|
||||||
consistentReadFromStorage := resourceVersion == "" && !(consistentListFromCacheEnabled && requestWatchProgressSupported)
|
return false
|
||||||
// Watch cache doesn't support continuations, so serve them from etcd.
|
|
||||||
hasContinuation := len(pred.Continue) > 0
|
|
||||||
// Watch cache only supports ResourceVersionMatchNotOlderThan (default).
|
|
||||||
// see https://kubernetes.io/docs/reference/using-api/api-concepts/#semantics-for-get-and-list
|
|
||||||
isLegacyExactMatch := opts.Predicate.Limit > 0 && match == "" && len(resourceVersion) > 0 && resourceVersion != "0"
|
|
||||||
unsupportedMatch := match != "" && match != metav1.ResourceVersionMatchNotOlderThan || isLegacyExactMatch
|
|
||||||
|
|
||||||
return consistentReadFromStorage || hasContinuation || unsupportedMatch
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// computeListLimit determines whether the cacher should
|
// computeListLimit determines whether the cacher should
|
||||||
|
@ -164,19 +164,28 @@ func key(requestInfo *apirequest.RequestInfo) string {
|
|||||||
//
|
//
|
||||||
// staging/src/k8s.io/apiserver/pkg/storage/cacher/cacher.go
|
// staging/src/k8s.io/apiserver/pkg/storage/cacher/cacher.go
|
||||||
func shouldListFromStorage(query url.Values, opts *metav1.ListOptions) bool {
|
func shouldListFromStorage(query url.Values, opts *metav1.ListOptions) bool {
|
||||||
resourceVersion := opts.ResourceVersion
|
// see https://kubernetes.io/docs/reference/using-api/api-concepts/#semantics-for-get-and-list
|
||||||
match := opts.ResourceVersionMatch
|
switch opts.ResourceVersionMatch {
|
||||||
|
case metav1.ResourceVersionMatchExact:
|
||||||
|
return true
|
||||||
|
case metav1.ResourceVersionMatchNotOlderThan:
|
||||||
|
case "":
|
||||||
|
// Legacy exact match
|
||||||
|
if opts.Limit > 0 && len(opts.ResourceVersion) > 0 && opts.ResourceVersion != "0" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
// Continue
|
||||||
|
if len(opts.Continue) > 0 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
// Consistent Read
|
||||||
|
if opts.ResourceVersion == "" {
|
||||||
consistentListFromCacheEnabled := utilfeature.DefaultFeatureGate.Enabled(features.ConsistentListFromCache)
|
consistentListFromCacheEnabled := utilfeature.DefaultFeatureGate.Enabled(features.ConsistentListFromCache)
|
||||||
requestWatchProgressSupported := etcdfeature.DefaultFeatureSupportChecker.Supports(storage.RequestWatchProgress)
|
requestWatchProgressSupported := etcdfeature.DefaultFeatureSupportChecker.Supports(storage.RequestWatchProgress)
|
||||||
|
return !consistentListFromCacheEnabled || !requestWatchProgressSupported
|
||||||
// Serve consistent reads from storage if ConsistentListFromCache is disabled
|
}
|
||||||
consistentReadFromStorage := resourceVersion == "" && !(consistentListFromCacheEnabled && requestWatchProgressSupported)
|
return false
|
||||||
// Watch cache doesn't support continuations, so serve them from etcd.
|
|
||||||
hasContinuation := len(opts.Continue) > 0
|
|
||||||
// Watch cache only supports ResourceVersionMatchNotOlderThan (default).
|
|
||||||
// see https://kubernetes.io/docs/reference/using-api/api-concepts/#semantics-for-get-and-list
|
|
||||||
isLegacyExactMatch := opts.Limit > 0 && match == "" && len(resourceVersion) > 0 && resourceVersion != "0"
|
|
||||||
unsupportedMatch := match != "" && match != metav1.ResourceVersionMatchNotOlderThan || isLegacyExactMatch
|
|
||||||
|
|
||||||
return consistentReadFromStorage || hasContinuation || unsupportedMatch
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user