diff --git a/vertical-pod-autoscaler/pkg/recommender/routines/recommender.go b/vertical-pod-autoscaler/pkg/recommender/routines/recommender.go index bf3060e6202b..4a87b21cf778 100644 --- a/vertical-pod-autoscaler/pkg/recommender/routines/recommender.go +++ b/vertical-pod-autoscaler/pkg/recommender/routines/recommender.go @@ -149,8 +149,6 @@ func (r *recommender) RunOnce() { defer timer.ObserveTotal() ctx := context.Background() - ctx, cancelFunc := context.WithDeadline(ctx, time.Now().Add(*checkpointsWriteTimeout)) - defer cancelFunc() klog.V(3).Infof("Recommender Run") @@ -167,7 +165,9 @@ func (r *recommender) RunOnce() { r.UpdateVPAs() timer.ObserveStep("UpdateVPAs") - r.MaintainCheckpoints(ctx, *minCheckpointsPerRun) + stepCtx, cancelFunc := context.WithDeadline(ctx, time.Now().Add(*checkpointsWriteTimeout)) + defer cancelFunc() + r.MaintainCheckpoints(stepCtx, *minCheckpointsPerRun) timer.ObserveStep("MaintainCheckpoints") r.clusterState.RateLimitedGarbageCollectAggregateCollectionStates(ctx, time.Now(), r.controllerFetcher)