H8 fingerprint-readers: process-builds answers a container's build from its module's have, composition-diff names the value left from before H2
Builds: design 47 H2 H-A-710 (4) (hq 27369077)
This commit is contained in:
@@ -1044,7 +1044,13 @@ func runLink(ctx context.Context, opts options) error {
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), lookBound)
|
||||
defer cancel()
|
||||
return processbuilds.Reader{Node: mine.Node, Run: processbuilds.Runner(opts.run())}.Read(ctx, d, module), nil
|
||||
have := func(ctx context.Context, module string) string {
|
||||
if ag := current.get(); ag != nil {
|
||||
return ag.HaveFingerprint(ctx, module)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
return processbuilds.Reader{Node: mine.Node, Run: processbuilds.Runner(opts.run()), Have: have}.Read(ctx, d, module), nil
|
||||
}
|
||||
queue.Acts.Converged = func() (any, error) {
|
||||
return convergedOf(opts.state, func() ([]string, error) { return outward.Links("", "") })
|
||||
|
||||
@@ -977,6 +977,20 @@ func (a *Agent) Running() []compositions.Composed {
|
||||
return out
|
||||
}
|
||||
|
||||
// HaveFingerprint is the fingerprint the have of module names, the want's build the node-engine applied it from, and empty
|
||||
// when its have names none or cannot be read: a container is handed no fingerprint, so this is the build the seat's
|
||||
// process-builds answers for it (design 47 H2, H-A-710 (4)).
|
||||
func (a *Agent) HaveFingerprint(ctx context.Context, module string) string {
|
||||
if a.env.Haves == nil {
|
||||
return ""
|
||||
}
|
||||
h, ok := a.env.Haves.Read(ctx, module)
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
return h.FP
|
||||
}
|
||||
|
||||
// takeWant takes a change of a want key and returns the module it concerns, or "" for a key that is not a want.
|
||||
func (a *Agent) takeWant(u Update) string {
|
||||
a.mu.Lock()
|
||||
|
||||
@@ -2129,11 +2129,18 @@ func testTheNodesOwnCompositionIsAppliedWhenItDiffersAndARecordMoveWaitsForAYes(
|
||||
t.Error("composition-diff with neither a revision nor a digest was answered")
|
||||
}
|
||||
if got := DiffResources([]json.RawMessage{json.RawMessage(`{"id":"web.key","type":"file","sealed":"a","content":"x"}`),
|
||||
json.RawMessage(`{"id":"web.run","type":"process","env":{"MODE":"a","GONE":"1"}}`)},
|
||||
json.RawMessage(`{"id":"web.run","type":"process","env":{"MODE":"a","GONE":"1"}}`),
|
||||
json.RawMessage(`{"id":"web.box","type":"container","env":{"MESH_FINGERPRINT":"src2:a"}}`),
|
||||
json.RawMessage(`{"id":"web.d","type":"process","env":{"MESH_FINGERPRINT":"src2:a"}}`)},
|
||||
[]json.RawMessage{json.RawMessage(`{"id":"web.key","type":"file","sealed":"b","content":"y"}`),
|
||||
json.RawMessage(`{"id":"web.run","type":"process","env":{"MODE":"b"}}`)}); len(got) != 2 ||
|
||||
!slices.Equal(got[0].Entries, []nodeengine.CompositionDiffEntry{{Name: "content", Masked: true}, {Name: "sealed", Masked: true}}) ||
|
||||
!slices.Equal(got[1].Entries, []nodeengine.CompositionDiffEntry{{Name: "env.GONE", Running: "1"}, {Name: "env.MODE", Running: "a", Other: "b"}}) {
|
||||
json.RawMessage(`{"id":"web.run","type":"process","env":{"MODE":"b"}}`),
|
||||
json.RawMessage(`{"id":"web.box","type":"container"}`),
|
||||
json.RawMessage(`{"id":"web.d","type":"process","env":{"MESH_FINGERPRINT":"src2:b"}}`)}); len(got) != 4 ||
|
||||
!slices.Equal(got[2].Entries, []nodeengine.CompositionDiffEntry{{Name: "content", Masked: true}, {Name: "sealed", Masked: true}}) ||
|
||||
// H-A-710 (4): a container's difference of MESH_FINGERPRINT is left from before H2; a daemon's is an ordinary entry.
|
||||
!slices.Equal(got[0].Entries, []nodeengine.CompositionDiffEntry{{Name: "env.MESH_FINGERPRINT (left from before H2, taken out at the container's next recreate)", Running: "src2:a"}}) ||
|
||||
!slices.Equal(got[1].Entries, []nodeengine.CompositionDiffEntry{{Name: "env.MESH_FINGERPRINT", Running: "src2:a", Other: "src2:b"}}) ||
|
||||
!slices.Equal(got[3].Entries, []nodeengine.CompositionDiffEntry{{Name: "env.GONE", Running: "1"}, {Name: "env.MODE", Running: "a", Other: "b"}}) {
|
||||
t.Errorf("the entries that differ, a secret masked, read %+v", got)
|
||||
}
|
||||
// Issue 774 (ace, 2026-11-04 01:29): the node's own revision shows its own fields, the provisioner client's account
|
||||
|
||||
@@ -406,6 +406,9 @@ func (a *Agent) CompositionDiff(ctx context.Context, module string, revision int
|
||||
return answer, nil
|
||||
}
|
||||
|
||||
// fingerprintLeft says what a container's difference of its env MESH_FINGERPRINT is (design 47 H2, H-A-710 (4)).
|
||||
const fingerprintLeft = "left from before H2, taken out at the container's next recreate"
|
||||
|
||||
// DiffResources is, per resource by its id, the entries that differ from running to other (design 47 H2 §813 (3)): each
|
||||
// top-level field by its name, the environment's entries each by `env.<name>`, and a value the declaration keeps secret
|
||||
// (a file's sealed, vault-sealed or secrets, and the content of a file that has any of them) masked. Resources in id
|
||||
@@ -437,6 +440,10 @@ func DiffResources(running, other []json.RawMessage) []nodeengine.CompositionDif
|
||||
continue
|
||||
}
|
||||
e := nodeengine.CompositionDiffEntry{Name: name}
|
||||
if name == "env."+engcomp.FingerprintVar && (w.values["type"] == string(declaration.TypeContainer) || n.values["type"] == string(declaration.TypeContainer)) {
|
||||
// A container is handed none since H2 (H-A-710 (4)): what a composition from before holds is no change to make.
|
||||
e.Name = name + " (" + fingerprintLeft + ")"
|
||||
}
|
||||
if w.secret[name] || n.secret[name] {
|
||||
e.Masked = true
|
||||
} else {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
// Package processbuilds reads the build each process of this node was started with (design 47, *The fingerprint handover*):
|
||||
// the value MESH_FINGERPRINT the node-engine handed a daemon or a container at its start, read from the running process
|
||||
// itself, never from what the declaration would hand it now. A process started before the node-engine handed the value,
|
||||
// or one whose value cannot be read, says why its build is unknown instead of a fingerprint.
|
||||
// the value MESH_FINGERPRINT the node-engine handed a daemon at its start, read from the running process itself, never
|
||||
// from what the declaration would hand it now; a container is handed none (design 47 H2, H-A-710 (4)), so its build is the
|
||||
// one its module's have names. A process started before the node-engine handed the value, or one whose value cannot be
|
||||
// read, says why its build is unknown instead of a fingerprint.
|
||||
package processbuilds
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"sort"
|
||||
@@ -30,6 +30,9 @@ type Reader struct {
|
||||
Run Runner
|
||||
// Environ reads a process's environment by its pid; nil reads /proc/<pid>/environ.
|
||||
Environ func(pid int) ([]byte, error)
|
||||
// Have answers the fingerprint the have of a module names, the want's build the node-engine applied it from; empty
|
||||
// when the have names none. A container's build is that value (H-A-710 (4)); nil answers none.
|
||||
Have func(ctx context.Context, module string) string
|
||||
}
|
||||
|
||||
func (r Reader) environ(pid int) ([]byte, error) {
|
||||
@@ -116,16 +119,17 @@ func (r Reader) container(ctx context.Context, module, name string) nodeengine.P
|
||||
b.Unknown = "the container cannot be read: " + err.Error()
|
||||
return b
|
||||
}
|
||||
env, started, _ := strings.Cut(strings.TrimSpace(said), "\t")
|
||||
var vars []string
|
||||
if err := json.Unmarshal([]byte(env), &vars); err != nil {
|
||||
b.Unknown = "its environment cannot be read: " + err.Error()
|
||||
return b
|
||||
}
|
||||
_, started, _ := strings.Cut(strings.TrimSpace(said), "\t")
|
||||
if t, err := time.Parse(time.RFC3339Nano, started); err == nil {
|
||||
b.Started = &t
|
||||
}
|
||||
b.Fingerprint, b.Unknown = fingerprintIn(vars)
|
||||
// A container is handed none: its build is the one its module's have names, the composition it was applied from.
|
||||
if r.Have != nil {
|
||||
b.Fingerprint = r.Have(ctx, module)
|
||||
}
|
||||
if b.Fingerprint == "" {
|
||||
b.Unknown = "the have of " + module + " names no build"
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
// Design 47, *The fingerprint handover*: the build of a daemon is read from its running process's environment and of a
|
||||
// container from its configuration, narrowed by module; one started without the value, one not running and one the
|
||||
// container from the fingerprint its module's have names (it is handed none, H-A-710 (4)), narrowed by module; one started without the value, one not running and one the
|
||||
// runtime cannot read each say why their build is unknown, never a guessed fingerprint.
|
||||
func TestProcessBuildsAreReadFromTheRunningProcesses(t *testing.T) {
|
||||
fp := "src2:" + strings.Repeat("a", 64)
|
||||
@@ -19,6 +19,7 @@ func TestProcessBuildsAreReadFromTheRunningProcesses(t *testing.T) {
|
||||
&declaration.Process{ID: "old.d", Type: declaration.TypeProcess, Module: "old", Name: "old-d"},
|
||||
&declaration.Process{ID: "down.d", Type: declaration.TypeProcess, Module: "down", Name: "down-d"},
|
||||
&declaration.Container{ID: "db.c", Type: declaration.TypeContainer, Module: "db", Name: "db-c"},
|
||||
&declaration.Container{ID: "fresh.c", Type: declaration.TypeContainer, Module: "fresh", Name: "fresh-c"},
|
||||
&declaration.Container{ID: "gone.c", Type: declaration.TypeContainer, Module: "gone", Name: "gone-c"},
|
||||
&declaration.Directory{ID: "web.dir", Type: declaration.TypeDirectory, Module: "web"},
|
||||
}}
|
||||
@@ -31,7 +32,10 @@ func TestProcessBuildsAreReadFromTheRunningProcesses(t *testing.T) {
|
||||
case name == "systemctl":
|
||||
return "MainPID=0\nActiveEnterTimestamp=\n", nil
|
||||
case name == "docker" && args[len(args)-1] == "db-c":
|
||||
return `["A=1","MESH_FINGERPRINT=` + fp + `"]` + "\t2026-11-09T10:00:00.5Z\n", nil
|
||||
// A container is handed no fingerprint (H-A-710): what its env holds, if anything, is no build.
|
||||
return `["A=1","MESH_FINGERPRINT=src2:` + strings.Repeat("0", 64) + `"]` + "\t2026-11-09T10:00:00.5Z\n", nil
|
||||
case name == "docker" && args[len(args)-1] == "fresh-c":
|
||||
return `["A=1"]` + "\t2026-11-09T10:00:00.5Z\n", nil
|
||||
}
|
||||
return "", errors.New("no such container")
|
||||
}
|
||||
@@ -41,7 +45,13 @@ func TestProcessBuildsAreReadFromTheRunningProcesses(t *testing.T) {
|
||||
}
|
||||
return []byte("A=1\x00"), nil
|
||||
}
|
||||
r := Reader{Node: "n1", Run: run, Environ: environ}
|
||||
have := func(_ context.Context, module string) string {
|
||||
if module == "db" {
|
||||
return fp
|
||||
}
|
||||
return ""
|
||||
}
|
||||
r := Reader{Node: "n1", Run: run, Environ: environ, Have: have}
|
||||
got := r.Read(context.Background(), d, "")
|
||||
by := map[string]string{}
|
||||
for _, p := range got.Processes {
|
||||
@@ -49,7 +59,7 @@ func TestProcessBuildsAreReadFromTheRunningProcesses(t *testing.T) {
|
||||
}
|
||||
want := map[string]string{"web": fp + "|", "db": fp + "|",
|
||||
"old": "|started before the node-engine handed MESH_FINGERPRINT, or without it",
|
||||
"down": "|the unit runs no process now", "gone": "|the container cannot be read: no such container"}
|
||||
"down": "|the unit runs no process now", "fresh": "|the have of fresh names no build", "gone": "|the container cannot be read: no such container"}
|
||||
if len(by) != len(want) || got.Node != "n1" {
|
||||
t.Fatalf("read %v, want %v", by, want)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user