feat(secondary): Send NOTIFY messages after zone transfer (#7901)

* feat(secondary): Send NOTIFY messages after zone transfer

- Modified TransferIn() method to accept a transfer.Transfer parameter
- Added NOTIFY message sending after successful zone transfer in secondary plugin
- Updated Update() method to pass the transfer handler through the zone update cycle
- Added comprehensive tests for the secondary notify functionality

Closes #5669

Signed-off-by: liucongran <liucongran327@gmail.com>

* fix(secondary): Fix TransferIn method call in test

Update test to pass nil parameter to TransferIn method after signature change

Signed-off-by: liucongran <liucongran327@gmail.com>

* refactor(secondary): Clean up imports and add helper methods

- Reorder imports for consistency
- Add hasSOA() and getSOA() helper methods to Zone
- Remove unnecessary blank lines in tests

Signed-off-by: liucongran <liucongran327@gmail.com>

* fix(test): Fix variable declaration in secondary test

Change corefile variable assignment to use short declaration syntax (:=)
to fix compilation error.

Signed-off-by: liucongran <liucongran327@gmail.com>

* refactor(secondary): Use getSOA helper method in shouldTransfer

Replace direct SOA access with getSOA() helper method for consistency.

Signed-off-by: liucongran <liucongran327@gmail.com>

---------

Signed-off-by: liucongran <liucongran327@gmail.com>
Co-authored-by: liucongran <liucongran@cestc.cn>
This commit is contained in:
liucongran
2026-03-08 13:15:44 +08:00
committed by GitHub
parent 90a9739478
commit 2daf48e42d
7 changed files with 170 additions and 20 deletions

View File

@@ -10,6 +10,7 @@ import (
clog "github.com/coredns/coredns/plugin/pkg/log"
"github.com/coredns/coredns/plugin/pkg/parse"
"github.com/coredns/coredns/plugin/pkg/upstream"
"github.com/coredns/coredns/plugin/transfer"
)
var log = clog.NewWithPlugin("secondary")
@@ -22,6 +23,17 @@ func setup(c *caddy.Controller) error {
return plugin.Error("secondary", err)
}
s := &Secondary{file.File{Zones: zones}}
var x *transfer.Transfer
c.OnStartup(func() error {
t := dnsserver.GetConfig(c).Handler("transfer")
if t != nil {
x = t.(*transfer.Transfer)
s.Xfer = x // if found this must be OK.
}
return nil
})
// Add startup functions to retrieve the zone and keep it up to date.
for i := range zones.Names {
n := zones.Names[i]
@@ -36,7 +48,7 @@ func setup(c *caddy.Controller) error {
dur := time.Millisecond * 250
max := time.Second * 10
for {
err := z.TransferIn()
err := z.TransferIn(x)
if err == nil {
break
}
@@ -52,7 +64,7 @@ func setup(c *caddy.Controller) error {
default:
}
}
z.Update(updateShutdown)
z.Update(updateShutdown, x)
}()
})
return nil
@@ -65,7 +77,8 @@ func setup(c *caddy.Controller) error {
}
dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler {
return Secondary{file.File{Next: next, Zones: zones}}
s.Next = next
return s
})
return nil