From 4d39363e48425ced65b2d0734ffa04789b3f8a0a Mon Sep 17 00:00:00 2001 From: Maskym Vavilov Date: Mon, 8 Apr 2024 12:22:41 +0100 Subject: [PATCH] GH-35 randomize validation reconcilation --- internal/controller/dnsrecord_controller.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/internal/controller/dnsrecord_controller.go b/internal/controller/dnsrecord_controller.go index 48b60985..ea912ff0 100644 --- a/internal/controller/dnsrecord_controller.go +++ b/internal/controller/dnsrecord_controller.go @@ -27,6 +27,7 @@ import ( "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/util/rand" "k8s.io/utils/clock" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" @@ -47,7 +48,7 @@ const ( var ( defaultRequeueTime time.Duration - validationRequeueTime = time.Second * 5 + validationRequeueTime = time.Millisecond * 5000 noRequeueDuration = time.Duration(0) validFor time.Duration reconcileStart = metav1.Time{} @@ -69,6 +70,13 @@ func (r *DNSRecordReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( logger := log.FromContext(ctx) reconcileStart = metav1.Now() + + // randomize validation reconcile delay + seconds := float64(validationRequeueTime.Milliseconds()) + validationRequeueTime = time.Millisecond * time.Duration(rand.Int63nRange( + int64(seconds*0.9), + int64(seconds*1.1))) + previous := &v1alpha1.DNSRecord{} err := r.Client.Get(ctx, client.ObjectKey{Namespace: req.Namespace, Name: req.Name}, previous) if err != nil {