Skip to content

Commit c37837e

Browse files
authored
Merge pull request kubernetes#91380 from liggitt/revert-watch-capacity
Revert "Rely on default watch cache capacity and ignore its requested size"
2 parents 3d7847e + 6249f28 commit c37837e

File tree

3 files changed

+10
-17
lines changed

3 files changed

+10
-17
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ 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.
6664
CacheCapacity int
6765

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

361359
watchCache := newWatchCache(
362-
config.KeyFunc, cacher.processEvent, config.GetAttrsFunc, config.Versioner, config.Indexers, objType)
360+
config.CacheCapacity, config.KeyFunc, cacher.processEvent, config.GetAttrsFunc, config.Versioner, config.Indexers, objType)
363361
listerWatcher := NewCacherListerWatcher(config.Storage, config.ResourcePrefix, config.NewListFunc)
364362
reflectorName := "storage/cacher.go:" + config.ResourcePrefix
365363

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

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

195195
func newWatchCache(
196+
capacity int,
196197
keyFunc func(runtime.Object) (string, error),
197198
eventHandler func(*watchCacheEvent),
198199
getAttrsFunc func(runtime.Object) (labels.Set, fields.Set, error),
199200
versioner storage.Versioner,
200201
indexers *cache.Indexers,
201202
objectType reflect.Type) *watchCache {
202203
wc := &watchCache{
203-
capacity: defaultLowerBoundCapacity,
204-
keyFunc: keyFunc,
205-
getAttrsFunc: getAttrsFunc,
206-
cache: make([]*watchCacheEvent, defaultLowerBoundCapacity),
207-
lowerBoundCapacity: defaultLowerBoundCapacity,
208-
upperBoundCapacity: defaultUpperBoundCapacity,
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),
209211
startIndex: 0,
210212
endIndex: 0,
211213
store: cache.NewIndexer(storeElementKey, storeElementIndexers(indexers)),

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,7 @@ func newTestWatchCache(capacity int, indexers *cache.Indexers) *watchCache {
8181
}
8282
versioner := etcd3.APIObjectVersioner{}
8383
mockHandler := func(*watchCacheEvent) {}
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-
84+
wc := newWatchCache(capacity, keyFunc, mockHandler, getAttrsFunc, versioner, indexers, reflect.TypeOf(&example.Pod{}))
9285
wc.clock = clock.NewFakeClock(time.Now())
9386
return wc
9487
}

0 commit comments

Comments
 (0)