package app import ( "strings" "git.k8s-git-k6n.net/mats/fancy-dns/internal/api" "git.k8s-git-k6n.net/mats/fancy-dns/internal/localzone" ) // The resolver only reads zones. Master files from blocklist.local_zones and the // rendered DNSZone objects are compiled into one store; editing is the // console's job and happens on the objects. // listZones renders the compiled store for the console. func (a *App) listZones() (any, error) { // The zones that can be edited are the DNSZone objects, which the Kubernetes // source renders into a directory of its own. The resolver itself writes // nothing; the console, which can, reports the zones writable. dir := a.kubeZoneDir() store := a.local.Get() // The slices are never nil: the console reads lengths and maps without // a null check, and an empty list is a list. res := api.ZonesResponse{ Zones: []api.Zone{}, Files: []string{}, ManagedDir: dir, Writable: false, Types: localzone.EditableTypes(), } if store != nil { res.Files = store.Files() res.BuiltAt = store.BuiltAt() for _, zone := range store.SnapshotAll(dir) { res.Zones = append(res.Zones, *zone) res.Records += zone.RecordCount } } res.Error = a.localZoneError() return res, nil } // localZoneError is the reason the store is stale, or "" when it is current. // It comes from the degraded list, so the console and /healthz agree. func (a *App) localZoneError() string { for _, d := range a.Degraded() { if rest, ok := strings.CutPrefix(d, "local zones: "); ok { return rest } } return "" }