Declare the directories that hold the data
novox/hq 04-ISSUES/026. Four modules mounted fourteen host paths that no resource declared — the mail spool, the databases, the object store's data. Each would be created by the container runtime as root, with a mode nobody chose, so `owner` and `mode` went unapplied on exactly the directories that matter. The worse half: a directory the mesh declared and no longer wants is kept rather than removed when it holds anything the mesh did not put there. That rule is the answer to what happens to data when a module goes away, and it is written in terms of declared directories. An undeclared one is not covered. So the one rule guarding against data loss reached the configuration directories, which are cheap to lose, and missed the data directories, which are why the rule exists. The cause is worth naming. These manifests were written by reading the arrangement being replaced and carrying its compose files across — service, image, ports, volumes, environment. The container shape can express all of that, which is what made the transliteration feel like progress. A shape that can express a compose file gets filled in like one, and a volume line borrowed from compose declares no owner, no mode and no intent. Declared parent-first, because the host applies in the order written and does not sort. The check is mechanical now, because a person comparing volumes against directories by hand is the process that produced this. Still open, and bigger: whether these paths are where a module's data should live at all. They were inherited whole, and they decide what a person backs up.
This commit is contained in:
@@ -505,3 +505,67 @@ func TestEveryImageTheExamplesNameIsOneThisRepositoryBuilds(t *testing.T) {
|
||||
t.Fatal("no example names an image this repository builds, so this proves nothing")
|
||||
}
|
||||
}
|
||||
|
||||
// Every host path a container mounts is a directory the module declared.
|
||||
//
|
||||
// **The mesh owns a directory or it does not** (novox/hq 04-ISSUES/026). A bind mount whose source
|
||||
// does not exist is created by the container runtime as root, with a mode nobody chose — so
|
||||
// `owner` and `mode` go unapplied on exactly the directories that hold the data.
|
||||
//
|
||||
// Worse, the rule that a directory is *kept* rather than removed when it holds something the mesh
|
||||
// did not put there (ADR 0030) is written in terms of declared directories. An undeclared one is
|
||||
// not covered by it. So the single rule guarding against data loss reached the configuration and
|
||||
// not the data.
|
||||
//
|
||||
// These manifests were written by carrying compose files across, and a container shape that can
|
||||
// express a compose file gets filled in like one. This is the check that says so.
|
||||
func TestEveryMountedPathIsADirectoryTheModuleDeclared(t *testing.T) {
|
||||
found, _ := filepath.Glob("*.json")
|
||||
var checked int
|
||||
for _, name := range found {
|
||||
m := read(t, name)
|
||||
declared := map[string]bool{}
|
||||
for _, r := range m.Resources {
|
||||
if fmt.Sprint(r["type"]) == "directory" {
|
||||
declared[fmt.Sprint(r["path"])] = true
|
||||
}
|
||||
}
|
||||
for _, r := range m.Resources {
|
||||
for _, v := range stringsOfTest(r["volumes"]) {
|
||||
host, _, _ := strings.Cut(v, ":")
|
||||
if !strings.HasPrefix(host, "/") {
|
||||
continue // a named volume, which the runtime owns and the mesh does not
|
||||
}
|
||||
checked++
|
||||
var covered bool
|
||||
for d := range declared {
|
||||
if host == d || strings.HasPrefix(host, strings.TrimRight(d, "/")+"/") {
|
||||
covered = true
|
||||
}
|
||||
}
|
||||
if !covered {
|
||||
t.Errorf(
|
||||
"%s: %v mounts %s and no resource declares it. The runtime will create it "+
|
||||
"as root, and the rule that keeps a directory holding data does not "+
|
||||
"reach a directory the mesh never declared",
|
||||
name, r["id"], host)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if checked == 0 {
|
||||
t.Fatal("no example mounts a host path, so this test proves nothing")
|
||||
}
|
||||
}
|
||||
|
||||
func stringsOfTest(v any) []string {
|
||||
list, ok := v.([]any)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
out := make([]string, 0, len(list))
|
||||
for _, item := range list {
|
||||
out = append(out, fmt.Sprint(item))
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user