plugin/clouddns: add refresh directive (#8616)

Brings clouddns to parity with route53, which already exposes a
refresh directive to control how often zones are re-synced. clouddns
currently hardcodes this to 1 minute (delay := 1 * time.Minute in Run)
with no way to change it.

Adds a refresh field to the CloudDNS struct, threads it through New(),
and has Run() use h.refresh instead of the hardcoded delay. Parses the
refresh directive in setup() mirroring route53's exact validation
(accepts a plain number as seconds or a duration string, must be
greater than 0).

Extends TestSetupCloudDNS with refresh coverage (valid duration, valid
plain number, missing arg, non-numeric, zero, negative). Verified it
fails without the setup.go change (unknown property error) and passes
with it.

Signed-off-by: stackedbyaradhya <aradhyaj736@gmail.com>
This commit is contained in:
Aradhya Jain
2026-10-09 07:17:32 +05:30
committed by GitHub
parent 45ac7fe659
commit 538c3554bc
5 changed files with 67 additions and 8 deletions

View File

@@ -5,7 +5,9 @@ import (
"encoding/json"
"fmt"
"os"
"strconv"
"strings"
"time"
"github.com/coredns/caddy"
"github.com/coredns/coredns/core/dnsserver"
@@ -64,6 +66,7 @@ func setup(c *caddy.Controller) error {
}
var opt option.ClientOption
refresh := time.Duration(1) * time.Minute // default update frequency to 1 minute
for c.NextBlock() {
switch c.Val() {
case "upstream":
@@ -79,6 +82,22 @@ func setup(c *caddy.Controller) error {
opt = option.WithAuthCredentialsFile(credType, c.Val())
case "fallthrough":
fall.SetZonesFromArgs(c.RemainingArgs())
case "refresh":
if !c.NextArg() {
return plugin.Error("clouddns", c.ArgErr())
}
refreshStr := c.Val()
_, err := strconv.Atoi(refreshStr)
if err == nil {
refreshStr += "s"
}
refresh, err = time.ParseDuration(refreshStr)
if err != nil {
return plugin.Error("clouddns", c.Errf("unable to parse duration: %v", err))
}
if refresh <= 0 {
return plugin.Error("clouddns", c.Errf("refresh interval must be greater than 0: %q", refreshStr))
}
default:
return plugin.Error("clouddns", c.Errf("unknown property %q", c.Val()))
}
@@ -91,7 +110,7 @@ func setup(c *caddy.Controller) error {
return err
}
h, err := New(ctx, client, keys, up)
h, err := New(ctx, client, keys, up, refresh)
if err != nil {
cancel()
return plugin.Error("clouddns", c.Errf("failed to create plugin: %v", err))