From 845de02631365764832565819bb610995216c870 Mon Sep 17 00:00:00 2001 From: jochen Date: Sun, 22 Nov 2026 01:12:33 +0100 Subject: [PATCH] Read a module's version through the registry seats' list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit H2's registry seat definitions fold the version read into list, filtered by module, so the validator refused the engine's manifest for invoking versions. The engine reads a version as a tag in list: oci-artifact-registry by the module, every page while it says next, the blob a manifest keeps; container-image-registry, whose list takes no module, by the repository's name. The manifest invokes list, and the node grant the tests run under follows it. Builds: design 47 H2 §779, §813 (7); H-A-350 DMC-10, H-A-415 (2) --- internal/nodegrant/testdata/node.json | 4 +- internal/selfcompose/selfcompose_test.go | 10 +-- internal/selfcompose/versions.go | 92 ++++++++++++++++-------- internal/selfcompose/versions_test.go | 31 +++++--- module.json | 6 +- 5 files changed, 94 insertions(+), 49 deletions(-) diff --git a/internal/nodegrant/testdata/node.json b/internal/nodegrant/testdata/node.json index e31dcc1c..8ef3e900 100644 --- a/internal/nodegrant/testdata/node.json +++ b/internal/nodegrant/testdata/node.json @@ -117,14 +117,14 @@ "mesh.control.NODE.>", "mesh.seat.mesh-catalog.call.entry.node~NODE", "mesh.seat.mesh-catalog.call.module.node~NODE", - "mesh.seat.container-image-registry.call.versions.node~NODE", + "mesh.seat.container-image-registry.call.list.node~NODE", "mesh.seat.mesh-catalog.call.revision.node~NODE", "mesh.seat.mesh-grants.call.withheld.node~NODE", "mesh.seat.mesh-module-assigner.call.assignments.node~NODE", "mesh.seat.mesh-recovery.call.kept-points.node~NODE", "mesh.seat.mesh-recovery.call.restore-kept.node~NODE", "mesh.seat.mesh-recovery.call.snapshot-kept.node~NODE", - "mesh.seat.oci-artifact-registry.call.versions.node~NODE", + "mesh.seat.oci-artifact-registry.call.list.node~NODE", "mesh.seat.mesh-catalog.call.seat-definitions.node~NODE", "mesh.seat.node-backup.call.backed-up.NODE.node~NODE", "mesh.seat.node-backup.call.now.NODE.node~NODE", diff --git a/internal/selfcompose/selfcompose_test.go b/internal/selfcompose/selfcompose_test.go index 69d67094..4126f872 100644 --- a/internal/selfcompose/selfcompose_test.go +++ b/internal/selfcompose/selfcompose_test.go @@ -470,8 +470,8 @@ func testTheNodeComposesItsWantsFromTheBus(t *testing.T) { // resolves the digests). e.Registry = EntryCall(func(_ context.Context, seat, _ string, args any) (json.RawMessage, error) { if seat == "container-image-registry" && args.(map[string]string)["name"] == "de-spiegel/site" { - return json.RawMessage(`{"name":"de-spiegel/site","versions":[{"name":"de-spiegel/site","kind":"image","digest":"sha256:` + - strings.Repeat("6", 64) + `","version":"1"}]}`), nil + return json.RawMessage(`{"repositories":[{"name":"de-spiegel/site","manifests":[{"digest":"sha256:` + + strings.Repeat("6", 64) + `","tags":["1"]}]}]}`), nil } return nil, errors.New("not held") }) @@ -1119,9 +1119,9 @@ func testTheNodeComposesItsWantsFromTheBus(t *testing.T) { catalogEntries[artFp] = artEntry // art's files archive at version 1, which the candidate "art-with" names (the candidate's version, never a digest). senv.Registry = EntryCall(func(_ context.Context, seat, _ string, args any) (json.RawMessage, error) { - if seat == "oci-artifact-registry" && args.(map[string]string)["name"] == "art/files" { - return json.RawMessage(`{"name":"art/files","versions":[{"name":"art/files","kind":"archive","digest":"sha256:` + - strings.Repeat("9", 64) + `","version":"1"}]}`), nil + if seat == "oci-artifact-registry" && args.(map[string]string)["module"] == "art" { + return json.RawMessage(`{"repositories":[{"name":"art/files","manifests":[{"digest":"sha256:` + strings.Repeat("8", 64) + + `","artifact":"sha256:` + strings.Repeat("9", 64) + `","tags":["1"]}]}]}`), nil } return nil, errors.New("not held") }) diff --git a/internal/selfcompose/versions.go b/internal/selfcompose/versions.go index 0e4ddae3..610f6601 100644 --- a/internal/selfcompose/versions.go +++ b/internal/selfcompose/versions.go @@ -19,7 +19,7 @@ import ( // **A want names its version; the node-engine resolves the digests** (design 47 G A-430, A-430a, the lead's answer A-430b). // A want of a released build names the module's version and no parts: each artifact of the build's entry is looked up at that -// version through the verb `versions` of the registry seat of its kind (oci-artifact-registry for a bundle or an archive, +// version through the verb `list` of the registry seat of its kind (oci-artifact-registry for a bundle or an archive, // container-image-registry for an image), under the name the builder numbered it by: `/`, or the entry's // package name for a package. An upstream copy is not numbered (it is mirrored by its pinned digest): its digest is the one its // manifest's `from` pins. A want that names parts (a build no version is known of) is read by its parts as before. A lookup that @@ -37,8 +37,12 @@ func (c *Composer) resolveAgain() time.Duration { return DefaultResolveAgain } -// versionsVerb is the verb a lookup asks. -const versionsVerb = "versions" +// listVerb is the verb a lookup asks: the registry seats read a version through `list`, filtered by module on +// oci-artifact-registry (design 47 H2 §813 (7), DMC-10, H-A-415 (2)). +const listVerb = "list" + +// listPagesMost bounds the pages one lookup reads of a seat's list. +const listPagesMost = 64 // resolvedKey names one resolution: a module's build at a version. type resolvedKey struct{ module, fp, version string } @@ -53,13 +57,21 @@ type versionParts struct { forgotten bool } -// registryVersions is the answer of either seat's verb `versions`: the two seats answer the same shape. -type registryVersions struct { - Versions []struct { - Digest string `json:"digest"` - Tag string `json:"tag,omitempty"` - Version string `json:"version,omitempty"` - } `json:"versions"` +// registryList is the answer of either seat's verb `list` (form 2): each repository with the manifests it holds, each +// manifest's digest, the blob it keeps (a bundle's or an archive's) and the tags naming it; capped with next when the rest +// is on another page. +type registryList struct { + Repositories []struct { + Name string `json:"name"` + Manifests []struct { + Digest string `json:"digest"` + Artifact string `json:"artifact,omitempty"` + Tags []string `json:"tags,omitempty"` + } `json:"manifests"` + } `json:"repositories"` + Capped bool `json:"capped,omitempty"` + Total int64 `json:"total,omitempty"` + Next string `json:"next,omitempty"` } // seatOfKind is the registry seat an artifact of kind is numbered in, and whether one is (design 51 *The seats*). @@ -218,7 +230,7 @@ func (c *Composer) lookUp(module string, e meshcatalog.CatalogEntry, w meshwants fail("(none)", a.Ref, "no registry seat the node-engine reads numbers an artifact of kind "+a.Kind) continue } - digest, why := c.versionDigest(seat, registryName(module, a), w) + digest, why := c.versionDigest(seat, module, registryName(module, a), w) if why != "" { fail(seat, a.Ref, why) continue @@ -232,30 +244,52 @@ func (c *Composer) lookUp(module string, e meshcatalog.CatalogEntry, w meshwants return parts, "" } -// versionDigest is the digest the seat's verb versions answers for name at w's version (its version or its tag), the newest -// first: a version names one build (A-430a), so the version alone is matched. -func (c *Composer) versionDigest(seat, name string, w meshwants.WantsByWantNodeModuleValue) (string, string) { +// versionDigest is the digest the seat's verb list answers for the repository name at w's version, a tag naming it: a +// version names one build (A-430a). oci-artifact-registry is asked for the module's repositories (`list {module}`) and +// answers the blob a manifest keeps, the digest a bundle or an archive is fetched by; container-image-registry, whose list +// takes no module, is asked for the repository by its name and answers the image manifest's digest. Every page is read +// while the answer says next (design 47 H2 §779, §813 (7), H-A-415 (2)). +func (c *Composer) versionDigest(seat, module, name string, w meshwants.WantsByWantNodeModuleValue) (string, string) { if c.env.Registry == nil { return "", "this node-engine reads no registry seat" } - raw, err := c.env.Registry("seat:"+seat+"."+versionsVerb, map[string]string{"name": name}) - if err != nil { - return "", fmt.Sprintf("the call for %s failed: %v", name, err) + in := map[string]string{"name": name} + if seat == ociartifactregistry.Seat { + in = map[string]string{"module": module} } - answer, said, ok := buscalls.Unwrap(raw) - if !ok { - return "", fmt.Sprintf("the seat refused %s: %s", name, said) - } - var v registryVersions - if err := json.Unmarshal(answer, &v); err != nil { - return "", fmt.Sprintf("its answer for %s cannot be read: %v", name, err) - } - for _, a := range v.Versions { - if (a.Version == w.Version || a.Tag == w.Version) && a.Digest != "" { - return a.Digest, "" + for page := 0; page < listPagesMost; page++ { + raw, err := c.env.Registry("seat:"+seat+"."+listVerb, in) + if err != nil { + return "", fmt.Sprintf("the call for %s failed: %v", name, err) } + answer, said, ok := buscalls.Unwrap(raw) + if !ok { + return "", fmt.Sprintf("the seat refused %s: %s", name, said) + } + var l registryList + if err := json.Unmarshal(answer, &l); err != nil { + return "", fmt.Sprintf("its answer for %s cannot be read: %v", name, err) + } + for _, r := range l.Repositories { + if r.Name != name { + continue + } + for _, m := range r.Manifests { + if !slices.Contains(m.Tags, w.Version) || m.Digest == "" { + continue + } + if seat == ociartifactregistry.Seat && m.Artifact != "" { + return m.Artifact, "" + } + return m.Digest, "" + } + } + if l.Next == "" { + return "", fmt.Sprintf("it holds no version %s of %s", w.Version, name) + } + in["next"] = l.Next } - return "", fmt.Sprintf("it holds no version %s of %s", w.Version, name) + return "", fmt.Sprintf("its list of %s did not end within %d pages", module, listPagesMost) } // pinnedDigest is the digest the manifest's upstream artifact pins in its from (`@sha256:`); "" when none. diff --git a/internal/selfcompose/versions_test.go b/internal/selfcompose/versions_test.go index 9b2fa862..1c22e10a 100644 --- a/internal/selfcompose/versions_test.go +++ b/internal/selfcompose/versions_test.go @@ -36,11 +36,13 @@ func aWantNamingItsVersionIsResolvedThroughTheRegistrySeats(t *testing.T) { }}} entry := meshcatalog.CatalogEntry{Module: "mail", Fp: fp, Manifest: manifest, Artifacts: []meshcatalog.Artifact{ {Ref: "mail:server", Kind: "upstream"}, {Ref: "mail:files", Kind: "archive"}, {Ref: "mail:web", Kind: "image"}}} - // The seats hold mail/files and mail/web; versions newest first. + // The seats hold mail/files and mail/web, each version a tag of its manifest; an archive's blob is what it is fetched + // by (design 47 H2 §813 (7), H-A-415 (2): the version is read through list). held := map[string]string{ - "oci-artifact-registry.mail/files": `{"name":"mail/files","versions":[{"name":"mail/files","kind":"archive","digest":"` + d("2") + `","version":"1.3.0"},{"name":"mail/files","kind":"archive","digest":"` + d("1") + `","version":"1.2.3"}]}`, - "container-image-registry.mail/web": `{"name":"mail/web","versions":[{"name":"mail/web","kind":"image","digest":"` + d("3") + `","version":"1.2.3"}]}`, - "container-image-registry.mail/other": `{"name":"mail/other","versions":[]}`, + "oci-artifact-registry.mail/files": `{"name":"mail/files","manifests":[{"digest":"` + d("8") + `","artifact":"` + d("2") + + `","tags":["1.3.0"]},{"digest":"` + d("7") + `","artifact":"` + d("1") + `","tags":["1.2.3"]}]}`, + "container-image-registry.mail/web": `{"name":"mail/web","manifests":[{"digest":"` + d("3") + `","tags":["1.2.3"]}]}`, + "container-image-registry.mail/other": `{"name":"mail/other","manifests":[]}`, } for name, row := range map[string]struct { want meshwants.WantsByWantNodeModuleValue @@ -62,17 +64,25 @@ func aWantNamingItsVersionIsResolvedThroughTheRegistrySeats(t *testing.T) { calls := 0 env.Registry = EntryCall(func(_ context.Context, seat, verb string, args any) (json.RawMessage, error) { calls++ - if verb != "versions" { - t.Errorf("%s: asked %s.%s", name, seat, verb) + in := args.(map[string]string) + // oci-artifact-registry is asked by the module, container-image-registry by the repository's name. + if verb != "list" || (seat == "oci-artifact-registry") != (in["module"] == "mail" && in["name"] == "") { + t.Errorf("%s: asked %s.%s %v", name, seat, verb, in) } if seat == row.down { return nil, errors.New("no responders") } - answer, ok := held[seat+"."+args.(map[string]string)["name"]] - if !ok { + var repos []string + for key, repo := range held { + r, ok := strings.CutPrefix(key, seat+".") + if ok && (r == in["name"] || (in["module"] != "" && strings.HasPrefix(r, in["module"]+"/"))) { + repos = append(repos, repo) + } + } + if len(repos) == 0 { return nil, errors.New("not held") } - return json.RawMessage(answer), nil + return json.RawMessage(`{"repositories":[` + strings.Join(repos, ",") + `]}`), nil }) env.Entry = EntryCall(func(context.Context, string, string, any) (json.RawMessage, error) { return nil, errors.New("not asked") @@ -311,7 +321,8 @@ func aResolutionWhoseFetchFailedIsForgotten(t *testing.T) { calls := 0 env.Registry = EntryCall(func(context.Context, string, string, any) (json.RawMessage, error) { calls++ - return json.RawMessage(`{"versions":[{"digest":"` + row.answer + `","version":"1.2.3"}]}`), nil + return json.RawMessage(`{"repositories":[{"name":"mail/files","manifests":[{"digest":"sha256:` + strings.Repeat("e", 64) + + `","artifact":"` + row.answer + `","tags":["1.2.3"]}]}]}`), nil }) env.Fetch = func(context.Context, string) ([]byte, error) { return body, row.fetch } env.Entry = EntryCall(func(context.Context, string, string, any) (json.RawMessage, error) { diff --git a/module.json b/module.json index c0ba5c01..928d52f7 100644 --- a/module.json +++ b/module.json @@ -45,7 +45,7 @@ } ], "invokes": [ - "seat:container-image-registry.versions", + "seat:container-image-registry.list", "seat:mesh-catalog.entry", "seat:mesh-catalog.module", {"verb": "seat:mesh-catalog.revision", "fields": ["none-yet"]}, @@ -56,7 +56,7 @@ "seat:mesh-recovery.restore-kept", "seat:mesh-recovery.snapshot-kept", "seat:node-packet-filter.allowed", - "seat:oci-artifact-registry.versions" + "seat:oci-artifact-registry.list" ], "consumes": [ "mesh-catalog.catalog-revision", @@ -125,7 +125,7 @@ }, "resolve-again-minutes": { "type": "number", - "description": "How long the node-engine holds a module whose want's version it could not resolve to its artifacts' digests, or whose resolution it forgot after a failed fetch, before it asks the registry seats' verb versions again, in minutes (design 47 H, H-A-146).", + "description": "How long the node-engine holds a module whose want's version it could not resolve to its artifacts' digests, or whose resolution it forgot after a failed fetch, before it asks the registry seats' verb list again, in minutes (design 47 H, H-A-146).", "minimum": 1, "maximum": 60, "default": 1