Skip to content

Commit

Permalink
ScheduleRunOnce if not already scheduled
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiumocanu committed Feb 17, 2022
1 parent dd870ae commit 58ae184
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
6 changes: 5 additions & 1 deletion controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 13 additions & 1 deletion controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 58ae184

Please sign in to comment.