Skip to content

Commit

Permalink
fix jitter
Browse files Browse the repository at this point in the history
  • Loading branch information
zreigz committed Dec 19, 2024
1 parent 048ea45 commit ce67633
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion internal/controller/kubecostextractor_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (r *KubecostExtractorReconciler) RunOnInterval(ctx context.Context, key str
r.Tasks.Set(key, cancel)

go func() {
_ = wait.PollUntilContextCancel(ctxCancel, interval+time.Duration(rand.Int63n(int64(kubeCostJitter))), true, condition)
_ = wait.PollUntilContextCancel(ctxCancel, interval, true, condition)
}()
}

Expand Down Expand Up @@ -132,6 +132,7 @@ func (r *KubecostExtractorReconciler) Reconcile(ctx context.Context, req ctrl.Re
}

r.RunOnInterval(ctx, req.NamespacedName.String(), kubecost.Spec.GetInterval(), func(ctx context.Context) (done bool, err error) {
time.Sleep(time.Duration(rand.Int63n(int64(kubeCostJitter))))
// Always patch object when exiting this function, so we can persist any object changes.
defer func() {
if err := scope.PatchObject(); err != nil && reterr == nil {
Expand Down

0 comments on commit ce67633

Please sign in to comment.