Skip to content

Commit

Permalink
Merge pull request kubernetes#91380 from liggitt/revert-watch-capacity
Browse files Browse the repository at this point in the history
Revert "Rely on default watch cache capacity and ignore its requested size"
  • Loading branch information
k8s-ci-robot authored May 23, 2020
2 parents 3d7847e + 6249f28 commit c37837e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
4 changes: 1 addition & 3 deletions staging/src/k8s.io/apiserver/pkg/storage/cacher/cacher.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ const (
// Config contains the configuration for a given Cache.
type Config struct {
// Maximum size of the history cached in memory.
//
// DEPRECATED: Cache capacity is dynamic and this field is no longer used.
CacheCapacity int

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

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

Expand Down
14 changes: 8 additions & 6 deletions staging/src/k8s.io/apiserver/pkg/storage/cacher/watch_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,19 +193,21 @@ type watchCache struct {
}

func newWatchCache(
capacity int,
keyFunc func(runtime.Object) (string, error),
eventHandler func(*watchCacheEvent),
getAttrsFunc func(runtime.Object) (labels.Set, fields.Set, error),
versioner storage.Versioner,
indexers *cache.Indexers,
objectType reflect.Type) *watchCache {
wc := &watchCache{
capacity: defaultLowerBoundCapacity,
keyFunc: keyFunc,
getAttrsFunc: getAttrsFunc,
cache: make([]*watchCacheEvent, defaultLowerBoundCapacity),
lowerBoundCapacity: defaultLowerBoundCapacity,
upperBoundCapacity: defaultUpperBoundCapacity,
capacity: capacity,
keyFunc: keyFunc,
getAttrsFunc: getAttrsFunc,
cache: make([]*watchCacheEvent, capacity),
// TODO get rid of them once we stop passing capacity as a parameter to watch cache.
lowerBoundCapacity: min(capacity, defaultLowerBoundCapacity),
upperBoundCapacity: max(capacity, defaultUpperBoundCapacity),
startIndex: 0,
endIndex: 0,
store: cache.NewIndexer(storeElementKey, storeElementIndexers(indexers)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,7 @@ func newTestWatchCache(capacity int, indexers *cache.Indexers) *watchCache {
}
versioner := etcd3.APIObjectVersioner{}
mockHandler := func(*watchCacheEvent) {}
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 := newWatchCache(capacity, keyFunc, mockHandler, getAttrsFunc, versioner, indexers, reflect.TypeOf(&example.Pod{}))
wc.clock = clock.NewFakeClock(time.Now())
return wc
}
Expand Down

0 comments on commit c37837e

Please sign in to comment.