Reconcile with hq 128: hosts template is the region form, node-names is shared
The merge commit took only the staged index; these reconciliation edits sat unstaged in the working tree. Integrate the template mechanism with #79's region write (hq 128): RosterFile gains Shared, FactsInto sets into:block for a shared fact, /etc/hosts becomes the region form (no floor) and node-names is marked shared. Without this the merge would have regressed /etc/hosts back to a whole-file write, replacing the operator's own lines.
This commit is contained in:
@@ -33,6 +33,32 @@ func TestAModuleIsGivenTheFileItAskedFor(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// **A shared fact is written into a region of the machine's file, not over it** (novox/hq issue
|
||||
// 128). A hosts file is the machine's — its localhost, the operator's lines, other tools' blocks —
|
||||
// so the mesh owns only a marked region (`into: block`); a resolver's zones file is the mesh's
|
||||
// whole, and carries no `into`.
|
||||
func TestASharedFactIsWrittenIntoARegion(t *testing.T) {
|
||||
roster := map[string]string{"homer.internal": "10.42.0.1"}
|
||||
m := Manifest{Module: "net", Facts: map[string]RosterFile{
|
||||
"node-names": {Path: "/etc/hosts", Template: "{{range .Names}}{{.FQDN}}\n{{end}}", Shared: true},
|
||||
"node-zones": {Path: "/etc/zones", Template: "{{range .Machines}}{{.FQDN}}\n{{end}}"},
|
||||
}}
|
||||
given, err := FactsInto(m, Resolution{Node: "homer"}, roster, roster, "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
by := map[string]map[string]any{}
|
||||
for _, f := range given {
|
||||
by[f["path"].(string)] = f
|
||||
}
|
||||
if by["/etc/hosts"]["into"] != "block" {
|
||||
t.Fatalf("a shared fact is not written into a region, so the mesh writes the file whole: %v", by["/etc/hosts"])
|
||||
}
|
||||
if _, has := by["/etc/zones"]["into"]; has {
|
||||
t.Fatalf("an unshared fact was written into a region, so the mesh does not own its own file whole: %v", by["/etc/zones"])
|
||||
}
|
||||
}
|
||||
|
||||
// **The format is the module's — the mesh renders whatever template it gives.** The same roster
|
||||
// through two templates is two entirely different files, and the control plane reads neither.
|
||||
func TestTheFormatIsTheModulesOwn(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user