Alejandro Mery
1 year ago
2 changed files with 79 additions and 0 deletions
@ -0,0 +1,62 @@
|
||||
package dns |
||||
|
||||
import ( |
||||
"bytes" |
||||
"fmt" |
||||
"io" |
||||
"net/netip" |
||||
) |
||||
|
||||
// WriteTo writes the DNS data for the cluster
|
||||
func (mgr *Manager) WriteTo(w io.Writer) (int64, error) { |
||||
var buf bytes.Buffer |
||||
|
||||
cache := make(map[string][]netip.Addr) |
||||
|
||||
// zones
|
||||
for _, z := range mgr.zones { |
||||
mgr.writeZoneHosts(&buf, z) |
||||
|
||||
// zone alias
|
||||
addrs := mgr.genZoneAddresses(z) |
||||
zoneName := z.Name |
||||
|
||||
rr := AddrRecord{ |
||||
Name: mgr.fqdn(zoneName + mgr.suffix), |
||||
Addr: addrs, |
||||
} |
||||
_, _ = rr.WriteTo(&buf) |
||||
|
||||
// and cache for regions
|
||||
cache[zoneName] = addrs |
||||
} |
||||
|
||||
// regions, sorted
|
||||
for _, name := range mgr.genRegionsSorted() { |
||||
addrs := mgr.genRegionAddressesCached(name, cache) |
||||
|
||||
mgr.writeRegionAddresses(&buf, name, addrs) |
||||
} |
||||
|
||||
return buf.WriteTo(w) |
||||
} |
||||
|
||||
func (mgr *Manager) writeZoneHosts(w io.Writer, z *Zone) { |
||||
_, _ = fmt.Fprintf(w, ";\n; %s\n;\n", z.Name) |
||||
|
||||
for _, rr := range mgr.genZoneHostRecords(z) { |
||||
rr.Name = mgr.fqdn(rr.Name) |
||||
_, _ = rr.WriteTo(w) |
||||
} |
||||
} |
||||
|
||||
func (mgr *Manager) writeRegionAddresses(w io.Writer, name string, addrs []netip.Addr) { |
||||
_, _ = fmt.Fprintf(w, "; %s\n", name) |
||||
|
||||
rr := AddrRecord{ |
||||
Name: mgr.fqdn(name + mgr.suffix), |
||||
Addr: addrs, |
||||
} |
||||
|
||||
_, _ = rr.WriteTo(w) |
||||
} |
Loading…
Reference in new issue