Add fancy-dns-console migrate to convert an existing deployment into cluster objects

The settings of the ConfigMap-and-YAML deployment have to become objects before
the mechanisms that held them can go. The command reads what the old console
wrote (the zone--<apex>.zone keys of the zones ConfigMap and the
address-overrides RPZ), and optionally the resolver's config.yaml, and converts:

  zone master files            -> DNSZone
  address-overrides RPZ        -> AddressOverride, one per name
  URL blocklists               -> BlockList
  allow_entries/block_entries  -> DomainRule inline-allow / inline-block
  acl.groups                   -> ClientGroup

By default it only prints manifests, which can be reviewed or committed; -apply
creates or updates the objects. It never deletes or edits the ConfigMaps or the
config. Each conversion is validated with the code the resolver uses to read the
objects, and anything it cannot represent faithfully is listed and left alone:
a zone with a record type the API does not write, a list that is a file on the
pod, a name that is not a legal object name, an RPZ line that is not an A or
AAAA override. Tests apply a conversion of the live data to a fake cluster and
read it back through the resolver's source, and run the command against fake
ConfigMaps, offline from files, and with the ConfigMaps missing.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
matsandClaude Sonnet 5.5 committed 2026-10-16 10:12:45 +02:00
1 parent bdcdbaf23a
commit 2f25463347
9 files changed
+919

No files matched your search

+34
View File
@@ -3,6 +3,8 @@ package localzone
import (
"fmt"
"strings"
"git.k8s-git-k6n.net/mats/fancy-dns/internal/zonefile"
)
// RenderZone renders a complete zone from declared records, for sources that
@@ -76,3 +78,35 @@ func CanonicalRecord(origin string, in Record) (Record, error) {
rec.TTL = in.TTL // 0 still means "the zone's default"
return rec, nil
}
// ZoneFile is a master file read back into the form a DNSZone holds it in.
type ZoneFile struct {
// TTL is the file's $TTL, or the default when it has none.
TTL uint32
// Soa is the SOA rdata ("ns mbox serial refresh retry expire minimum"), or
// "" when the file has none.
Soa string
Records []Record
}
// ParseZoneFile reads an RFC 1035 master file for the zone origin. Records come
// back canonical (absolute owner, uppercase type, rdata as the parser prints
// it) and without the SOA, which is returned separately. It is the reading half
// of a migration from master files to DNSZone objects.
func ParseZoneFile(origin, text string) (ZoneFile, error) {
origin, err := NormalizeOrigin(origin)
if err != nil {
return ZoneFile{}, fmt.Errorf("zone name: %w", err)
}
z, err := zonefile.Parse(strings.NewReader(text), zonefile.Options{Origin: origin, File: origin + "zone"})
if err != nil {
return ZoneFile{}, err
}
f := fileStateFromZone(z, origin)
out := ZoneFile{TTL: f.ttl, Records: f.recs}
if f.soa != nil {
out.Soa = fmt.Sprintf("%s %s %d %d %d %d %d", f.soa.Ns, f.soa.Mbox,
f.soa.Serial, f.soa.Refresh, f.soa.Retry, f.soa.Expire, f.soa.Minttl)
}
return out, nil
}