Split the console from the resolver: fancy-dns-console writes the cluster
fancy-dns-console is a second binary holding the web UI, authentication and every edit. It writes ClientGroup, BlockList and DNSZone objects through the new kubeedit package and forwards all other /api routes to a running resolver with its own key, dropping the browser's credentials, so it can run in the cluster or on a workstation with a kubeconfig and nothing about the resolver's placement matters. The resolver never imports kubeedit and the console is not on the DNS path. kubeedit validates every spec with the runtime's own converters (kubesource.CheckGroup/CheckList/CheckZone) before writing, so the console cannot store an object the resolver would reject. Zone edits keep the file-based writer's behaviour: duplicate and below-a-delegation records are refused, a delegation in a new zone also gives the zone its servers, and a zone with no apex NS is never stored. Each object records the editing user in an annotation; updates retry on conflict. The resolver reports groups from ClientGroup objects as source "kubernetes" and counter-only rows (the "(default)" bucket, or a group removed since) as "history", and lists DNSZone zones as the editable ones. The console uses that to leave the YAML's groups alone and to drop history rows, which the UI would otherwise send back on save. Its GET /api/clients overlays the cluster's current objects on the resolver's list, because the resolver only sees an edit after its watch fires and a save made just after another would delete the first. An end-to-end test runs both halves against one fake apiserver: a group saved through the console refuses queries, a zone built record by record answers authoritatively, and a request with the resolver's own key is rejected by the console. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4d38945d94
commit
1a536e7d0e
25 files changed
+1950
-8
No files matched your search
@@ -42,8 +42,19 @@ func convertGroup(u *unstructured.Unstructured) (group, error) {
|
||||
if err := spec(u, &s); err != nil {
|
||||
return group{}, err
|
||||
}
|
||||
return groupFromSpec(u.GetName(), s)
|
||||
}
|
||||
|
||||
// CheckGroup validates a ClientGroup spec the way the runtime will, so an
|
||||
// editor can refuse a bad one before it is written.
|
||||
func CheckGroup(name string, s ClientGroupSpec) (config.Group, error) {
|
||||
g, err := groupFromSpec(name, s)
|
||||
return g.cfg, err
|
||||
}
|
||||
|
||||
func groupFromSpec(name string, s ClientGroupSpec) (group, error) {
|
||||
g := config.Group{
|
||||
Name: u.GetName(),
|
||||
Name: name,
|
||||
Comment: s.Comment,
|
||||
Match: s.Match,
|
||||
Policy: s.Policy,
|
||||
@@ -92,8 +103,17 @@ func convertList(u *unstructured.Unstructured) (config.ListSource, error) {
|
||||
if err := spec(u, &s); err != nil {
|
||||
return config.ListSource{}, err
|
||||
}
|
||||
return listFromSpec(u.GetName(), s)
|
||||
}
|
||||
|
||||
// CheckList validates a BlockList spec the way the runtime will.
|
||||
func CheckList(name string, s BlockListSpec) (config.ListSource, error) {
|
||||
return listFromSpec(name, s)
|
||||
}
|
||||
|
||||
func listFromSpec(name string, s BlockListSpec) (config.ListSource, error) {
|
||||
l := config.ListSource{
|
||||
Name: u.GetName(),
|
||||
Name: name,
|
||||
Format: s.Format,
|
||||
URL: s.URL,
|
||||
Mirror: s.Mirror,
|
||||
@@ -152,6 +172,17 @@ func convertZone(u *unstructured.Unstructured) (zone, error) {
|
||||
if err := spec(u, &s); err != nil {
|
||||
return zone{}, err
|
||||
}
|
||||
return zoneFromSpec(s, u.GetGeneration())
|
||||
}
|
||||
|
||||
// CheckZone validates a DNSZone spec by rendering it exactly as the runtime
|
||||
// will, and returns the master file.
|
||||
func CheckZone(s DNSZoneSpec) (string, error) {
|
||||
z, err := zoneFromSpec(s, 1)
|
||||
return z.text, err
|
||||
}
|
||||
|
||||
func zoneFromSpec(s DNSZoneSpec, generation int64) (zone, error) {
|
||||
if s.Zone == "" {
|
||||
return zone{}, fmt.Errorf("spec.zone is required")
|
||||
}
|
||||
@@ -179,7 +210,7 @@ func convertZone(u *unstructured.Unstructured) (zone, error) {
|
||||
}
|
||||
// The generation changes exactly when the spec does, so every replica
|
||||
// renders the same bytes for the same object version.
|
||||
serial := uint32(u.GetGeneration())
|
||||
serial := uint32(generation)
|
||||
if serial == 0 {
|
||||
serial = 1
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user