From 8711a1e37aa32eeda5ba7f3abb02295ab6c223db Mon Sep 17 00:00:00 2001 From: Joachim Bartosik Date: Wed, 7 Oct 2020 20:01:58 +0200 Subject: [PATCH] Use caching when getting controllers --- .../pkg/recommender/input/cluster_feeder.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/vertical-pod-autoscaler/pkg/recommender/input/cluster_feeder.go b/vertical-pod-autoscaler/pkg/recommender/input/cluster_feeder.go index 628a09116a2c..7a6312b4b779 100644 --- a/vertical-pod-autoscaler/pkg/recommender/input/cluster_feeder.go +++ b/vertical-pod-autoscaler/pkg/recommender/input/cluster_feeder.go @@ -49,7 +49,14 @@ import ( resourceclient "k8s.io/metrics/pkg/client/clientset/versioned/typed/metrics/v1beta1" ) -const defaultResyncPeriod time.Duration = 10 * time.Minute +const ( + betweenContainerParentRefreshes time.Duration = 10 * time.Minute + containerCacheCleanupLoopPeriod time.Duration = time.Hour + containerCacheRefreshLoopPeriod time.Duration = time.Minute + containerParentRefreshCacheLifetime time.Duration = time.Hour + containerParentRefreshJitter time.Duration = time.Minute + defaultResyncPeriod time.Duration = 10 * time.Minute +) // ClusterStateFeeder can update state of ClusterState object. type ClusterStateFeeder interface { @@ -109,7 +116,10 @@ func NewClusterStateFeeder(config *rest.Config, clusterState *model.ClusterState podLister, oomObserver := NewPodListerAndOOMObserver(kubeClient, namespace) factory := informers.NewSharedInformerFactoryWithOptions(kubeClient, defaultResyncPeriod, informers.WithNamespace(namespace)) dirtectControllerParentGetter := controllerfetcher.NewDirectControllerParentGetter(config, kubeClient, factory) - controllerFetcher := controllerfetcher.NewControllerFetcher(dirtectControllerParentGetter) + cachingControllerParentGetter := controllerfetcher.NewCachingControllerGetter(betweenContainerParentRefreshes, containerParentRefreshJitter, containerParentRefreshCacheLifetime, dirtectControllerParentGetter) + cachingControllerParentGetter.Start(context.TODO(), containerCacheCleanupLoopPeriod, containerCacheRefreshLoopPeriod) + controllerFetcher := controllerfetcher.NewControllerFetcher(cachingControllerParentGetter) + return ClusterStateFeederFactory{ PodLister: podLister, OOMObserver: oomObserver,