mirror of
https://github.com/kubernetes/client-go.git
synced 2025-09-14 14:18:59 +00:00
[client-go #1415] Use transformer from provided store within internal stores in reflector to limit memory usage bursts
Signed-off-by: Valerian Roche <valerian.roche@datadoghq.com> Kubernetes-commit: 585ed0a5cb378e794e4775bc846d5309ca65f2c6
This commit is contained in:
committed by
Kubernetes Publisher
parent
c2ce9a8b31
commit
71776a84bd
14
tools/cache/reflector.go
vendored
14
tools/cache/reflector.go
vendored
@@ -76,6 +76,13 @@ type ReflectorStore interface {
|
||||
Resync() error
|
||||
}
|
||||
|
||||
// TransformingStore is an optional interface that can be implemented by the provided store.
|
||||
// If implemented on the provided store reflector will use the same transformer in its internal stores.
|
||||
type TransformingStore interface {
|
||||
Store
|
||||
Transformer() TransformFunc
|
||||
}
|
||||
|
||||
// Reflector watches a specified resource and causes all changes to be reflected in the given store.
|
||||
type Reflector struct {
|
||||
// name identifies this reflector. By default, it will be a file:line if possible.
|
||||
@@ -718,6 +725,11 @@ func (r *Reflector) watchList(ctx context.Context) (watch.Interface, error) {
|
||||
return false
|
||||
}
|
||||
|
||||
storeOpts := []StoreOption{}
|
||||
if tr, ok := r.store.(TransformingStore); ok && tr.Transformer() != nil {
|
||||
storeOpts = append(storeOpts, WithTransformer(tr.Transformer()))
|
||||
}
|
||||
|
||||
initTrace := trace.New("Reflector WatchList", trace.Field{Key: "name", Value: r.name})
|
||||
defer initTrace.LogIfLong(10 * time.Second)
|
||||
for {
|
||||
@@ -729,7 +741,7 @@ func (r *Reflector) watchList(ctx context.Context) (watch.Interface, error) {
|
||||
|
||||
resourceVersion = ""
|
||||
lastKnownRV := r.rewatchResourceVersion()
|
||||
temporaryStore = NewStore(DeletionHandlingMetaNamespaceKeyFunc)
|
||||
temporaryStore = NewStore(DeletionHandlingMetaNamespaceKeyFunc, storeOpts...)
|
||||
// TODO(#115478): large "list", slow clients, slow network, p&f
|
||||
// might slow down streaming and eventually fail.
|
||||
// maybe in such a case we should retry with an increased timeout?
|
||||
|
Reference in New Issue
Block a user