mirror of
https://github.com/coredns/coredns.git
synced 2026-10-18 16:25:43 -04:00
plugin/azure: add refresh directive (#8614)
Brings azure to parity with route53, which already exposes a refresh directive to control how often zones are re-synced. azure currently hardcodes this to 1 minute (Run calls h.run(ctx, time.Minute)) with no way to change it, even though the internal run() method already takes an arbitrary interval parameter - the plumbing exists, it just wasn't exposed as a Corefile option. Adds a refresh field to the Azure struct, threads it through New(), and has Run() use h.refresh instead of the hardcoded value. Parses the refresh directive in parse() mirroring route53's exact validation (accepts a plain number as seconds or a duration string, must be greater than 0). Extends TestSetup 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:
@@ -33,6 +33,7 @@ type Azure struct {
|
||||
publicClient publicdns.RecordSetsClient
|
||||
privateClient privatedns.RecordSetsClient
|
||||
upstream *upstream.Upstream
|
||||
refresh time.Duration
|
||||
zMu sync.RWMutex
|
||||
zones zones
|
||||
updates sync.WaitGroup
|
||||
@@ -42,7 +43,8 @@ type Azure struct {
|
||||
}
|
||||
|
||||
// New initializes the configured DNS zones without contacting Azure.
|
||||
func New(_ctx context.Context, publicClient publicdns.RecordSetsClient, privateClient privatedns.RecordSetsClient, keys map[string][]string, accessMap map[string]string) (*Azure, error) {
|
||||
// refresh sets how often the zones are refreshed from Azure DNS.
|
||||
func New(_ctx context.Context, publicClient publicdns.RecordSetsClient, privateClient privatedns.RecordSetsClient, keys map[string][]string, accessMap map[string]string, refresh time.Duration) (*Azure, error) {
|
||||
zones := make(map[string][]*zone, len(keys))
|
||||
names := make([]string, 0, len(keys))
|
||||
for resourceGroup, znames := range keys {
|
||||
@@ -64,13 +66,14 @@ func New(_ctx context.Context, publicClient publicdns.RecordSetsClient, privateC
|
||||
zones: zones,
|
||||
zoneNames: names,
|
||||
upstream: upstream.New(),
|
||||
refresh: refresh,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Run starts initial and periodic zone synchronization in the background.
|
||||
func (h *Azure) Run(ctx context.Context) error {
|
||||
h.updates.Go(func() {
|
||||
h.run(ctx, time.Minute)
|
||||
h.run(ctx, h.refresh)
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user