aboutsummaryrefslogtreecommitdiff
path: root/plugin
diff options
context:
space:
mode:
authorGravatar Matt Kulka <mattlqx@users.noreply.github.com> 2020-10-24 05:37:01 -0700
committerGravatar GitHub <noreply@github.com> 2020-10-24 14:37:01 +0200
commit3168a722cac244c91fc56e3a4d1d3d7fd48f0dd2 (patch)
tree0603f78383a7b7816935ed9590949ade23a29527 /plugin
parent054c9ae1fbea39d586652664fbc9a5cedbd97618 (diff)
downloadcoredns-3168a722cac244c91fc56e3a4d1d3d7fd48f0dd2.tar.gz
coredns-3168a722cac244c91fc56e3a4d1d3d7fd48f0dd2.tar.zst
coredns-3168a722cac244c91fc56e3a4d1d3d7fd48f0dd2.zip
Use cancelable contexts for cloud provider plugin refreshes (#4226)
This commit uses a cancelable context to spawn goroutines that refresh records from a cloud DNS provider. The Caddy shutdown routine uses the returned cancel function to terminate existing goroutines when a USR1 reload signal is received. Signed-off-by: Matt Kulka <mkulka@parchment.com>
Diffstat (limited to 'plugin')
-rw-r--r--plugin/azure/azure.go4
-rw-r--r--plugin/azure/setup.go3
-rw-r--r--plugin/clouddns/clouddns.go4
-rw-r--r--plugin/clouddns/setup.go4
-rw-r--r--plugin/route53/route53.go4
-rw-r--r--plugin/route53/setup.go4
6 files changed, 12 insertions, 11 deletions
diff --git a/plugin/azure/azure.go b/plugin/azure/azure.go
index f65503947..ac5c97f76 100644
--- a/plugin/azure/azure.go
+++ b/plugin/azure/azure.go
@@ -87,11 +87,11 @@ func (h *Azure) Run(ctx context.Context) error {
for {
select {
case <-ctx.Done():
- log.Infof("Breaking out of Azure update loop: %v", ctx.Err())
+ log.Debugf("Breaking out of Azure update loop for %v: %v", h.zoneNames, ctx.Err())
return
case <-time.After(1 * time.Minute):
if err := h.updateZones(ctx); err != nil && ctx.Err() == nil {
- log.Errorf("Failed to update zones: %v", err)
+ log.Errorf("Failed to update zones %v: %v", h.zoneNames, err)
}
}
}
diff --git a/plugin/azure/setup.go b/plugin/azure/setup.go
index 11506be6d..302555f11 100644
--- a/plugin/azure/setup.go
+++ b/plugin/azure/setup.go
@@ -25,7 +25,7 @@ func setup(c *caddy.Controller) error {
if err != nil {
return plugin.Error("azure", err)
}
- ctx := context.Background()
+ ctx, cancel := context.WithCancel(context.Background())
publicDNSClient := publicAzureDNS.NewRecordSetsClient(env.Values[auth.SubscriptionID])
if publicDNSClient.Authorizer, err = env.GetAuthorizer(); err != nil {
@@ -50,6 +50,7 @@ func setup(c *caddy.Controller) error {
h.Next = next
return h
})
+ c.OnShutdown(func() error { cancel(); return nil })
return nil
}
diff --git a/plugin/clouddns/clouddns.go b/plugin/clouddns/clouddns.go
index 3546a4fea..343b4ca53 100644
--- a/plugin/clouddns/clouddns.go
+++ b/plugin/clouddns/clouddns.go
@@ -85,11 +85,11 @@ func (h *CloudDNS) Run(ctx context.Context) error {
for {
select {
case <-ctx.Done():
- log.Infof("Breaking out of CloudDNS update loop: %v", ctx.Err())
+ log.Debugf("Breaking out of CloudDNS update loop for %v: %v", h.zoneNames, ctx.Err())
return
case <-time.After(1 * time.Minute):
if err := h.updateZones(ctx); err != nil && ctx.Err() == nil /* Don't log error if ctx expired. */ {
- log.Errorf("Failed to update zones: %v", err)
+ log.Errorf("Failed to update zones %v: %v", h.zoneNames, err)
}
}
}
diff --git a/plugin/clouddns/setup.go b/plugin/clouddns/setup.go
index a40b58432..507ae278e 100644
--- a/plugin/clouddns/setup.go
+++ b/plugin/clouddns/setup.go
@@ -78,7 +78,7 @@ func setup(c *caddy.Controller) error {
}
}
- ctx := context.Background()
+ ctx, cancel := context.WithCancel(context.Background())
client, err := f(ctx, opt)
if err != nil {
return err
@@ -98,7 +98,7 @@ func setup(c *caddy.Controller) error {
h.Next = next
return h
})
- c.OnShutdown(func() error { ctx.Done(); return nil })
+ c.OnShutdown(func() error { cancel(); return nil })
}
return nil
diff --git a/plugin/route53/route53.go b/plugin/route53/route53.go
index c1e495fbf..930acc6d3 100644
--- a/plugin/route53/route53.go
+++ b/plugin/route53/route53.go
@@ -87,11 +87,11 @@ func (h *Route53) Run(ctx context.Context) error {
for {
select {
case <-ctx.Done():
- log.Infof("Breaking out of Route53 update loop: %v", ctx.Err())
+ log.Debugf("Breaking out of Route53 update loop for %v: %v", h.zoneNames, ctx.Err())
return
case <-time.After(h.refresh):
if err := h.updateZones(ctx); err != nil && ctx.Err() == nil /* Don't log error if ctx expired. */ {
- log.Errorf("Failed to update zones: %v", err)
+ log.Errorf("Failed to update zones %v: %v", h.zoneNames, err)
}
}
}
diff --git a/plugin/route53/setup.go b/plugin/route53/setup.go
index 2f6ee8fc1..182231662 100644
--- a/plugin/route53/setup.go
+++ b/plugin/route53/setup.go
@@ -124,7 +124,7 @@ func setup(c *caddy.Controller) error {
Client: ec2metadata.New(session),
})
client := f(credentials.NewChainCredentials(providers))
- ctx := context.Background()
+ ctx, cancel := context.WithCancel(context.Background())
h, err := New(ctx, client, keys, refresh)
if err != nil {
return plugin.Error("route53", c.Errf("failed to create route53 plugin: %v", err))
@@ -137,7 +137,7 @@ func setup(c *caddy.Controller) error {
h.Next = next
return h
})
- c.OnShutdown(func() error { ctx.Done(); return nil })
+ c.OnShutdown(func() error { cancel(); return nil })
}
return nil
}