Add a read-only Kubernetes source for zones, client groups and blocklists
The runtime can now take ClientGroup, BlockList and DNSZone objects (fancydns.k6n.net/v1alpha1) from a cluster with -kube, from a pod's service account or a kubeconfig alike. internal/kubesource watches them with dynamic informers, converts and validates each object on its own, and publishes an immutable snapshot. A bad object is skipped and keeps its last good version, so one broken edit cannot remove a running policy; an invalid merged config is dropped whole. The last snapshot is saved so a restart without apiserver access still serves. config.Store gains an overlay: Base() is what the YAML says, Get() is base plus cluster objects. Everything that writes the config back (mutateConfig, SetAdminAddr, the settings editor) now starts from Base(), otherwise cluster objects would be copied into the file and shadow their own objects. YAML wins every name collision. putACL and toggleBlocklist refuse to edit cluster-owned objects. BlockList has no path field and refuses file:// URLs so a namespaced object cannot pick files the runtime reads or writes. DNSZone is rendered through the zone writer's own prove-by-reparse step, with the SOA serial taken from metadata.generation so every replica renders identical bytes. qlog: Flush reset the pending slice to [:0], so entries logged while it was still storing the batch were appended over the same backing array. The race detector found it through the new Kubernetes integration test. pending is now set to nil, with a regression test that fails without the change. CRD manifests, RBAC and examples are in deploy/k8s/crds; tests pin the schemas to the Go spec structs so the two cannot drift. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
340b4eaf80
commit
4d38945d94
27 files changed
+2250
-19
No files matched your search
+16
-1
@@ -16,6 +16,7 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"git.k8s-git-k6n.net/mats/fancy-dns/internal/acl"
|
||||
@@ -25,6 +26,7 @@ import (
|
||||
"git.k8s-git-k6n.net/mats/fancy-dns/internal/cluster"
|
||||
"git.k8s-git-k6n.net/mats/fancy-dns/internal/config"
|
||||
"git.k8s-git-k6n.net/mats/fancy-dns/internal/engine"
|
||||
"git.k8s-git-k6n.net/mats/fancy-dns/internal/kubesource"
|
||||
"git.k8s-git-k6n.net/mats/fancy-dns/internal/kubezones"
|
||||
"git.k8s-git-k6n.net/mats/fancy-dns/internal/localzone"
|
||||
"git.k8s-git-k6n.net/mats/fancy-dns/internal/metrics"
|
||||
@@ -47,6 +49,8 @@ type Options struct {
|
||||
// LogLevel and LogFormat override the config's logging settings.
|
||||
LogLevel string
|
||||
LogFormat string
|
||||
// Kube turns on the Kubernetes source for groups, lists and zones.
|
||||
Kube KubeOptions
|
||||
}
|
||||
|
||||
// App is the running process.
|
||||
@@ -65,6 +69,10 @@ type App struct {
|
||||
local *localzone.Holder
|
||||
// zones is the Kubernetes-sourced zone client.
|
||||
zones *kubezones.Client
|
||||
// kube watches the cluster's fancy-dns objects when enabled; kubeSnap is
|
||||
// what the config overlay merges in.
|
||||
kube *kubesource.Source
|
||||
kubeSnap atomic.Pointer[kubesource.Snapshot]
|
||||
// managedZones is the console-managed zone directory: the only zone data
|
||||
// the admin API may rewrite. An empty directory is what makes the
|
||||
// console's Zones page read-only.
|
||||
@@ -167,6 +175,10 @@ func (a *App) Start(ctx context.Context) error {
|
||||
if err := a.startLogger(cfg); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := a.startKube(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
cfg = a.cfg.Get() // the overlay may have changed it
|
||||
a.startBlocklist()
|
||||
a.startLocalZones(cfg)
|
||||
a.startUpstream(cfg)
|
||||
@@ -369,6 +381,9 @@ func (a *App) reloadLocalZones() {
|
||||
if a.managedZones.Exists() {
|
||||
paths = append(paths, a.managedZones.Dir())
|
||||
}
|
||||
if dir := a.kubeZoneDir(); dir != "" {
|
||||
paths = append(paths, dir)
|
||||
}
|
||||
if len(paths) == 0 {
|
||||
a.local.Set(nil)
|
||||
metrics.SetLocalRecords(0)
|
||||
@@ -866,7 +881,7 @@ func (a *App) Log() *slog.Logger { return a.log }
|
||||
// SetAdminAddr overrides the admin API listen address without touching the
|
||||
// config file, which is what a container platform's -admin-addr flag wants.
|
||||
func (a *App) SetAdminAddr(addr string) error {
|
||||
next := a.cfg.Get()
|
||||
next := a.cfg.Base()
|
||||
cp := *next
|
||||
cp.API = next.API
|
||||
cp.API.Listen = []string{addr}
|
||||
|
||||
Reference in new issue
Block a user