Skip to content

Commit

Permalink
Use exponential backoff for DNS updates
Browse files Browse the repository at this point in the history
  • Loading branch information
hakman committed Mar 9, 2021
1 parent 6ce35f9 commit d468bc2
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions dns-controller/pkg/dns/dnscontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
var zoneListCacheValidity = time.Minute * 15

const DefaultTTL = time.Minute
const MaxBackoff = time.Minute * 3

// DNSController applies the desired DNS state to the DNS backend
type DNSController struct {
Expand All @@ -56,6 +57,8 @@ type DNSController struct {
// changeCount is a change-counter, which helps us avoid computation when nothing has changed
changeCount uint64

// failCount is a fail-counter for exponential backoff
failCount uint64
// update loop frequency (seconds)
updateInterval time.Duration
}
Expand Down Expand Up @@ -120,10 +123,15 @@ func (c *DNSController) runWatcher(stopCh <-chan struct{}) {
}

if err != nil {
klog.Warningf("Unexpected error in DNS controller, will retry: %v", err)
time.Sleep(2 * c.updateInterval)
fails := atomic.AddUint64(&c.failCount, 1)
backoff := 1 << fails * c.updateInterval
if backoff > MaxBackoff {
backoff = MaxBackoff
}
klog.Warningf("Unexpected error in DNS controller, will retry in %s: %v", backoff, err)
time.Sleep(backoff)
} else {
// Simple debouncing; DNS servers are typically pretty slow anyway
atomic.StoreUint64(&c.failCount, 0)
time.Sleep(c.updateInterval)
}
}
Expand Down Expand Up @@ -308,7 +316,7 @@ func (c *DNSController) runOnce() error {
continue
}

klog.V(2).Infof("applying DNS changeset for zone %s", key)
klog.V(2).Infof("Applying DNS changeset for zone %s", key)
if err := changeset.Apply(ctx); err != nil {
klog.Warningf("error applying DNS changeset for zone %s: %v", key, err)
errors = append(errors, fmt.Errorf("error applying DNS changeset for zone %s: %v", key, err))
Expand Down Expand Up @@ -351,7 +359,7 @@ func (c *DNSController) RemoveRecordsImmediate(records []Record) error {
}

for key, changeset := range op.changesets {
klog.V(2).Infof("applying DNS changeset for zone %s", key)
klog.V(2).Infof("Applying DNS changeset for zone %s", key)
if err := changeset.Apply(ctx); err != nil {
klog.Warningf("error applying DNS changeset for zone %s: %v", key, err)
errors = append(errors, fmt.Errorf("error applying DNS changeset for zone %s: %v", key, err))
Expand Down

0 comments on commit d468bc2

Please sign in to comment.