Skip to content

Commit

Permalink
GH-35 randomize validation reconcilation
Browse files Browse the repository at this point in the history
  • Loading branch information
maksymvavilov committed Apr 8, 2024
1 parent 9dc4819 commit 6b9b68d
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion internal/controller/dnsrecord_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,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"
Expand All @@ -48,7 +49,7 @@ const (

var (
defaultRequeueTime time.Duration
validationRequeueTime = time.Second * 5
validationRequeueTime = time.Millisecond * 5000
validFor time.Duration
reconcileStart = metav1.Time{}
Clock clock.Clock = clock.RealClock{}
Expand All @@ -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 {
Expand Down

0 comments on commit 6b9b68d

Please sign in to comment.