var dataConsistencyDetectionForListFromCacheEnabled … func init() { … } // IsDataConsistencyDetectionForListEnabled returns true when // the KUBE_LIST_FROM_CACHE_INCONSISTENCY_DETECTOR environment variable was set during a binary startup. func IsDataConsistencyDetectionForListEnabled() bool { … } // CheckListFromCacheDataConsistencyIfRequested performs a data consistency check only when // the KUBE_LIST_FROM_CACHE_INCONSISTENCY_DETECTOR environment variable was set during a binary startup // for requests that have a high chance of being served from the watch-cache. // // The consistency check is meant to be enforced only in the CI, not in production. // The check ensures that data retrieved by a list api call from the watch-cache // is exactly the same as data received by the list api call from etcd. // // Note that this function will panic when data inconsistency is detected. // This is intentional because we want to catch it in the CI. // // Note that this function doesn't examine the ListOptions to determine // if the original request has hit the cache because it would be challenging // to maintain consistency with the server-side implementation. // For simplicity, we assume that the first request retrieved data from // the cache (even though this might not be true for some requests) // and issue the second call to get data from etcd for comparison. func CheckListFromCacheDataConsistencyIfRequested[T runtime.Object](ctx context.Context, identity string, listItemsFn ListFunc[T], optionsUsedToReceiveList metav1.ListOptions, receivedList runtime.Object) { … } func checkListFromCacheDataConsistencyIfRequestedInternal[T runtime.Object](ctx context.Context, identity string, listItemsFn ListFunc[T], optionsUsedToReceiveList metav1.ListOptions, receivedList runtime.Object) { … }