mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Merge pull request #91260 from wojtek-t/dont_use_watchcache_capacity
Rely on default watch cache capacity and ignore its requested size
This commit is contained in:
commit
1700acb035
@ -61,6 +61,8 @@ const (
|
|||||||
// Config contains the configuration for a given Cache.
|
// Config contains the configuration for a given Cache.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
// Maximum size of the history cached in memory.
|
// Maximum size of the history cached in memory.
|
||||||
|
//
|
||||||
|
// DEPRECATED: Cache capacity is dynamic and this field is no longer used.
|
||||||
CacheCapacity int
|
CacheCapacity int
|
||||||
|
|
||||||
// An underlying storage.Interface.
|
// An underlying storage.Interface.
|
||||||
@ -357,7 +359,7 @@ func NewCacherFromConfig(config Config) (*Cacher, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
watchCache := newWatchCache(
|
watchCache := newWatchCache(
|
||||||
config.CacheCapacity, config.KeyFunc, cacher.processEvent, config.GetAttrsFunc, config.Versioner, config.Indexers, objType)
|
config.KeyFunc, cacher.processEvent, config.GetAttrsFunc, config.Versioner, config.Indexers, objType)
|
||||||
listerWatcher := NewCacherListerWatcher(config.Storage, config.ResourcePrefix, config.NewListFunc)
|
listerWatcher := NewCacherListerWatcher(config.Storage, config.ResourcePrefix, config.NewListFunc)
|
||||||
reflectorName := "storage/cacher.go:" + config.ResourcePrefix
|
reflectorName := "storage/cacher.go:" + config.ResourcePrefix
|
||||||
|
|
||||||
|
@ -193,7 +193,6 @@ type watchCache struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newWatchCache(
|
func newWatchCache(
|
||||||
capacity int,
|
|
||||||
keyFunc func(runtime.Object) (string, error),
|
keyFunc func(runtime.Object) (string, error),
|
||||||
eventHandler func(*watchCacheEvent),
|
eventHandler func(*watchCacheEvent),
|
||||||
getAttrsFunc func(runtime.Object) (labels.Set, fields.Set, error),
|
getAttrsFunc func(runtime.Object) (labels.Set, fields.Set, error),
|
||||||
@ -201,13 +200,12 @@ func newWatchCache(
|
|||||||
indexers *cache.Indexers,
|
indexers *cache.Indexers,
|
||||||
objectType reflect.Type) *watchCache {
|
objectType reflect.Type) *watchCache {
|
||||||
wc := &watchCache{
|
wc := &watchCache{
|
||||||
capacity: capacity,
|
capacity: defaultLowerBoundCapacity,
|
||||||
keyFunc: keyFunc,
|
keyFunc: keyFunc,
|
||||||
getAttrsFunc: getAttrsFunc,
|
getAttrsFunc: getAttrsFunc,
|
||||||
cache: make([]*watchCacheEvent, capacity),
|
cache: make([]*watchCacheEvent, defaultLowerBoundCapacity),
|
||||||
// TODO get rid of them once we stop passing capacity as a parameter to watch cache.
|
lowerBoundCapacity: defaultLowerBoundCapacity,
|
||||||
lowerBoundCapacity: min(capacity, defaultLowerBoundCapacity),
|
upperBoundCapacity: defaultUpperBoundCapacity,
|
||||||
upperBoundCapacity: max(capacity, defaultUpperBoundCapacity),
|
|
||||||
startIndex: 0,
|
startIndex: 0,
|
||||||
endIndex: 0,
|
endIndex: 0,
|
||||||
store: cache.NewIndexer(storeElementKey, storeElementIndexers(indexers)),
|
store: cache.NewIndexer(storeElementKey, storeElementIndexers(indexers)),
|
||||||
|
@ -81,7 +81,14 @@ func newTestWatchCache(capacity int, indexers *cache.Indexers) *watchCache {
|
|||||||
}
|
}
|
||||||
versioner := etcd3.APIObjectVersioner{}
|
versioner := etcd3.APIObjectVersioner{}
|
||||||
mockHandler := func(*watchCacheEvent) {}
|
mockHandler := func(*watchCacheEvent) {}
|
||||||
wc := newWatchCache(capacity, keyFunc, mockHandler, getAttrsFunc, versioner, indexers, reflect.TypeOf(&example.Pod{}))
|
wc := newWatchCache(keyFunc, mockHandler, getAttrsFunc, versioner, indexers, reflect.TypeOf(&example.Pod{}))
|
||||||
|
// To preserve behavior of tests that assume a given capacity,
|
||||||
|
// resize it to th expected size.
|
||||||
|
wc.capacity = capacity
|
||||||
|
wc.cache = make([]*watchCacheEvent, capacity)
|
||||||
|
wc.lowerBoundCapacity = min(capacity, defaultLowerBoundCapacity)
|
||||||
|
wc.upperBoundCapacity = max(capacity, defaultUpperBoundCapacity)
|
||||||
|
|
||||||
wc.clock = clock.NewFakeClock(time.Now())
|
wc.clock = clock.NewFakeClock(time.Now())
|
||||||
return wc
|
return wc
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user