diff --git a/internal/compose/node.go b/internal/compose/node.go index 1d52253f..c9be3575 100644 --- a/internal/compose/node.go +++ b/internal/compose/node.go @@ -2,6 +2,7 @@ package compose import ( "encoding/json" + "errors" "fmt" "sort" "strings" @@ -171,6 +172,29 @@ func ComposeIn(in Input, node string, mode Mode) (Declared, []string, error) { return d, validate.Declaration(body), nil } +// composeWithoutStoreFetchers is resolution.Compose where a module that fetches from the artifact store while the node reaches +// none (resolution.NoStoreError, whatever the shape: an image, a source, a tools bundle, a runtime program, a templates +// archive) is left out of the declaration with its words and the rest composes again; the node is never refused whole for it +// (design 47 G A-461, A-452). The rendering returned carries the modules so left out, for the filter and the rest to read. +func composeWithoutStoreFetchers(plan catalogue.Resolution, with catalogue.Rendering) (catalogue.Composed, catalogue.Rendering, error) { + for { + composed, err := resolution.Compose(plan, with) + var none *resolution.NoStoreError + if !errors.As(err, &none) { + return composed, with, err + } + if _, already := with.NotPlaced[none.Module]; already { + return catalogue.Composed{}, with, err + } + left := make(map[string]string, len(with.NotPlaced)+1) + for m, why := range with.NotPlaced { + left[m] = why + } + left[none.Module] = none.Error() + with.NotPlaced = left + } +} + // declaration is the controller's declarationWith over the plain Input. func (c *composer) declaration(nodeName string, mode Mode) (Declared, error) { resolved, err := c.planFor(nodeName) @@ -188,7 +212,7 @@ func (c *composer) declaration(nodeName string, mode Mode) (Declared, error) { with := rendered.Rendering with.Generators = gens plan := resolved.Plan - composed, err := resolution.Compose(plan, with) + composed, with, err := composeWithoutStoreFetchers(plan, with) if err != nil { return Declared{}, err } diff --git a/internal/compose/render.go b/internal/compose/render.go index 194c3da2..09d9b7be 100644 --- a/internal/compose/render.go +++ b/internal/compose/render.go @@ -125,16 +125,6 @@ func (c *composer) render(nodeName string, mode Mode) (Rendered, error) { } } - // A module that fetches from an artifact store with no known address waits for it; the machine composes the rest (A-461). - for module, why := range placed.storeHeld { - if r.NotPlaced == nil { - r.NotPlaced = map[string]string{} - } - if _, said := r.NotPlaced[module]; !said { - r.NotPlaced[module] = why - } - } - // And a certificate for this machine's name inside the mesh, when anything on it asks. for _, m := range plan.Modules { if m.Certificate == nil { diff --git a/internal/compose/rendering.go b/internal/compose/rendering.go index 4dfb2ed6..d7750d0f 100644 --- a/internal/compose/rendering.go +++ b/internal/compose/rendering.go @@ -10,7 +10,6 @@ import ( "git.novox.be/novox/mesh-networking/modules/mesh-wireguard/go/overlay" "git.novox.be/novox/mesh-sdk/go/catalogue" "github.com/novox/mesh-host/internal/compose/resolution" - "github.com/novox/mesh-host/internal/registryforms" ) // The contracts of the node-engine's statement that gate what a machine is sent, as the controller's link package names them @@ -42,8 +41,6 @@ type Placed struct { // manifest's own number as the Reading mode composes them, and never invented. The controller's adapter allocates and // composes again. ForeseenPorts []string - // storeHeld are the modules left out of the declaration because the artifact store has no known address, and why (A-461). - storeHeld map[string]string } // Places composes the place half of the rendering for a node (the controller's renderingFor in the Reading and Foreseeing modes, @@ -101,7 +98,6 @@ func (c *composer) places(nodeName string, resolved Resolved) (Placed, error) { var noAddress *storeListenError if errors.As(err, &noAddress) { // Only the store holder's listen refusal holds its fetchers; any other error still refuses the node (A-461b). - out.storeHeld = modulesNeedingTheStore(plan.Modules, err) store, err = "", nil } if err != nil { @@ -338,29 +334,6 @@ func (c *composer) namesInTheMesh() map[string]string { return out } -// modulesNeedingTheStore are the modules with a resource whose image or source is a kept reference into the artifact store, each -// with why it waits: nothing provides the store's address (A-461). -func modulesNeedingTheStore(modules []catalogue.Manifest, why error) map[string]string { - out := map[string]string{} - for _, m := range modules { - for _, res := range m.Resources { - needs := false - for _, key := range []string{"image", "source"} { - if written, ok := res[key].(string); ok { - if _, kept := registryforms.Forms.InArtifactStore(written); kept { - needs = true - } - } - } - if needs { - out[m.Module] = fmt.Sprintf("nothing provides %q, wanted by %s: %v", "the artifact store's address", m.Module, why) - break - } - } - } - return out -} - // StoreSeat is the seat whose holder is the artifact store (novox/hq ADR 0632 §1): the store's address is that holder's // listen open to the mesh, on the machine assignment puts it on. The provision artifact-store it was found by before is // retired; no module serves it. diff --git a/internal/compose/rendering_test.go b/internal/compose/rendering_test.go index e7bc84e0..698021a5 100644 --- a/internal/compose/rendering_test.go +++ b/internal/compose/rendering_test.go @@ -2,6 +2,7 @@ package compose import ( "errors" + "slices" "strings" "testing" @@ -351,23 +352,44 @@ func TestTheStoreIsFoundByTheImageSeatsHolderAndItsListen(t *testing.T) { m := in.Catalogue["registry"] m.Listens = append(m.Listens, catalogue.Listening{Name: "other", Port: 5300, From: catalogue.FromMesh}) in.Catalogue["registry"] = m - // A-461: a store with no known address (two listens open to the mesh, so none is a guess) costs the modules that fetch from - // it, not the node: those wait with the words of an unanswered requirement, and the node composes the rest. + // A-461, A-452: a node that reaches no store address (a holder opening two listens to the mesh, so none is a guess, or a holder + // laid name-only, found by nobody) costs the modules that fetch from it, whatever the shape of the fetch (an image, a tools + // bundle of the runtime), and never the node: they wait with the words of an unanswered requirement, and the rest composes. + dg := "sha256:" + strings.Repeat("a", 64) in.Catalogue["app"] = catalogue.Manifest{Module: "app", Version: "1", - Resources: []map[string]any{{"id": "c", "type": "container", "name": "app", "image": "artifact-store://app/c@sha256:" + strings.Repeat("a", 64)}}} - in.Catalogue["plain"] = catalogue.Manifest{Module: "plain", Version: "1"} + Resources: []map[string]any{{"id": "c", "type": "container", "name": "app", "image": "artifact-store://app/c@" + dg}}} + in.Catalogue["node-tools"] = catalogue.Manifest{Module: "node-tools", Version: "1", ToolRunner: true, + OwnSecrets: catalogue.OwnSecrets{"broker": {Path: "/var/lib/node-tools/broker"}}, + Bundles: []catalogue.Bundle{{Name: "runtime", Source: catalogue.ArtifactStoreScheme + "node-tools/runtime/blobs/" + dg, + Digest: dg, Language: "go", Binary: "node-tools"}}} + in.Catalogue["plain"] = catalogue.Manifest{Module: "plain", Version: "1", + Resources: []map[string]any{{"id": "state", "type": "directory", "path": "/var/lib/plain", "mode": "0700"}}} laptop := nodeOf(t, &in, "laptop") - laptop.Assigned = append(laptop.Assigned, "app", "plain") + laptop.Assigned = append(laptop.Assigned, "app", "node-tools", "plain") + laptop.SealingKey = keyOf(t, "laptop") + in.BusMinted = []string{"laptop.node-tools"} got, err := Render(in, "laptop", Reading) if err != nil { t.Fatalf("a holder opening two listens to the mesh refuses the whole node: %v", err) } - if why := got.Rendering.NotPlaced["app"]; !strings.Contains(why, "nothing provides") || !strings.Contains(why, "opens registry (5000), other (5300) to the mesh") { - t.Errorf("the module that fetches from the store waits with %q", why) + if got.Rendering.ArtifactStore != "" { + t.Errorf("the store has an address: %q", got.Rendering.ArtifactStore) } - if why, held := got.Rendering.NotPlaced["plain"]; held { + d, _, err := Compose(in, "laptop") + if err != nil { + t.Fatalf("a node that reaches no store address is refused whole: %v", err) + } + for _, m := range []string{"app", "node-tools"} { + if why := d.LeftOutWhy[m]; !strings.Contains(why, "nothing provides") || !strings.Contains(why, "no artifact store") { + t.Errorf("%s, which fetches from the store, waits with %q", m, why) + } + } + if why, held := d.LeftOutWhy["plain"]; held { t.Errorf("a module that fetches nothing from the store waits: %q", why) } + if !slices.ContainsFunc(d.Resources, func(r map[string]any) bool { return r["id"] == "plain.state" }) { + t.Errorf("the rest of the node was not composed: %v", d.Resources) + } // A-461b: only the listen refusal holds the store's fetchers; any other fault of finding the store (here the holder's machine is // on the network as first read but unknown when its assignment is read) still refuses the node. broken := newComposer(in) diff --git a/internal/compose/resolution/artifacts.go b/internal/compose/resolution/artifacts.go index dab2f869..71613ea4 100644 --- a/internal/compose/resolution/artifacts.go +++ b/internal/compose/resolution/artifacts.go @@ -8,6 +8,17 @@ import ( "github.com/novox/mesh-host/internal/registryforms" ) +// NoStoreError is a module that fetches from the artifact store while this node reaches none: it costs that module, never the +// node. The caller leaves the module out of the declaration, with these words (design 47 G A-461, A-452; ADR 0163 rule 6). +type NoStoreError struct { + Module string + said string +} + +func (e *NoStoreError) Error() string { + return fmt.Sprintf("nothing provides %q, wanted by %s: %s", "the artifact store's address", e.Module, e.said) +} + // artifactsInto composes the artifact store's address into a resource's `image` and `source`. // // **Composed here, at the last moment before a machine, and stored nowhere.** A kept reference is @@ -35,11 +46,11 @@ func artifactsInto(resource map[string]any, module string, with mcat.Rendering) } if _, kept := registryforms.Forms.InArtifactStore(written); kept { if with.ArtifactStore == "" { - return fmt.Errorf( + return &NoStoreError{Module: module, said: fmt.Sprintf( "%s's %v names %s, which is in the mesh's artifact store, and this mesh has no "+ "artifact store on its network to fetch it from — nothing assigned holds the seat "+ "container-image-registry, or the machine holding it is not on the private network", - module, resource["id"], written) + module, resource["id"], written)} } resource[key] = registryforms.Forms.Routed(written, with.ArtifactStore) imageSeatInto(resource, key, written, with)