diff --git a/internal/agent/agent.go b/internal/agent/agent.go index a83ace65..72262646 100644 --- a/internal/agent/agent.go +++ b/internal/agent/agent.go @@ -1631,7 +1631,7 @@ func (a *Agent) apply(ctx context.Context, module string, w wantNow, comp compNo // A want with parts is applied only when they and the digests its composition fetches agree (design 47 G ยง524): the // module keeps running what it has, and the have says which digest differs. - if words := partsDifference(w.Want.Parts, comp.C.Resources); words != "" { + if words := partsDifference(w.Want.Parts, comp.C.Resources, comp.C.Templates); words != "" { a.mu.Lock() prev, runs := a.running[module] a.attempt[module] = attempt{FP: fp, Composed: dig, WantRev: w.Rev, CompRev: comp.Rev, Held: true, AnsweredRev: w.Rev} diff --git a/internal/agent/agent_test.go b/internal/agent/agent_test.go index 8ea01aa6..4a4989a2 100644 --- a/internal/agent/agent_test.go +++ b/internal/agent/agent_test.go @@ -364,33 +364,44 @@ func TestAWantAndItsCompositionApplyTheModuleAndTheHaveNamesBoth(t *testing.T) { } // A container's digest is the one after its image's @. container := json.RawMessage(`{"id":"web.c","type":"container","name":"web-c","image":"store/web@` + d3 + `","image-seat":"mesh-artifact-store","image-holder":"n1","module":"web"}`) - if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{container}); got != "" { + if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{container}, nil); got != "" { t.Fatalf("a container whose digest is in the parts differs: %q", got) } // A-454: an image the manifest pins from outside, by its digest, is no part of the want's parts, and a mesh-built one still is. upstream := json.RawMessage(`{"id":"web.u","type":"container","name":"web-u","image":"registry@` + d2 + `","module":"web"}`) - if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{container, upstream}); got != "" { + if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{container, upstream}, nil); got != "" { t.Fatalf("an upstream image pinned by its digest is a part: %q", got) } // And neither is the registry seat's copy of an upstream image, though it is routed through the seat. mirrored := json.RawMessage(`{"id":"web.m","type":"container","name":"web-m","image":"store:5000/upstream/docker.io/library/registry@` + d1 + `","image-seat":"container-image-registry","image-holder":"n1","module":"web"}`) - if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{container, mirrored}); got != "" { + if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{container, mirrored}, nil); got != "" { t.Fatalf("an upstream copy served through the registry seat is a part: %q", got) } - if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{upstream}); !strings.Contains(got, "in the want's parts and not fetched: "+d3) || strings.Contains(got, d2) { + if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{upstream}, nil); !strings.Contains(got, "in the want's parts and not fetched: "+d3) || strings.Contains(got, d2) { t.Fatalf("with only an upstream image the mesh-built one is not missing, or the upstream one is named: %q", got) } // A-454a: a mesh-built image whose seat holder is not on record carries no image-seat; its digest is in the parts, so it is fetched. noSeat := json.RawMessage(`{"id":"web.n","type":"container","name":"web-n","image":"store/web@` + d3 + `","module":"web"}`) - if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{noSeat}); got != "" { + if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{noSeat}, nil); got != "" { t.Fatalf("a mesh-built image with no image-seat, named by the parts, is not fetched: %q", got) } - if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{noSeat, upstream}); got != "" { + if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{noSeat, upstream}, nil); got != "" { t.Fatalf("an upstream image beside it is a part: %q", got) } + // A-481: a templates archive the composition was rendered from is fetched, one the want's parts do not name is a part + // the composition lacks, and the want's digest nothing read stays not fetched. + if got := partsDifference(map[string]string{"web:c": d3, "web:files": d1}, []json.RawMessage{container}, []string{d1}); got != "" { + t.Fatalf("a templates archive named by the parts and rendered from is fetched: %q", got) + } + if got := partsDifference(map[string]string{"web:c": d3, "web:files": d1}, []json.RawMessage{container}, nil); !strings.Contains(got, "in the want's parts and not fetched: "+d1) { + t.Fatalf("a templates archive nothing read stays not fetched: %q", got) + } + if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{container}, []string{d1}); !strings.Contains(got, "fetched and not in the want's parts: "+d1) { + t.Fatalf("a templates archive outside the parts differs: %q", got) + } // A-432: a runtime of its own runs the tool runner's program, which the module's parts do not name. ownRuntime := json.RawMessage(`{"id":"web.own-runtime","type":"process","name":"web-runtime","source":"store/node-tools","digest":"` + d1 + `","run":["./node-tools"],"module":"web"}`) - if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{container, ownRuntime}); got != "" { + if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{container, ownRuntime}, nil); got != "" { t.Fatalf("a runtime of its own differs from the module's parts: %q", got) } } diff --git a/internal/agent/parts.go b/internal/agent/parts.go index 5d19152b..bcd9c0eb 100644 --- a/internal/agent/parts.go +++ b/internal/agent/parts.go @@ -60,7 +60,7 @@ func upstreamCopy(image string) bool { // assigner of before G, or a node whose record does not state `want-parts`) is applied as today: it returns "". With // `parts`, the want is applied only when the digest of every resource fetched is among the values of `parts` and every // value of `parts` is the digest of a resource fetched; otherwise it returns the detail naming each digest. -func partsDifference(parts map[string]string, resources []json.RawMessage) string { +func partsDifference(parts map[string]string, resources []json.RawMessage, templates []string) string { if len(parts) == 0 { return "" } @@ -69,6 +69,11 @@ func partsDifference(parts map[string]string, resources []json.RawMessage) strin inParts[d] = true } fetched := map[string]bool{} + // A templates archive the composition was rendered from was read from the artifact store and checked by its digest: + // a part fetched (design 47 G A-481, A-481a). + for _, d := range templates { + fetched[d] = true + } for _, raw := range resources { r, err := declaration.ParseResource(raw) if err != nil { diff --git a/internal/compose/composed.go b/internal/compose/composed.go index eff389e5..6866fa9a 100644 --- a/internal/compose/composed.go +++ b/internal/compose/composed.go @@ -297,6 +297,10 @@ func compositions(in Input, node string, fps map[string]string, mode Mode, appli } if m, ok := in.Catalogue[c.Module]; ok && c.Module != "" { c.Data = len(m.DataItems()) > 0 + // The archive its files were rendered from, which the parts check counts as fetched (design 47 G A-481a). + if m.TemplatesDigest != "" { + c.Templates = []string{m.TemplatesDigest} + } out[key] = c } } diff --git a/internal/compose/composed_test.go b/internal/compose/composed_test.go index 11732c84..71eaf9b0 100644 --- a/internal/compose/composed_test.go +++ b/internal/compose/composed_test.go @@ -4,6 +4,7 @@ import ( "encoding/json" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient" engcomp "github.com/novox/mesh-host/internal/compositions" + "slices" "sort" "strings" "testing" @@ -32,10 +33,19 @@ func TestCompositionsAreTheDeclarationSplitByModule(t *testing.T) { sort.Strings(want) fps := map[string]string{"mesh-wireguard": fpFor('a'), "files": fpFor('b')} + // A-481a: the composition names the digest of the templates archive its module was rendered from. + templated := in.Catalogue["files"] + templated.TemplatesDigest = "sha256:" + strings.Repeat("e", 64) + in.Catalogue["files"] = templated out, skipped, err := Compositions(in, "laptop", fps, Foreseeing) if err != nil || len(skipped) != 0 { t.Fatalf("Compositions = %v, skipped %v", err, skipped) } + for _, c := range out { + if want := map[string][]string{"files": {templated.TemplatesDigest}}[c.Module]; !slices.Equal(c.Templates, want) { + t.Errorf("%s names the templates %v, want %v", c.Module, c.Templates, want) + } + } var got []string for key, c := range out { node, module, fp, isNode, err := engcomp.ParseKey(key) diff --git a/internal/compositions/composed.go b/internal/compositions/composed.go index 6549e389..5d1d730b 100644 --- a/internal/compositions/composed.go +++ b/internal/compositions/composed.go @@ -40,6 +40,8 @@ type Composed struct { Own NodeOwn Plan *catalogue.Plan Refused string + // Templates are the digests of the templates archives the module's files were rendered from, sorted (A-481a). + Templates []string } // Bucket constants of a node's compositions (the state composed is one bucket per node). @@ -65,7 +67,7 @@ func BucketFor(node string) (string, error) { func toClient(c Composed) (nodeengineclient.Composition, error) { out := nodeengineclient.Composition{V: c.V, Node: c.Node, Module: c.Module, FP: c.FP, Data: c.Data, - Resources: c.Resources, Filled: c.Filled, Refused: c.Refused} + Resources: c.Resources, Filled: c.Filled, Refused: c.Refused, Templates: c.Templates} raw, err := json.Marshal(c.Own) if err != nil { return out, err @@ -83,7 +85,7 @@ func toClient(c Composed) (nodeengineclient.Composition, error) { func fromClient(c nodeengineclient.Composition) (Composed, error) { out := Composed{V: c.V, Node: c.Node, Module: c.Module, FP: c.FP, Data: c.Data, Resources: c.Resources, - Filled: c.Filled, Refused: c.Refused} + Filled: c.Filled, Refused: c.Refused, Templates: c.Templates} raw, err := json.Marshal(c.Own) if err != nil { return out, err diff --git a/internal/compositions/composed_compare.go b/internal/compositions/composed_compare.go index ec3606ed..827a40be 100644 --- a/internal/compositions/composed_compare.go +++ b/internal/compositions/composed_compare.go @@ -150,6 +150,8 @@ func compareOne(module string, composed, running Composed, sameValue func(a, b s switch { case !jsonEqual(a.Filled, b.Filled): return differs("", "the files the provisioner fills differ") + case !jsonEqual(a.Templates, b.Templates): + return differs("", "the templates archives it was rendered from differ") case a.Data != b.Data: return differs("", "whether it declares data differs") case !jsonEqual(a.Own, b.Own):