A machine's names are not suffixed twice: the facts take the internal names the control plane hands them (novox/hq issue 079)

This commit is contained in:
2026-09-22 01:13:28 +02:00
parent 713b43799f
commit b529c49cff
2 changed files with 40 additions and 3 deletions
+17 -3
View File
@@ -106,10 +106,11 @@ func nodeNames(r Resolution, addresses map[string]string) string {
b.WriteString("\n")
for _, name := range sortedNames(addresses) {
at := addresses[name]
internal, bare := meshName(name)
// Its mesh name resolves to its address on the private network rather than to loopback,
// so a service binding the name it was given stays reachable from everywhere else.
fmt.Fprintf(&b, "%s\t%s.internal\t%s", at, name, name)
if name == r.Node {
fmt.Fprintf(&b, "%s\t%s\t%s", at, internal, bare)
if bare == r.Node {
b.WriteString("\t# this machine")
}
b.WriteString("\n")
@@ -126,11 +127,24 @@ func nodeZones(_ Resolution, addresses map[string]string) string {
b.WriteString("# Generated by the mesh. Do not edit — this file is replaced whenever a machine\n")
b.WriteString("# joins or leaves, and an edit would survive until then and vanish.\n\n")
for _, name := range sortedNames(addresses) {
fmt.Fprintf(&b, "address=/%s.internal/%s\n", name, addresses[name])
internal, _ := meshName(name)
fmt.Fprintf(&b, "address=/%s/%s\n", internal, addresses[name])
}
return b.String()
}
// meshName is a machine's internal name and its bare one, from either. The control plane keys
// the names it hands a resolution by the internal name (`homer.internal`), the same map a
// container gets as its hosts; a caller that keys by the bare name gets the same answer. Written
// once, because the alternative was `homer.internal.internal` on every machine.
func meshName(name string) (internal, bare string) {
const suffix = ".internal"
if strings.HasSuffix(name, suffix) {
return name, strings.TrimSuffix(name, suffix)
}
return name + suffix, name
}
func sortedNames(addresses map[string]string) []string {
out := make([]string, 0, len(addresses))
for name, at := range addresses {