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
@@ -21,6 +21,10 @@ func main() {
|
||||
checkOnly = flag.Bool("check", false, "validate the configuration and exit")
|
||||
logLevel = flag.String("log-level", os.Getenv("FANCYDNS_LOG_LEVEL"), "override log level (debug, info, warn, error)")
|
||||
logFormat = flag.String("log-format", os.Getenv("FANCYDNS_LOG_FORMAT"), "override log format (text, json)")
|
||||
kube = flag.Bool("kube", envBool("FANCYDNS_KUBE"), "watch Kubernetes for ClientGroup, BlockList and DNSZone objects")
|
||||
kubeconfig = flag.String("kubeconfig", os.Getenv("FANCYDNS_KUBECONFIG"), "kubeconfig for -kube (default: in-cluster service account, then $KUBECONFIG, then ~/.kube/config)")
|
||||
kubeContext = flag.String("kube-context", os.Getenv("FANCYDNS_KUBE_CONTEXT"), "kubeconfig context for -kube")
|
||||
kubeNS = flag.String("kube-namespace", os.Getenv("FANCYDNS_KUBE_NAMESPACE"), "namespace to watch for -kube (default: the pod's own, else all)")
|
||||
adminAddr = flag.String("admin-addr", os.Getenv("FANCYDNS_ADMIN_ADDR"), "override the admin API listen address")
|
||||
)
|
||||
flag.Parse()
|
||||
@@ -36,6 +40,12 @@ func main() {
|
||||
logFormat: *logFormat,
|
||||
adminAddr: *adminAddr,
|
||||
checkOnly: *checkOnly,
|
||||
kube: app.KubeOptions{
|
||||
Enabled: *kube || *kubeconfig != "" || *kubeContext != "",
|
||||
Kubeconfig: *kubeconfig,
|
||||
Context: *kubeContext,
|
||||
Namespace: *kubeNS,
|
||||
},
|
||||
}); err != nil {
|
||||
fmt.Fprintln(os.Stderr, "fancy-dns:", err)
|
||||
os.Exit(1)
|
||||
@@ -48,6 +58,7 @@ type runOptions struct {
|
||||
logFormat string
|
||||
adminAddr string
|
||||
checkOnly bool
|
||||
kube app.KubeOptions
|
||||
}
|
||||
|
||||
func run(o runOptions) error {
|
||||
@@ -56,6 +67,7 @@ func run(o runOptions) error {
|
||||
Version: app.Version,
|
||||
LogLevel: o.logLevel,
|
||||
LogFormat: o.logFormat,
|
||||
Kube: o.kube,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -124,3 +136,11 @@ func envOr(key, def string) string {
|
||||
}
|
||||
return def
|
||||
}
|
||||
|
||||
func envBool(key string) bool {
|
||||
switch os.Getenv(key) {
|
||||
case "1", "true", "TRUE", "True", "yes":
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
Reference in new issue
Block a user