plugin/route53: make refresh frequency adjustable (#3083)

the current update frequency for the refresh loop in the route 53 plugin is hard-coded
to 1 minute. aws rate-limits the number of api requests so less frequent record refreshes
can help when reaching those limits depending upon your individual scenarios. this pull
adds a configuration option to the route53 plugin to adjust the refresh frequency.

thanks for getting my last pull released so quickly. this is the last local change that
i have been running and would love to get it contributed back to the project.

Signed-off-by: Matt Kulka <mkulka@parchment.com>
This commit is contained in:
Matt Kulka
2019-08-03 18:07:28 -07:00
committed by dilyevsky
parent fc1e313ca7
commit 94468c41b0
5 changed files with 65 additions and 6 deletions

View File

@@ -2,7 +2,10 @@ package route53
import (
"context"
"fmt"
"strconv"
"strings"
"time"
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/plugin"
@@ -53,6 +56,8 @@ func setup(c *caddy.Controller, f func(*credentials.Credentials) route53iface.Ro
up := upstream.New()
refresh := time.Duration(1) * time.Minute // default update frequency to 1 minute
args := c.RemainingArgs()
for i := 0; i < len(args); i++ {
@@ -98,6 +103,23 @@ func setup(c *caddy.Controller, f func(*credentials.Credentials) route53iface.Ro
}
case "fallthrough":
fall.SetZonesFromArgs(c.RemainingArgs())
case "refresh":
if c.NextArg() {
refreshStr := c.Val()
_, err := strconv.Atoi(refreshStr)
if err == nil {
refreshStr = fmt.Sprintf("%ss", c.Val())
}
refresh, err = time.ParseDuration(refreshStr)
if err != nil {
return c.Errf("Unable to parse duration: '%v'", err)
}
if refresh <= 0 {
return c.Errf("refresh interval must be greater than 0: %s", refreshStr)
}
} else {
return c.ArgErr()
}
default:
return c.Errf("unknown property '%s'", c.Val())
}
@@ -107,7 +129,7 @@ func setup(c *caddy.Controller, f func(*credentials.Credentials) route53iface.Ro
})
client := f(credentials.NewChainCredentials(providers))
ctx := context.Background()
h, err := New(ctx, client, keys, up)
h, err := New(ctx, client, keys, up, refresh)
if err != nil {
return c.Errf("failed to create Route53 plugin: %v", err)
}