From 58ae18439c2381e9e5845fbdd2eeb11222194371 Mon Sep 17 00:00:00 2001 From: claudiumocanu Date: Thu, 17 Feb 2022 18:28:07 +0200 Subject: [PATCH 1/2] ScheduleRunOnce if not already scheduled --- controller/controller.go | 6 +++++- controller/controller_test.go | 14 +++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/controller/controller.go b/controller/controller.go index d609c089d..66228c3ea 100644 --- a/controller/controller.go +++ b/controller/controller.go @@ -242,7 +242,11 @@ func filterARecords(endpoints []*endpoint.Endpoint) []string { func (c *Controller) ScheduleRunOnce(now time.Time) { c.nextRunAtMux.Lock() defer c.nextRunAtMux.Unlock() - c.nextRunAt = now.Add(c.MinEventSyncInterval) + // Shedule only if a reconciliation is not already planned + // to happen in the following c.MinEventSyncInterval + if !c.nextRunAt.Before(now.Add(c.MinEventSyncInterval)) { + c.nextRunAt = now.Add(c.MinEventSyncInterval) + } } func (c *Controller) ShouldRunOnce(now time.Time) bool { diff --git a/controller/controller_test.go b/controller/controller_test.go index 27d01777c..8781385bb 100644 --- a/controller/controller_test.go +++ b/controller/controller_test.go @@ -19,12 +19,13 @@ package controller import ( "context" "errors" - "github.com/prometheus/client_golang/prometheus" "math" "reflect" "testing" "time" + "github.com/prometheus/client_golang/prometheus" + "sigs.k8s.io/external-dns/endpoint" "sigs.k8s.io/external-dns/internal/testutils" "sigs.k8s.io/external-dns/pkg/apis/externaldns" @@ -236,6 +237,17 @@ func TestShouldRunOnce(t *testing.T) { // But not two times assert.False(t, ctrl.ShouldRunOnce(now)) + + // Multiple ingresses or services changes, closer than MinInterval from each other + firstChangeTime := now + secondChangeTime := firstChangeTime.Add(time.Second) + // First change + ctrl.ScheduleRunOnce(firstChangeTime) + // Second change + ctrl.ScheduleRunOnce(secondChangeTime) + // Should not postpone the reconciliation further than firstChangeTime + MinInterval + now = now.Add(ctrl.MinEventSyncInterval) + assert.True(t, ctrl.ShouldRunOnce(now)) } func testControllerFiltersDomains(t *testing.T, configuredEndpoints []*endpoint.Endpoint, domainFilter endpoint.DomainFilterInterface, providerEndpoints []*endpoint.Endpoint, expectedChanges []*plan.Changes) { From 6e75baa3563a1084d3e0f242ceec0526283467af Mon Sep 17 00:00:00 2001 From: Claudiu Mocanu Date: Sat, 23 Jul 2022 17:47:38 +0300 Subject: [PATCH 2/2] Fixed type as suggested Co-authored-by: Raffaele Di Fazio --- controller/controller.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controller/controller.go b/controller/controller.go index 66228c3ea..eeaeb2717 100644 --- a/controller/controller.go +++ b/controller/controller.go @@ -242,7 +242,7 @@ func filterARecords(endpoints []*endpoint.Endpoint) []string { func (c *Controller) ScheduleRunOnce(now time.Time) { c.nextRunAtMux.Lock() defer c.nextRunAtMux.Unlock() - // Shedule only if a reconciliation is not already planned + // schedule only if a reconciliation is not already planned // to happen in the following c.MinEventSyncInterval if !c.nextRunAt.Before(now.Add(c.MinEventSyncInterval)) { c.nextRunAt = now.Add(c.MinEventSyncInterval)