mirror of
https://github.com/coredns/coredns.git
synced 2025-10-27 08:14:18 -04:00
clouddns,route53: fix lingering goroutines after restart (#4096)
Stop the context so the refresh loop terminates on restart. Fixes: #3815 Signed-off-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
@@ -46,14 +46,14 @@ func setup(c *caddy.Controller) error {
|
|||||||
for i := 0; i < len(args); i++ {
|
for i := 0; i < len(args); i++ {
|
||||||
parts := strings.SplitN(args[i], ":", 3)
|
parts := strings.SplitN(args[i], ":", 3)
|
||||||
if len(parts) != 3 {
|
if len(parts) != 3 {
|
||||||
return c.Errf("invalid zone '%s'", args[i])
|
return plugin.Error("clouddns", c.Errf("invalid zone %q", args[i]))
|
||||||
}
|
}
|
||||||
dnsName, projectName, hostedZone := parts[0], parts[1], parts[2]
|
dnsName, projectName, hostedZone := parts[0], parts[1], parts[2]
|
||||||
if dnsName == "" || projectName == "" || hostedZone == "" {
|
if dnsName == "" || projectName == "" || hostedZone == "" {
|
||||||
return c.Errf("invalid zone '%s'", args[i])
|
return plugin.Error("clouddns", c.Errf("invalid zone %q", args[i]))
|
||||||
}
|
}
|
||||||
if _, ok := keyPairs[args[i]]; ok {
|
if _, ok := keyPairs[args[i]]; ok {
|
||||||
return c.Errf("conflict zone '%s'", args[i])
|
return plugin.Error("clouddns", c.Errf("conflict zone %q", args[i]))
|
||||||
}
|
}
|
||||||
|
|
||||||
keyPairs[args[i]] = struct{}{}
|
keyPairs[args[i]] = struct{}{}
|
||||||
@@ -64,18 +64,17 @@ func setup(c *caddy.Controller) error {
|
|||||||
for c.NextBlock() {
|
for c.NextBlock() {
|
||||||
switch c.Val() {
|
switch c.Val() {
|
||||||
case "upstream":
|
case "upstream":
|
||||||
c.RemainingArgs() // eats args
|
c.RemainingArgs()
|
||||||
// if filepath is provided in the Corefile use it to authenticate the dns client
|
|
||||||
case "credentials":
|
case "credentials":
|
||||||
if c.NextArg() {
|
if c.NextArg() {
|
||||||
opt = option.WithCredentialsFile(c.Val())
|
opt = option.WithCredentialsFile(c.Val())
|
||||||
} else {
|
} else {
|
||||||
return c.ArgErr()
|
return plugin.Error("clouddns", c.ArgErr())
|
||||||
}
|
}
|
||||||
case "fallthrough":
|
case "fallthrough":
|
||||||
fall.SetZonesFromArgs(c.RemainingArgs())
|
fall.SetZonesFromArgs(c.RemainingArgs())
|
||||||
default:
|
default:
|
||||||
return c.Errf("unknown property '%s'", c.Val())
|
return plugin.Error("clouddns", c.Errf("unknown property %q", c.Val()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,18 +86,19 @@ func setup(c *caddy.Controller) error {
|
|||||||
|
|
||||||
h, err := New(ctx, client, keys, up)
|
h, err := New(ctx, client, keys, up)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Errf("failed to create Cloud DNS plugin: %v", err)
|
return plugin.Error("clouddns", c.Errf("failed to create plugin: %v", err))
|
||||||
}
|
}
|
||||||
h.Fall = fall
|
h.Fall = fall
|
||||||
|
|
||||||
if err := h.Run(ctx); err != nil {
|
if err := h.Run(ctx); err != nil {
|
||||||
return c.Errf("failed to initialize Cloud DNS plugin: %v", err)
|
return plugin.Error("clouddns", c.Errf("failed to initialize plugin: %v", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler {
|
dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler {
|
||||||
h.Next = next
|
h.Next = next
|
||||||
return h
|
return h
|
||||||
})
|
})
|
||||||
|
c.OnShutdown(func() error { ctx.Done(); return nil })
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ func TestRoute53(t *testing.T) {
|
|||||||
|
|
||||||
r, err := New(ctx, fakeRoute53{}, map[string][]string{"bad.": {"0987654321"}}, time.Minute)
|
r, err := New(ctx, fakeRoute53{}, map[string][]string{"bad.": {"0987654321"}}, time.Minute)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to create Route53: %v", err)
|
t.Fatalf("Failed to create route53: %v", err)
|
||||||
}
|
}
|
||||||
if err = r.Run(ctx); err == nil {
|
if err = r.Run(ctx); err == nil {
|
||||||
t.Fatalf("Expected errors for zone bad.")
|
t.Fatalf("Expected errors for zone bad.")
|
||||||
@@ -89,7 +89,7 @@ func TestRoute53(t *testing.T) {
|
|||||||
|
|
||||||
r, err = New(ctx, fakeRoute53{}, map[string][]string{"org.": {"1357986420", "1234567890"}, "gov.": {"Z098765432", "1234567890"}}, 90*time.Second)
|
r, err = New(ctx, fakeRoute53{}, map[string][]string{"org.": {"1357986420", "1234567890"}, "gov.": {"Z098765432", "1234567890"}}, 90*time.Second)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to create Route53: %v", err)
|
t.Fatalf("Failed to create route53: %v", err)
|
||||||
}
|
}
|
||||||
r.Fall = fall.Zero
|
r.Fall = fall.Zero
|
||||||
r.Fall.SetZonesFromArgs([]string{"gov."})
|
r.Fall.SetZonesFromArgs([]string{"gov."})
|
||||||
@@ -117,7 +117,7 @@ func TestRoute53(t *testing.T) {
|
|||||||
})
|
})
|
||||||
err = r.Run(ctx)
|
err = r.Run(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to initialize Route53: %v", err)
|
t.Fatalf("Failed to initialize route53: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
|
|||||||
@@ -53,14 +53,14 @@ func setup(c *caddy.Controller) error {
|
|||||||
for i := 0; i < len(args); i++ {
|
for i := 0; i < len(args); i++ {
|
||||||
parts := strings.SplitN(args[i], ":", 2)
|
parts := strings.SplitN(args[i], ":", 2)
|
||||||
if len(parts) != 2 {
|
if len(parts) != 2 {
|
||||||
return plugin.Error("route53", c.Errf("invalid zone '%s'", args[i]))
|
return plugin.Error("route53", c.Errf("invalid zone %q", args[i]))
|
||||||
}
|
}
|
||||||
dns, hostedZoneID := parts[0], parts[1]
|
dns, hostedZoneID := parts[0], parts[1]
|
||||||
if dns == "" || hostedZoneID == "" {
|
if dns == "" || hostedZoneID == "" {
|
||||||
return plugin.Error("route53", c.Errf("invalid zone '%s'", args[i]))
|
return plugin.Error("route53", c.Errf("invalid zone %q", args[i]))
|
||||||
}
|
}
|
||||||
if _, ok := keyPairs[args[i]]; ok {
|
if _, ok := keyPairs[args[i]]; ok {
|
||||||
return plugin.Error("route53", c.Errf("conflict zone '%s'", args[i]))
|
return plugin.Error("route53", c.Errf("conflict zone %q", args[i]))
|
||||||
}
|
}
|
||||||
|
|
||||||
keyPairs[args[i]] = struct{}{}
|
keyPairs[args[i]] = struct{}{}
|
||||||
@@ -72,7 +72,7 @@ func setup(c *caddy.Controller) error {
|
|||||||
case "aws_access_key":
|
case "aws_access_key":
|
||||||
v := c.RemainingArgs()
|
v := c.RemainingArgs()
|
||||||
if len(v) < 2 {
|
if len(v) < 2 {
|
||||||
return plugin.Error("route53", c.Errf("invalid access key '%v'", v))
|
return plugin.Error("route53", c.Errf("invalid access key: '%v'", v))
|
||||||
}
|
}
|
||||||
providers = append(providers, &credentials.StaticProvider{
|
providers = append(providers, &credentials.StaticProvider{
|
||||||
Value: credentials.Value{
|
Value: credentials.Value{
|
||||||
@@ -102,16 +102,16 @@ func setup(c *caddy.Controller) error {
|
|||||||
}
|
}
|
||||||
refresh, err = time.ParseDuration(refreshStr)
|
refresh, err = time.ParseDuration(refreshStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return plugin.Error("route53", c.Errf("Unable to parse duration: '%v'", err))
|
return plugin.Error("route53", c.Errf("Unable to parse duration: %v", err))
|
||||||
}
|
}
|
||||||
if refresh <= 0 {
|
if refresh <= 0 {
|
||||||
return plugin.Error("route53", c.Errf("refresh interval must be greater than 0: %s", refreshStr))
|
return plugin.Error("route53", c.Errf("refresh interval must be greater than 0: %q", refreshStr))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return plugin.Error("route53", c.ArgErr())
|
return plugin.Error("route53", c.ArgErr())
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return plugin.Error("route53", c.Errf("unknown property '%s'", c.Val()))
|
return plugin.Error("route53", c.Errf("unknown property %q", c.Val()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,16 +127,17 @@ func setup(c *caddy.Controller) error {
|
|||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
h, err := New(ctx, client, keys, refresh)
|
h, err := New(ctx, client, keys, refresh)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return plugin.Error("route53", c.Errf("failed to create Route53 plugin: %v", err))
|
return plugin.Error("route53", c.Errf("failed to create route53 plugin: %v", err))
|
||||||
}
|
}
|
||||||
h.Fall = fall
|
h.Fall = fall
|
||||||
if err := h.Run(ctx); err != nil {
|
if err := h.Run(ctx); err != nil {
|
||||||
return plugin.Error("route53", c.Errf("failed to initialize Route53 plugin: %v", err))
|
return plugin.Error("route53", c.Errf("failed to initialize route53 plugin: %v", err))
|
||||||
}
|
}
|
||||||
dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler {
|
dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler {
|
||||||
h.Next = next
|
h.Next = next
|
||||||
return h
|
return h
|
||||||
})
|
})
|
||||||
|
c.OnShutdown(func() error { ctx.Done(); return nil })
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user