Skip to content

Commit 1700acb

Browse files
authored
Merge pull request kubernetes#91260 from wojtek-t/dont_use_watchcache_capacity
Rely on default watch cache capacity and ignore its requested size
2 parents 10caa46 + 99dff90 commit 1700acb

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

staging/src/k8s.io/apiserver/pkg/storage/cacher/cacher.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ const (
6161
// Config contains the configuration for a given Cache.
6262
type Config struct {
6363
// Maximum size of the history cached in memory.
64+
//
65+
// DEPRECATED: Cache capacity is dynamic and this field is no longer used.
6466
CacheCapacity int
6567

6668
// An underlying storage.Interface.
@@ -357,7 +359,7 @@ func NewCacherFromConfig(config Config) (*Cacher, error) {
357359
}
358360

359361
watchCache := newWatchCache(
360-
config.CacheCapacity, config.KeyFunc, cacher.processEvent, config.GetAttrsFunc, config.Versioner, config.Indexers, objType)
362+
config.KeyFunc, cacher.processEvent, config.GetAttrsFunc, config.Versioner, config.Indexers, objType)
361363
listerWatcher := NewCacherListerWatcher(config.Storage, config.ResourcePrefix, config.NewListFunc)
362364
reflectorName := "storage/cacher.go:" + config.ResourcePrefix
363365

staging/src/k8s.io/apiserver/pkg/storage/cacher/watch_cache.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -193,21 +193,19 @@ type watchCache struct {
193193
}
194194

195195
func newWatchCache(
196-
capacity int,
197196
keyFunc func(runtime.Object) (string, error),
198197
eventHandler func(*watchCacheEvent),
199198
getAttrsFunc func(runtime.Object) (labels.Set, fields.Set, error),
200199
versioner storage.Versioner,
201200
indexers *cache.Indexers,
202201
objectType reflect.Type) *watchCache {
203202
wc := &watchCache{
204-
capacity: capacity,
205-
keyFunc: keyFunc,
206-
getAttrsFunc: getAttrsFunc,
207-
cache: make([]*watchCacheEvent, capacity),
208-
// TODO get rid of them once we stop passing capacity as a parameter to watch cache.
209-
lowerBoundCapacity: min(capacity, defaultLowerBoundCapacity),
210-
upperBoundCapacity: max(capacity, defaultUpperBoundCapacity),
203+
capacity: defaultLowerBoundCapacity,
204+
keyFunc: keyFunc,
205+
getAttrsFunc: getAttrsFunc,
206+
cache: make([]*watchCacheEvent, defaultLowerBoundCapacity),
207+
lowerBoundCapacity: defaultLowerBoundCapacity,
208+
upperBoundCapacity: defaultUpperBoundCapacity,
211209
startIndex: 0,
212210
endIndex: 0,
213211
store: cache.NewIndexer(storeElementKey, storeElementIndexers(indexers)),

staging/src/k8s.io/apiserver/pkg/storage/cacher/watch_cache_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,14 @@ func newTestWatchCache(capacity int, indexers *cache.Indexers) *watchCache {
8181
}
8282
versioner := etcd3.APIObjectVersioner{}
8383
mockHandler := func(*watchCacheEvent) {}
84-
wc := newWatchCache(capacity, keyFunc, mockHandler, getAttrsFunc, versioner, indexers, reflect.TypeOf(&example.Pod{}))
84+
wc := newWatchCache(keyFunc, mockHandler, getAttrsFunc, versioner, indexers, reflect.TypeOf(&example.Pod{}))
85+
// To preserve behavior of tests that assume a given capacity,
86+
// resize it to th expected size.
87+
wc.capacity = capacity
88+
wc.cache = make([]*watchCacheEvent, capacity)
89+
wc.lowerBoundCapacity = min(capacity, defaultLowerBoundCapacity)
90+
wc.upperBoundCapacity = max(capacity, defaultUpperBoundCapacity)
91+
8592
wc.clock = clock.NewFakeClock(time.Now())
8693
return wc
8794
}

0 commit comments

Comments
 (0)