-
Notifications
You must be signed in to change notification settings - Fork 1
/
merge.go
43 lines (38 loc) · 898 Bytes
/
merge.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package dynamicupdate
import (
"github.com/coredns/coredns/plugin/file"
)
// Merge the dynamic zone with the static zone. Return a new zone.
func (d DynamicUpdate) Merge(origin string) *file.Zone {
z, ok := d.Zones.Z[origin]
if !ok || z == nil {
return nil
}
dz, ok := d.Zones.DynamicZones[origin]
if !ok || dz == nil {
return nil
}
// Lock the zones
z.RLock()
defer z.RUnlock()
dz.RLock()
defer dz.RUnlock()
// Make a copy of the base zone
newZone := z.Copy()
for _, e := range z.All() {
for _, rr := range e.All() {
if err := newZone.Insert(rr); err != nil {
log.Errorf("Failed to insert RR %s: %s", rr, err)
}
}
}
// Merge the dynamic zone with the static zone.
for _, te := range dz.All() {
for _, rr := range te.All() {
if err := newZone.Insert(rr); err != nil {
log.Errorf("Failed to insert RR %s: %s", rr, err)
}
}
}
return newZone
}