You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.2 KiB
63 lines
1.2 KiB
1 year ago
|
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)
|
||
|
}
|