Merge pull request #118792 from serathius/refactor-delegate
Refactor shouldDelegateList/shouldListFromStorage to better explain d… Kubernetes-commit: 55fb1805a1217b91b36fa8fe8f2bf3a28af2454d
This commit is contained in:
		
						commit
						9cfab516c2
					
				| 
						 | 
					@ -721,17 +721,17 @@ func shouldDelegateList(opts storage.ListOptions) bool {
 | 
				
			||||||
	pred := opts.Predicate
 | 
						pred := opts.Predicate
 | 
				
			||||||
	match := opts.ResourceVersionMatch
 | 
						match := opts.ResourceVersionMatch
 | 
				
			||||||
	pagingEnabled := utilfeature.DefaultFeatureGate.Enabled(features.APIListChunking)
 | 
						pagingEnabled := utilfeature.DefaultFeatureGate.Enabled(features.APIListChunking)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Serve consistent reads from storage
 | 
				
			||||||
 | 
						consistentReadFromStorage := resourceVersion == ""
 | 
				
			||||||
 | 
						// Watch cache doesn't support continuations, so serve them from etcd.
 | 
				
			||||||
	hasContinuation := pagingEnabled && len(pred.Continue) > 0
 | 
						hasContinuation := pagingEnabled && len(pred.Continue) > 0
 | 
				
			||||||
 | 
						// Serve paginated requests about revision "0" from watch cache to avoid overwhelming etcd.
 | 
				
			||||||
	hasLimit := pagingEnabled && pred.Limit > 0 && resourceVersion != "0"
 | 
						hasLimit := pagingEnabled && pred.Limit > 0 && resourceVersion != "0"
 | 
				
			||||||
 | 
						// Watch cache only supports ResourceVersionMatchNotOlderThan (default).
 | 
				
			||||||
	unsupportedMatch := match != "" && match != metav1.ResourceVersionMatchNotOlderThan
 | 
						unsupportedMatch := match != "" && match != metav1.ResourceVersionMatchNotOlderThan
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// If resourceVersion is not specified, serve it from underlying
 | 
						return consistentReadFromStorage || hasContinuation || hasLimit || unsupportedMatch
 | 
				
			||||||
	// 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 resourceVersion == "" || hasContinuation || hasLimit || unsupportedMatch
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (c *Cacher) listItems(ctx context.Context, listRV uint64, key string, pred storage.SelectionPredicate, recursive bool) ([]interface{}, uint64, string, error) {
 | 
					func (c *Cacher) listItems(ctx context.Context, listRV uint64, key string, pred storage.SelectionPredicate, recursive bool) ([]interface{}, uint64, string, error) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -149,9 +149,15 @@ func shouldListFromStorage(query url.Values, opts *metav1.ListOptions) bool {
 | 
				
			||||||
	resourceVersion := opts.ResourceVersion
 | 
						resourceVersion := opts.ResourceVersion
 | 
				
			||||||
	match := opts.ResourceVersionMatch
 | 
						match := opts.ResourceVersionMatch
 | 
				
			||||||
	pagingEnabled := utilfeature.DefaultFeatureGate.Enabled(features.APIListChunking)
 | 
						pagingEnabled := utilfeature.DefaultFeatureGate.Enabled(features.APIListChunking)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Serve consistent reads from storage
 | 
				
			||||||
 | 
						consistentReadFromStorage := resourceVersion == ""
 | 
				
			||||||
 | 
						// Watch cache doesn't support continuations, so serve them from etcd.
 | 
				
			||||||
	hasContinuation := pagingEnabled && len(opts.Continue) > 0
 | 
						hasContinuation := pagingEnabled && len(opts.Continue) > 0
 | 
				
			||||||
 | 
						// Serve paginated requests about revision "0" from watch cache to avoid overwhelming etcd.
 | 
				
			||||||
	hasLimit := pagingEnabled && opts.Limit > 0 && resourceVersion != "0"
 | 
						hasLimit := pagingEnabled && opts.Limit > 0 && resourceVersion != "0"
 | 
				
			||||||
 | 
						// Watch cache only supports ResourceVersionMatchNotOlderThan (default).
 | 
				
			||||||
	unsupportedMatch := match != "" && match != metav1.ResourceVersionMatchNotOlderThan
 | 
						unsupportedMatch := match != "" && match != metav1.ResourceVersionMatchNotOlderThan
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return resourceVersion == "" || hasContinuation || hasLimit || unsupportedMatch
 | 
						return consistentReadFromStorage || hasContinuation || hasLimit || unsupportedMatch
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue