Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Randomize duration bug #81

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions internal/common/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import (
// RandomizeDuration randomizes duration for a given variance.
// variance is expected to be of a format 0.1 for 10%, 0.5 for 50% and so on
func RandomizeDuration(variance float64, duration time.Duration) time.Duration {
// do not allow less than a second requeue
if duration.Milliseconds() < 1000 {
philbrookes marked this conversation as resolved.
Show resolved Hide resolved
duration = time.Second * 1
}
// we won't go smaller than a second - using milliseconds to have a relatively big number to randomize
millisecond := float64(duration.Milliseconds())

Expand Down
5 changes: 3 additions & 2 deletions internal/controller/dnsrecord_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ const (
DNSRecordFinalizer = "kuadrant.io/dns-record"
WriteCounterLimit = 20
validationRequeueVariance = 0.5
DefaultValidationDuration = time.Second * 5
philbrookes marked this conversation as resolved.
Show resolved Hide resolved
)

var (
defaultRequeueTime time.Duration
validationRequeueTime = time.Millisecond * 5000
validationRequeueTime time.Duration
noRequeueDuration = time.Duration(0)
validFor time.Duration
reconcileStart = metav1.Time{}
Expand All @@ -75,7 +76,7 @@ func (r *DNSRecordReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
reconcileStart = metav1.Now()

// randomize validation reconcile delay
validationRequeueTime = common.RandomizeDuration(validationRequeueVariance, validationRequeueTime)
validationRequeueTime = common.RandomizeDuration(validationRequeueVariance, DefaultValidationDuration)

previous := &v1alpha1.DNSRecord{}
err := r.Client.Get(ctx, client.ObjectKey{Namespace: req.Namespace, Name: req.Name}, previous)
Expand Down
Loading