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

@@ -6,6 +6,7 @@ import (
"reflect"
"sync"
"testing"
"time"
"github.com/coredns/coredns/plugin/file"
"github.com/coredns/coredns/plugin/pkg/dnstest"
@@ -134,7 +135,7 @@ func (c fakeGCPClient) listRRSets(_ctx context.Context, projectName, hostedZoneN
func TestCloudDNS(t *testing.T) {
ctx := context.Background()
r, err := New(ctx, fakeGCPClient{}, map[string][]string{"bad.": {"bad-project:bad-zone"}}, &upstream.Upstream{})
r, err := New(ctx, fakeGCPClient{}, map[string][]string{"bad.": {"bad-project:bad-zone"}}, &upstream.Upstream{}, time.Minute)
if err != nil {
t.Fatalf("Failed to create Cloud DNS: %v", err)
}
@@ -142,7 +143,7 @@ func TestCloudDNS(t *testing.T) {
t.Fatalf("Expected errors for zone bad.")
}
r, err = New(ctx, fakeGCPClient{}, map[string][]string{"org.": {"sample-project-1:sample-zone-2", "sample-project-1:sample-zone-1"}, "gov.": {"sample-project-1:sample-zone-2", "sample-project-1:sample-zone-1"}}, &upstream.Upstream{})
r, err = New(ctx, fakeGCPClient{}, map[string][]string{"org.": {"sample-project-1:sample-zone-2", "sample-project-1:sample-zone-1"}, "gov.": {"sample-project-1:sample-zone-2", "sample-project-1:sample-zone-1"}}, &upstream.Upstream{}, time.Minute)
if err != nil {
t.Fatalf("Failed to create Cloud DNS: %v", err)
}
@@ -339,6 +340,7 @@ func TestCloudDNSConcurrentServeDNS(t *testing.T) {
"org.": {"sample-project-1:sample-zone-2", "sample-project-1:sample-zone-1"},
},
&upstream.Upstream{},
time.Minute,
)
if err != nil {
t.Fatalf("Failed to create Cloud DNS: %v", err)
@@ -406,7 +408,8 @@ func TestCloudDNSConcurrentLookupNameCache(t *testing.T) {
map[string][]string{
"org.": {"sample-project-1:sample-zone-2", "sample-project-1:sample-zone-1"},
},
&upstream.Upstream{})
&upstream.Upstream{},
time.Minute)
if err != nil {
t.Fatalf("Failed to create Cloud DNS: %v", err)
}