Merge pull request 'distribution serves name-of: the reference it keeps an upstream copy under (design 47 H2, H-A-513)' (#745) from fix/registry-name-of into main
This commit was merged in pull request #745.
This commit is contained in:
@@ -34,7 +34,7 @@ func jsonFields(v any) map[string]bool {
|
||||
func TestTheVerbsSpeakTheSeatsContract(t *testing.T) {
|
||||
inputs := map[string]any{reg.VerbPublish: reg.PublishInput{}, reg.VerbPublishPart: reg.PublishPartInput{},
|
||||
reg.VerbVersions: reg.VersionsInput{}, reg.VerbRemove: reg.RemoveInput{}, reg.VerbHold: reg.HoldInput{},
|
||||
reg.VerbRelease: reg.ReleaseInput{}, reg.VerbMirror: reg.MirrorInput{}, reg.VerbTags: reg.TagsInput{}}
|
||||
reg.VerbRelease: reg.ReleaseInput{}, reg.VerbMirror: reg.MirrorInput{}, reg.VerbNameOf: reg.NameOfInput{}, reg.VerbTags: reg.TagsInput{}}
|
||||
seen := 0
|
||||
for _, tool := range tools(&holder.Verbs{}, kept[holder.Window]{}, nil) {
|
||||
seat, verb, ok := strings.Cut(tool.Name, ".")
|
||||
@@ -51,8 +51,8 @@ func TestTheVerbsSpeakTheSeatsContract(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if seen != 14 {
|
||||
t.Errorf("%d seat verbs served, want 14 (8 on the image seat, 6 on the artifact seat)", seen)
|
||||
if seen != 15 {
|
||||
t.Errorf("%d seat verbs served, want 15 (9 on the image seat, 6 on the artifact seat)", seen)
|
||||
}
|
||||
for event, want := range map[string]any{holder.EventPublished: ®.Outcome{}, holder.EventKept: ®.KeptEvent{}, holder.EventHeld: ®.Hold{}, holder.EventReleased: ®.Hold{}} {
|
||||
b, _ := json.Marshal(eventBody(event, holder.Event{Name: "m/a", Kind: holder.KindArchive, Digest: "sha256:aa", Holder: holder.Self, By: "x.artifact-store-tools"}))
|
||||
|
||||
@@ -364,6 +364,19 @@ func tools(v *holder.Verbs, windows kept[holder.Window], taken *asks) []stdio.To
|
||||
}
|
||||
return reg.MirrorAnswer{Digest: in.Digest, Reference: ref}, nil
|
||||
}},
|
||||
stdio.Tool{Name: holder.ImageSeat + "." + holder.VerbNameOf, Description: "The reference an outside image, as a manifest's from names it pinned by its digest, is kept under in the store (upstream/<host>/<path>@<digest> in the seat's form), the one mirror answers; reads only, asks no copy, refuses a from with no digest.",
|
||||
Input: obj(map[string]any{"from": s("<name>[:<tag>]@sha256:…")}, "from"),
|
||||
Run: func(args map[string]any) (any, error) {
|
||||
in, err := arg[reg.NameOfInput](args)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ref, err := v.NameOf(holder.ImageSeat, in.From)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return reg.NameOfAnswer{Reference: ref}, nil
|
||||
}},
|
||||
stdio.Tool{Name: "registry_health", Description: "distribution's health check, run by the runtime each minute: versions of each seat asked through the store's read side (the program's port 5100); fails naming the program when it does not answer.",
|
||||
Input: obj(map[string]any{}),
|
||||
Run: func(map[string]any) (any, error) {
|
||||
|
||||
@@ -823,6 +823,18 @@ func TestTheHolderOfTheTwoImageSeats(t *testing.T) {
|
||||
if strings.ContainsAny(key, ":@") {
|
||||
t.Errorf("the ask's key %q holds characters a key may not", key)
|
||||
}
|
||||
// name-of answers the same reference for a manifest's pinned from, asking no copy (H-A-513); a from with no digest,
|
||||
// and the artifact seat, are refused.
|
||||
for _, from := range []string{"nats:2.11.17-alpine@" + d, "docker.io/library/nats@" + d} {
|
||||
if named, err := b.v.NameOf(ImageSeat, from); err != nil || named != want || len(asked) != 1 {
|
||||
t.Errorf("name-of %s = %q, %v, asks %d: want %s and no copy asked", from, named, err, len(asked), want)
|
||||
}
|
||||
}
|
||||
for seat, from := range map[string]string{ImageSeat: "nats:2.11.17-alpine", ArtifactSeat: "nats@" + d} {
|
||||
if named, err := b.v.NameOf(seat, from); err == nil {
|
||||
t.Errorf("name-of %s on %s = %q: want a refusal", from, seat, named)
|
||||
}
|
||||
}
|
||||
if err := b.v.Mirrored(asked[key]); err != nil || len(b.said) != 1 || b.said[0].event != EventPublished ||
|
||||
b.said[0].body.Reference != want || b.said[0].body.Kind != KindUpstream || len(asked) != 0 {
|
||||
t.Fatalf("the copy's end = %v, said %+v, asks %v: want published with the reference and the ask gone", err, b.said, asked)
|
||||
|
||||
@@ -26,6 +26,7 @@ const (
|
||||
VerbVersions = "versions"
|
||||
VerbRemove = "remove"
|
||||
VerbMirror = "mirror"
|
||||
VerbNameOf = "name-of"
|
||||
VerbTags = "tags"
|
||||
VerbHold = "hold"
|
||||
VerbRelease = "release"
|
||||
@@ -34,11 +35,11 @@ const (
|
||||
// Seats are the seats distribution answers verbs on.
|
||||
var Seats = []string{ImageSeat, ArtifactSeat}
|
||||
|
||||
// VerbsOf are a seat's verbs: mirror and tags on the image seat alone; hold, release and list on both of distribution's.
|
||||
// VerbsOf are a seat's verbs: mirror, name-of and tags on the image seat alone; hold, release and list on both of distribution's.
|
||||
func VerbsOf(seat string) []string {
|
||||
v := []string{VerbPublish, VerbPublishPart, VerbVersions, VerbRemove, VerbHold, VerbRelease, VerbList}
|
||||
if seat == ImageSeat {
|
||||
v = append(v, VerbMirror, VerbTags)
|
||||
v = append(v, VerbMirror, VerbNameOf, VerbTags)
|
||||
}
|
||||
sort.Strings(v)
|
||||
return v
|
||||
|
||||
@@ -333,6 +333,25 @@ func (v *Verbs) Mirror(seat, caller string, r MirrorRequest) (string, error) {
|
||||
return SeatReference(seat, v.Catalog.Reference(src.Name(), r.Digest)), nil
|
||||
}
|
||||
|
||||
// NameOf is `name-of` on the image seat (design 47 H2 H-A-513): the reference mirror answers, and keeps the copy under, for an
|
||||
// outside image as a manifest's from names it, pinned (<name>[:<tag>]@sha256:<digest>): the holder's own name for the copy,
|
||||
// upstream/<host>/<path>, with that digest, in the seat's form. It reads only and asks no copy; a from that pins no digest is
|
||||
// refused, as mirror refuses it.
|
||||
func (v *Verbs) NameOf(seat, from string) (string, error) {
|
||||
if seat != ImageSeat {
|
||||
return "", fmt.Errorf("name-of: %s serves no name-of", seat)
|
||||
}
|
||||
_, digest, pinned := strings.Cut(strings.TrimSpace(from), "@")
|
||||
if !pinned || !strings.HasPrefix(digest, "sha256:") || len(digest) != len("sha256:")+64 {
|
||||
return "", fmt.Errorf("name-of: refused: %q pins no digest, and an upstream image is named only by its pinned digest", from)
|
||||
}
|
||||
src, err := ParseSource(from)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return SeatReference(seat, v.Catalog.Reference(src.Name(), digest)), nil
|
||||
}
|
||||
|
||||
// Mirrored runs one asked copy and says its outcome on the image seat's events: published with the reference, or
|
||||
// refused with the reason; the ask leaves the state either way. An outcome that cannot be said keeps the ask, so the
|
||||
// next watch takes it on again.
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
"hold",
|
||||
"list",
|
||||
"mirror",
|
||||
"name-of",
|
||||
"publish",
|
||||
"publish-part",
|
||||
"release",
|
||||
|
||||
Reference in New Issue
Block a user