The node-engine follows the module-assignment seat: assignments, not placement; the seat's packages move to mesh-contracts and mesh-delivery (issue 1966)
The state, events and types of the seat mesh-module-assigner say assignments; the legacy node key form is gone from the reads; the dead seat-verb list of the retired name is deleted. The placement guard and the placed-file sense stay. Claude-Session: https://claude.ai/code/session_01NcbgfFSnn24M3GcqttoU7i
This commit is contained in:
@@ -6,9 +6,9 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.novox.be/novox/mesh-contracts/placement/go/seats/meshwants"
|
||||
"git.novox.be/novox/mesh-delivery/contracts/go/clients/meshcatalogclient"
|
||||
"git.novox.be/novox/mesh-delivery/contracts/go/seats/meshcatalog"
|
||||
"git.novox.be/novox/mesh-delivery/contracts/go/seats/meshwants"
|
||||
"github.com/novox/mesh-host/internal/buckets"
|
||||
engcomp "github.com/novox/mesh-host/internal/compositions"
|
||||
"maps"
|
||||
@@ -28,7 +28,7 @@ import (
|
||||
// **A check's candidate, composed in shadow on a call** (novox/hq ADR 0593 §7): the node seat's verb compose-candidate.
|
||||
// Given the check's composition key (`<group>.<heads hash>`), it reads the group's candidate from the indexer
|
||||
// (buckets.Candidates, keyed by the group alone, buckets.CandidateKey) at those heads, and composes itself
|
||||
// twice from what its shadow holds (placement, records, the indexer's modules, its config values), with its own sealed
|
||||
// twice from what its shadow holds (assignment, records, the indexer's modules, its config values), with its own sealed
|
||||
// values: once as it is, and once with the candidate's modules laid over the indexer's (each at the candidate's
|
||||
// fingerprint, its manifest by digest and the indexer's verdict on it, ADR 0578 §3; a module the candidate removes left
|
||||
// out). It answers per module placed here composed (its digest, and whether the candidate changes it), refused by the
|
||||
@@ -315,7 +315,7 @@ func (c *Composer) scratch() *Composer {
|
||||
out := New(c.env)
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
out.placements = maps.Clone(c.placements)
|
||||
out.assignments = maps.Clone(c.assignments)
|
||||
out.records = maps.Clone(c.records)
|
||||
out.inOwn = maps.Clone(c.inOwn)
|
||||
out.modules = maps.Clone(c.modules)
|
||||
@@ -326,7 +326,7 @@ func (c *Composer) scratch() *Composer {
|
||||
out.sealedOwn = maps.Clone(c.sealedOwn)
|
||||
out.ownHanded = maps.Clone(c.ownHanded)
|
||||
out.certified = c.certified
|
||||
out.placementKeys = c.placementKeys
|
||||
out.assignmentKeys = c.assignmentKeys
|
||||
out.origin = c
|
||||
return out
|
||||
}
|
||||
@@ -433,14 +433,14 @@ func (c *Composer) layCandidate(ctx context.Context, cand meshcatalog.Candidates
|
||||
func (c *Composer) composeShadow(ctx context.Context, running []engcomp.Composed, laid map[string]bool, input func(frombus.Scope, map[string]string)) (map[string]engcomp.Composed, map[string]string, error) {
|
||||
node := c.env.Node
|
||||
c.mu.Lock()
|
||||
placement, placed := c.placements[node]
|
||||
assignment, placed := c.assignments[node]
|
||||
modules := maps.Clone(c.modules)
|
||||
inOwn := c.inOwnOf(placement)
|
||||
inOwn := c.inOwnOf(assignment)
|
||||
c.mu.Unlock()
|
||||
if !placed {
|
||||
return nil, nil, errors.New("this node's key in the seat's placement state is gone: it composes nothing of its own")
|
||||
return nil, nil, errors.New("this node's key in the seat's assignment state is gone: it composes nothing of its own")
|
||||
}
|
||||
fps := shadowBuilds(running, placement, modules, inOwn)
|
||||
fps := shadowBuilds(running, assignment, modules, inOwn)
|
||||
// A module the laid candidate changes is composed at the candidate's build, though the node runs another.
|
||||
for module := range fps {
|
||||
if mod, ok := modules[module]; ok && laid[module] {
|
||||
|
||||
@@ -3,8 +3,7 @@ package selfcompose
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"git.novox.be/novox/mesh-contracts/placement/go/clients/meshmoduleassignerclient"
|
||||
"git.novox.be/novox/mesh-contracts/placement/go/seats/meshmoduleassigner"
|
||||
"git.novox.be/novox/mesh-contracts/go/seats/meshmoduleassigner"
|
||||
"git.novox.be/novox/mesh-delivery/contracts/go/clients/meshcatalogclient"
|
||||
"git.novox.be/novox/mesh-delivery/contracts/go/clients/meshdeliveryclient"
|
||||
"git.novox.be/novox/mesh-delivery/contracts/go/seats/meshcatalog"
|
||||
@@ -25,7 +24,7 @@ import (
|
||||
// novox/hq ADR 0593 §7: the verb compose-candidate composes a check's candidate on this node in shadow. A candidate that
|
||||
// changes a placed module composes it at the candidate's build, changed; one whose manifest the indexer refused is
|
||||
// answered refused, naming the module and the judge's words, and the verdict is refused; a candidate the indexer does not
|
||||
// hold is refused in words. Nothing is applied, nothing is written, no placement answer is handed, and the answer comes
|
||||
// hold is refused in words. Nothing is applied, nothing is written, no assignment answer is handed, and the answer comes
|
||||
// within the bound; a shadow not ready and an ended bound answer unready at once, which the checker takes as no answer.
|
||||
func TestTheNodeComposesACandidateOnAsk(t *testing.T) {
|
||||
b := newFakeBus()
|
||||
@@ -87,7 +86,7 @@ func TestTheNodeComposesACandidateOnAsk(t *testing.T) {
|
||||
if a := s.ComposeCandidate(ctx, nodeengine.ComposeCandidateInput{Candidate: accepted}); a.Verdict != nec.Unready || a.Refused == "" {
|
||||
t.Errorf("a shadow not ready answered %+v", a)
|
||||
}
|
||||
place, _ := meshmoduleassignerclient.EncodePlacement(meshmoduleassigner.Placement{Node: "n1", Decided: meshmoduleassigner.NodeDecided{Hub: true, Address: "10.77.0.1"},
|
||||
place := assignedValues(t, meshmoduleassigner.Assignments{Node: "n1", Decided: meshmoduleassigner.NodeDecided{Hub: true, Address: "10.77.0.1"},
|
||||
Modules: []meshmoduleassigner.PlacedModule{{Module: "lemurs"}}})
|
||||
have, _ := nec.EncodeHaveNode(nodeengine.HaveByNodeNodeValue{Record: &nodeengine.NodeRecord{Node: "n1", TunnelKey: "k", SealingKey: "sk", Capabilities: []string{"systemd"}}})
|
||||
mod, _ := meshcatalogclient.EncodeModule(meshcatalog.ModulesByModuleValue{Fp2: fp, Manifest: digest, Repository: "novox/x", Commit: "c"})
|
||||
@@ -96,10 +95,10 @@ func TestTheNodeComposesACandidateOnAsk(t *testing.T) {
|
||||
for watching() < 6 && time.Now().Before(deadline) {
|
||||
time.Sleep(5 * time.Millisecond)
|
||||
}
|
||||
b.put(t, buckets.Placement, "placement.n1", place)
|
||||
b.putAssigned(t, place)
|
||||
b.put(t, buckets.Have, "n1.node", have)
|
||||
b.put(t, buckets.Modules, "lemurs", mod)
|
||||
for _, bucket := range []string{buckets.PlacementCandidates, buckets.Placement, buckets.Have, buckets.Modules, ResolvedBucket} {
|
||||
for _, bucket := range []string{buckets.ProposalCandidates, buckets.Assignments, buckets.Have, buckets.Modules, ResolvedBucket} {
|
||||
b.send(bucket, agent.Update{Caught: true})
|
||||
}
|
||||
for !s.ready.Load() && time.Now().Before(deadline) {
|
||||
@@ -185,7 +184,7 @@ func TestTheNodeComposesACandidateOnAsk(t *testing.T) {
|
||||
var tick atomic.Int64
|
||||
env.Now = func() time.Time { return time.Unix(0, 0).Add(time.Duration(tick.Add(1)) * time.Second) }
|
||||
s := NewShadow(env, nil)
|
||||
s.c.placements["n1"] = meshmoduleassigner.Placement{Node: "n1", Decided: meshmoduleassigner.NodeDecided{Hub: true, Address: "10.77.0.1"},
|
||||
s.c.assignments["n1"] = meshmoduleassigner.Assignments{Node: "n1", Decided: meshmoduleassigner.NodeDecided{Hub: true, Address: "10.77.0.1"},
|
||||
Modules: []meshmoduleassigner.PlacedModule{{Module: "lemurs"}}}
|
||||
s.c.records["n1"] = nodeengine.NodeRecord{Node: "n1", TunnelKey: "k", SealingKey: "sk", Capabilities: []string{"systemd"}}
|
||||
s.c.modules["lemurs"] = meshcatalog.ModulesByModuleValue{Fp2: fp, Manifest: digest, Repository: "novox/x", Commit: "c"}
|
||||
|
||||
@@ -54,7 +54,7 @@ type published struct {
|
||||
fps map[string]string // by module, the wanted fingerprint
|
||||
comps map[string]engcomp.Composed
|
||||
held map[string]string
|
||||
// placed is the modules the node's placement puts here, ran what runs of each module (by its composition's FP).
|
||||
// placed is the modules the node's assignment puts here, ran what runs of each module (by its composition's FP).
|
||||
placed []string
|
||||
ran map[string]string
|
||||
}
|
||||
|
||||
@@ -3,12 +3,11 @@ package selfcompose
|
||||
import (
|
||||
"context"
|
||||
"git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient"
|
||||
"git.novox.be/novox/mesh-contracts/go/seats/meshmoduleassigner"
|
||||
"git.novox.be/novox/mesh-contracts/go/seats/nodeengine"
|
||||
"git.novox.be/novox/mesh-contracts/placement/go/clients/meshmoduleassignerclient"
|
||||
"git.novox.be/novox/mesh-contracts/placement/go/seats/meshmoduleassigner"
|
||||
"git.novox.be/novox/mesh-contracts/placement/go/seats/meshwants"
|
||||
"git.novox.be/novox/mesh-delivery/contracts/go/clients/meshcatalogclient"
|
||||
"git.novox.be/novox/mesh-delivery/contracts/go/seats/meshcatalog"
|
||||
"git.novox.be/novox/mesh-delivery/contracts/go/seats/meshwants"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds"
|
||||
"github.com/novox/mesh-host/internal/buckets"
|
||||
"github.com/novox/mesh-host/internal/buckets/bucketstest"
|
||||
@@ -91,20 +90,20 @@ func TestTheNodePublishesItsCompositions(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
place, _ := meshmoduleassignerclient.EncodePlacement(meshmoduleassigner.Placement{Node: "n1", Decided: meshmoduleassigner.NodeDecided{Hub: true, Address: "10.77.0.1"},
|
||||
place := assignedValues(t, meshmoduleassigner.Assignments{Node: "n1", Decided: meshmoduleassigner.NodeDecided{Hub: true, Address: "10.77.0.1"},
|
||||
Modules: []meshmoduleassigner.PlacedModule{{Module: "lemurs"}, {Module: "oldie"}}})
|
||||
have, _ := nodeengineclient.EncodeHaveNode(nodeengine.HaveByNodeNodeValue{Record: &nodeengine.NodeRecord{Node: "n1", TunnelKey: "k", SealingKey: "sk", Capabilities: []string{"systemd"}}})
|
||||
mod, _ := meshcatalogclient.EncodeModule(meshcatalog.ModulesByModuleValue{Fp2: fp, Manifest: digest, Repository: "novox/x", Commit: "c"})
|
||||
omod, _ := meshcatalogclient.EncodeModule(meshcatalog.ModulesByModuleValue{Fp2: ofp, Manifest: odigest, Repository: "novox/o", Commit: "c"})
|
||||
want, _ := bucketstest.Want(meshwants.WantsByWantNodeModuleValue{Fp: fp, Self: true})
|
||||
nodeWant, _ := bucketstest.NodeWant(meshwants.WantsByWantNodeNodeValue{Self: true})
|
||||
b.put(t, buckets.Placement, "placement.n1", place)
|
||||
b.putAssigned(t, place)
|
||||
b.put(t, buckets.Have, "n1.node", have)
|
||||
b.put(t, buckets.Modules, "lemurs", mod)
|
||||
b.put(t, buckets.Modules, "oldie", omod)
|
||||
b.put(t, buckets.Wants, "want.n1.lemurs", want)
|
||||
b.put(t, buckets.Wants, "want.n1.node", nodeWant)
|
||||
for _, bucket := range []string{buckets.Wants, buckets.Placement, buckets.Have, buckets.Modules, ResolvedBucket, builds.BuilderBuildsBucket} {
|
||||
for _, bucket := range []string{buckets.Wants, buckets.Assignments, buckets.Have, buckets.Modules, ResolvedBucket, builds.BuilderBuildsBucket} {
|
||||
b.send(bucket, agent.Update{Caught: true})
|
||||
}
|
||||
for u := next(t, out); !u.Caught; u = next(t, out) {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// modules and its own composition with mesh-sdk's composer, from what is on the bus, and hands the compositions to the
|
||||
// agent as the agent once read them from the controller's bucket `composed-<node>`.
|
||||
//
|
||||
// **It watches, it never polls** (ADR 0547 §2): its inputs are watches of the node's wants, the indexer's placement and
|
||||
// **It watches, it never polls** (ADR 0547 §2): its inputs are watches of the node's wants, the indexer's assignment and
|
||||
// modules, every node's own have key (where a node's record rides, ADR 0555 §3) and mesh-config's resolved values of this
|
||||
// node. A change of any of them marks the node to compose again; one loop drains the mark, so a burst of changes composes
|
||||
// the node once (composing one node takes 0.8 to 4.4 s, measured 2026-10-26). It hands the agent only the compositions that
|
||||
@@ -19,14 +19,14 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.novox.be/novox/mesh-contracts/go/clients/meshmoduleassignerclient"
|
||||
"git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient"
|
||||
"git.novox.be/novox/mesh-contracts/go/seats/meshmoduleassigner"
|
||||
"git.novox.be/novox/mesh-contracts/go/seats/nodeengine"
|
||||
"git.novox.be/novox/mesh-contracts/identity-and-access/go/clients/meshvaultclient"
|
||||
"git.novox.be/novox/mesh-contracts/placement/go/clients/meshmoduleassignerclient"
|
||||
"git.novox.be/novox/mesh-contracts/placement/go/seats/meshmoduleassigner"
|
||||
"git.novox.be/novox/mesh-contracts/placement/go/seats/meshwants"
|
||||
"git.novox.be/novox/mesh-delivery/contracts/go/clients/meshcatalogclient"
|
||||
"git.novox.be/novox/mesh-delivery/contracts/go/seats/meshcatalog"
|
||||
"git.novox.be/novox/mesh-delivery/contracts/go/seats/meshwants"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds"
|
||||
"git.novox.be/novox/mesh-sdk/go/declaration"
|
||||
"github.com/novox/mesh-host/internal/buckets"
|
||||
@@ -135,13 +135,13 @@ const VaultSecretChanged = "mesh.mod.mesh-vault.event.secret-changed"
|
||||
type Composer struct {
|
||||
env Env
|
||||
|
||||
mu sync.Mutex
|
||||
wants map[string]meshwants.WantsByWantNodeModuleValue // by module, the node's own under agent.NodeModule
|
||||
placements map[string]meshmoduleassigner.Placement
|
||||
// placementKeys is the seat's state placement key by key in either form, each node's placement assembled from it
|
||||
mu sync.Mutex
|
||||
wants map[string]meshwants.WantsByWantNodeModuleValue // by module, the node's own under agent.NodeModule
|
||||
assignments map[string]meshmoduleassigner.Assignments
|
||||
// assignmentKeys is the seat's state assignment key by key in either form, each node's assignment assembled from it
|
||||
// (meshmoduleassignerclient.Keys; research 072 row 37): a write of the holder's under way is never composed half.
|
||||
placementKeys *meshmoduleassignerclient.Keys
|
||||
records map[string]nodeengine.NodeRecord
|
||||
assignmentKeys *meshmoduleassignerclient.Keys
|
||||
records map[string]nodeengine.NodeRecord
|
||||
// inOwn is, by module, whether this node's have of it names no fingerprint of the new form (mesh-wireguard, a module
|
||||
// at a build of the old form): the node runs it inside its own composition, and composes it there again (issue 1126).
|
||||
inOwn map[string]bool
|
||||
@@ -307,7 +307,7 @@ func New(env Env) *Composer {
|
||||
if env.Say == nil {
|
||||
env.Say = func(string) {}
|
||||
}
|
||||
return &Composer{env: env, wants: map[string]meshwants.WantsByWantNodeModuleValue{}, placements: map[string]meshmoduleassigner.Placement{}, placementKeys: meshmoduleassignerclient.NewKeys(),
|
||||
return &Composer{env: env, wants: map[string]meshwants.WantsByWantNodeModuleValue{}, assignments: map[string]meshmoduleassigner.Assignments{}, assignmentKeys: meshmoduleassignerclient.NewKeys(),
|
||||
records: map[string]nodeengine.NodeRecord{}, inOwn: map[string]bool{}, modules: map[string]meshcatalog.ModulesByModuleValue{}, values: map[string]map[string]any{},
|
||||
manifests: map[string][]byte{}, archives: map[string][]byte{}, builds: map[string]builds.BuilderBuild{}, handed: map[string]string{}, sealedOwn: map[string]ownSealed{},
|
||||
pkgs: map[string]compositions.Composed{}, asked: make(chan chan Pass, 8)}
|
||||
@@ -363,7 +363,7 @@ func (c *Composer) inputs() []input {
|
||||
node := c.env.Node
|
||||
return []input{
|
||||
{buckets.Wants, "want." + node + ".>", (*Composer).takeWant, nil},
|
||||
{buckets.Placement, ">", (*Composer).takePlacement, nil},
|
||||
{buckets.Assignments, ">", (*Composer).takeAssignments, nil},
|
||||
// Every node's record, and this node's own haves (what it runs inside its own composition): two watches, each
|
||||
// within the node's grant (buscompose: readGrants of the have bucket at `*.node`, NodeKeysGrants at `<node>.>`).
|
||||
// A watch of every key is refused by the bus (issue 1126, 2026-10-27 09:21: the fold's `>` stopped every agent).
|
||||
@@ -396,7 +396,7 @@ func (c *Composer) takeBuildDone(u agent.Update) bool {
|
||||
w, wanted := c.wants[module]
|
||||
m := c.modules[module]
|
||||
placedHere := false
|
||||
for _, pm := range c.placements[c.env.Node].Modules {
|
||||
for _, pm := range c.assignments[c.env.Node].Modules {
|
||||
placedHere = placedHere || pm.Module == module
|
||||
}
|
||||
c.mu.Unlock()
|
||||
@@ -593,7 +593,7 @@ func (c *Composer) caughtSent() bool {
|
||||
return sent
|
||||
}
|
||||
|
||||
// takeChanged takes u through in.take and says whether the entry it names changed: a want, a placement, a module or a
|
||||
// takeChanged takes u through in.take and says whether the entry it names changed: a want, a assignment, a module or a
|
||||
// config value written again with the value it held changes nothing composed, so it makes no pass (issue 774,
|
||||
// 2026-10-31: every put under want.<node>.> made a pass, and each pass asked the vault for the node's own secrets).
|
||||
func (c *Composer) takeChanged(in input, u agent.Update) bool {
|
||||
@@ -623,14 +623,14 @@ func (c *Composer) entry(bucket, key string) (v any, has, known bool) {
|
||||
}
|
||||
w, ok := c.wants[module]
|
||||
return w.Fp, ok, true
|
||||
case buckets.Placement:
|
||||
// Any key of a node, its node key, a module key or its legacy key, stands for the node's whole placement: a
|
||||
case buckets.Assignments:
|
||||
// Any key of a node, its node key, a module key or its legacy key, stands for the node's whole assignment: a
|
||||
// module key written before its node key names it changes nothing composed.
|
||||
node, _, _, err := meshmoduleassignerclient.ParseKey(key)
|
||||
if err != nil {
|
||||
return nil, false, true
|
||||
}
|
||||
p, ok := c.placements[node]
|
||||
p, ok := c.assignments[node]
|
||||
return p, ok, true
|
||||
case buckets.Modules:
|
||||
name, err := meshcatalogclient.ParseModulesKey(key)
|
||||
@@ -677,25 +677,25 @@ func (c *Composer) takeWant(u agent.Update) {
|
||||
c.wants[module] = w
|
||||
}
|
||||
|
||||
func (c *Composer) takePlacement(u agent.Update) {
|
||||
func (c *Composer) takeAssignments(u agent.Update) {
|
||||
if u.Caught {
|
||||
return
|
||||
}
|
||||
c.mu.Lock()
|
||||
if c.placementKeys == nil {
|
||||
c.placementKeys = meshmoduleassignerclient.NewKeys()
|
||||
if c.assignmentKeys == nil {
|
||||
c.assignmentKeys = meshmoduleassignerclient.NewKeys()
|
||||
}
|
||||
node, err := c.placementKeys.Put(u.Key, u.Value, u.Revision, u.Deleted || len(u.Value) == 0)
|
||||
node, err := c.assignmentKeys.Put(u.Key, u.Value, u.Revision, u.Deleted || len(u.Value) == 0)
|
||||
if node != "" {
|
||||
if p, _, ok := c.placementKeys.Of(node); ok {
|
||||
c.placements[node] = p
|
||||
if p, _, ok := c.assignmentKeys.Of(node); ok {
|
||||
c.assignments[node] = p
|
||||
} else {
|
||||
delete(c.placements, node)
|
||||
delete(c.assignments, node)
|
||||
}
|
||||
}
|
||||
c.mu.Unlock()
|
||||
if node != "" && err != nil && c.env.Say != nil {
|
||||
c.env.Say("the seat's placement of " + node + ": " + err.Error())
|
||||
c.env.Say("the seat's assignment of " + node + ": " + err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -758,14 +758,14 @@ func (c *Composer) takeModuleHave(u agent.Update) bool {
|
||||
}
|
||||
|
||||
// inOwnOf is, of the modules p places, those the node runs inside its own composition (c.inOwn), sorted; c.mu held.
|
||||
// Machines is, from the placements this composer holds, each node by its address on the private network, and the hub's
|
||||
// Machines is, from the assignments this composer holds, each node by its address on the private network, and the hub's
|
||||
// node: what names the machine a failing network part points at (nodeengine.NetworkPart.Targets, issue 774). Empty
|
||||
// before any placement is read.
|
||||
// before any assignment is read.
|
||||
func (c *Composer) Machines() (byAddress map[string]string, hub string) {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
byAddress = map[string]string{}
|
||||
for node, p := range c.placements {
|
||||
for node, p := range c.assignments {
|
||||
if a, _, _ := strings.Cut(p.Decided.Address, "/"); a != "" {
|
||||
byAddress[a] = node
|
||||
}
|
||||
@@ -776,7 +776,7 @@ func (c *Composer) Machines() (byAddress map[string]string, hub string) {
|
||||
return byAddress, hub
|
||||
}
|
||||
|
||||
func (c *Composer) inOwnOf(p meshmoduleassigner.Placement) []string {
|
||||
func (c *Composer) inOwnOf(p meshmoduleassigner.Assignments) []string {
|
||||
var out []string
|
||||
for _, m := range p.Modules {
|
||||
if c.inOwn[m.Module] {
|
||||
@@ -874,14 +874,14 @@ func (c *Composer) compose(ctx context.Context) []agent.Update {
|
||||
_, nodeWanted := c.wants[agent.NodeModule]
|
||||
// What it runs inside its own composition and no want names at a build of the new form stays there, as the
|
||||
// controller's composed writer folds it (issue 1126); compose folds none a want names.
|
||||
own, placed := c.placements[c.env.Node]
|
||||
own, placed := c.assignments[c.env.Node]
|
||||
inOwn := c.inOwnOf(own)
|
||||
r := reader{c: c}
|
||||
c.mu.Unlock()
|
||||
if !placed {
|
||||
// The catalogue does not place it: it composes nothing, applies no composition made elsewhere, and this is no
|
||||
// refusal of what it runs (issue 1126).
|
||||
c.sayOnce("this node's key in the seat's placement state is gone: it composes nothing of its own, and keeps running what it runs")
|
||||
c.sayOnce("this node's key in the seat's assignment state is gone: it composes nothing of its own, and keeps running what it runs")
|
||||
c.paid() // nothing of its own to compose, so no pass is owed and no timer armed again
|
||||
return nil
|
||||
}
|
||||
@@ -1317,10 +1317,10 @@ func (r reader) VaultAuthority(context.Context) string {
|
||||
|
||||
var _ frombus.SignersReader = reader{}
|
||||
|
||||
// certificateWanted says whether a module the placement p puts on this node asks for a certificate for the machine's
|
||||
// certificateWanted says whether a module the assignment p puts on this node asks for a certificate for the machine's
|
||||
// internal name (its manifest's `certificate`), read from the indexer's manifests; a manifest that cannot be read is
|
||||
// taken as asking none, and the composition says what it misses.
|
||||
func (c *Composer) certificateWanted(ctx context.Context, r reader, p meshmoduleassigner.Placement) bool {
|
||||
func (c *Composer) certificateWanted(ctx context.Context, r reader, p meshmoduleassigner.Assignments) bool {
|
||||
for _, m := range p.Modules {
|
||||
c.mu.Lock()
|
||||
digest := c.modules[m.Module].Manifest
|
||||
@@ -1348,7 +1348,7 @@ func (c *Composer) certificateWanted(ctx context.Context, r reader, p meshmodule
|
||||
|
||||
// certifyIfWanted asks Certify once per serving key when a module placed here asks for a certificate and this node's
|
||||
// record holds none for its internal name and serving key from an authority it trusts (the one it holds, or the vault's).
|
||||
func (c *Composer) certifyIfWanted(ctx context.Context, r reader, p meshmoduleassigner.Placement) {
|
||||
func (c *Composer) certifyIfWanted(ctx context.Context, r reader, p meshmoduleassigner.Assignments) {
|
||||
if c.env.Certify == nil || !c.certificateWanted(ctx, r, p) {
|
||||
return
|
||||
}
|
||||
@@ -1377,11 +1377,11 @@ func (c *Composer) certifyIfWanted(ctx context.Context, r reader, p meshmoduleas
|
||||
c.mu.Unlock()
|
||||
}
|
||||
|
||||
func (r reader) Placements(context.Context) (map[string]meshmoduleassigner.Placement, error) {
|
||||
func (r reader) Assignments(context.Context) (map[string]meshmoduleassigner.Assignments, error) {
|
||||
r.c.mu.Lock()
|
||||
defer r.c.mu.Unlock()
|
||||
out := make(map[string]meshmoduleassigner.Placement, len(r.c.placements))
|
||||
for k, v := range r.c.placements {
|
||||
out := make(map[string]meshmoduleassigner.Assignments, len(r.c.assignments))
|
||||
for k, v := range r.c.assignments {
|
||||
out[k] = v
|
||||
}
|
||||
return out, nil
|
||||
@@ -1721,7 +1721,7 @@ func Transient(err error) bool {
|
||||
// ComposedToday is the digest of module composed at the build fp with today's settings and secrets, as this node would
|
||||
// compose it now beside its other modules at their wanted builds, the boxes it runs kept as compose keeps them, and whether
|
||||
// it composed (novox/hq ADR 0601 §1): the node agent compares it with what runs, to say whether a move to another build
|
||||
// changes the build alone. A module held, a node refused, or no placement: false, and the move is asked of a person.
|
||||
// changes the build alone. A module held, a node refused, or no assignment: false, and the move is asked of a person.
|
||||
func (c *Composer) ComposedToday(ctx context.Context, module, fp string) (string, bool) {
|
||||
c.mu.Lock()
|
||||
fps, kept := map[string]string{}, map[string]string{}
|
||||
@@ -1739,7 +1739,7 @@ func (c *Composer) ComposedToday(ctx context.Context, module, fp string) (string
|
||||
if mm, ok := c.modules[module]; !ok || mm.Fp2 != fp {
|
||||
kept[module] = fp
|
||||
}
|
||||
own, placed := c.placements[c.env.Node]
|
||||
own, placed := c.assignments[c.env.Node]
|
||||
inOwn := c.inOwnOf(own)
|
||||
c.mu.Unlock()
|
||||
if !placed {
|
||||
|
||||
@@ -8,13 +8,13 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.novox.be/novox/mesh-contracts/go/clients/meshmoduleassignerclient"
|
||||
"git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient"
|
||||
"git.novox.be/novox/mesh-contracts/go/seats/meshmoduleassigner"
|
||||
nodeengine "git.novox.be/novox/mesh-contracts/go/seats/nodeengine"
|
||||
"git.novox.be/novox/mesh-contracts/placement/go/clients/meshmoduleassignerclient"
|
||||
"git.novox.be/novox/mesh-contracts/placement/go/seats/meshmoduleassigner"
|
||||
"git.novox.be/novox/mesh-contracts/placement/go/seats/meshwants"
|
||||
"git.novox.be/novox/mesh-delivery/contracts/go/clients/meshcatalogclient"
|
||||
"git.novox.be/novox/mesh-delivery/contracts/go/seats/meshcatalog"
|
||||
"git.novox.be/novox/mesh-delivery/contracts/go/seats/meshwants"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds"
|
||||
"git.novox.be/novox/mesh-sdk/go/declaration"
|
||||
"github.com/novox/mesh-host/internal/buckets"
|
||||
@@ -197,13 +197,13 @@ func TestTheNodeComposesItsWantsFromTheBus(t *testing.T) {
|
||||
okey, _ := meshcatalogclient.ManifestsKey(odigest)
|
||||
b.kv[buckets.Manifests+"/"+okey] = oman
|
||||
omod, _ := meshcatalogclient.EncodeModule(meshcatalog.ModulesByModuleValue{Fp2: meshcatalogclient.SourcePrefix2 + strings.Repeat("c", 64), Manifest: odigest, Repository: "novox/o", Commit: "c"})
|
||||
place, _ := meshmoduleassignerclient.EncodePlacement(meshmoduleassigner.Placement{Node: "n1", Decided: meshmoduleassigner.NodeDecided{Hub: true, Address: "10.77.0.1"},
|
||||
place := assignedValues(t, meshmoduleassigner.Assignments{Node: "n1", Decided: meshmoduleassigner.NodeDecided{Hub: true, Address: "10.77.0.1"},
|
||||
Modules: []meshmoduleassigner.PlacedModule{{Module: "lemurs"}, {Module: "oldie"}}})
|
||||
have, _ := nodeengineclient.EncodeHaveNode(nodeengine.HaveByNodeNodeValue{Record: &nodeengine.NodeRecord{Node: "n1", TunnelKey: "k", SealingKey: "sk", Capabilities: []string{"systemd"}}})
|
||||
mod, _ := meshcatalogclient.EncodeModule(meshcatalog.ModulesByModuleValue{Fp2: fp, Manifest: digest, Repository: "novox/x", Commit: "c"})
|
||||
want, _ := bucketstest.Want(meshwants.WantsByWantNodeModuleValue{Fp: fp, Self: true})
|
||||
nodeWant, _ := bucketstest.NodeWant(meshwants.WantsByWantNodeNodeValue{Self: true})
|
||||
b.put(t, buckets.Placement, "placement.n1", place)
|
||||
b.putAssigned(t, place)
|
||||
b.put(t, buckets.Have, "n1.node", have)
|
||||
oldHave, _ := nodeengineclient.EncodeHave(nodeengine.HaveByNodeModuleValue{Build: "build-1", Phase: nodeengineclient.PhaseRunning, Health: nodeengineclient.HealthOK})
|
||||
b.put(t, buckets.Have, "n1.oldie", oldHave)
|
||||
@@ -211,7 +211,7 @@ func TestTheNodeComposesItsWantsFromTheBus(t *testing.T) {
|
||||
b.put(t, buckets.Modules, "oldie", omod)
|
||||
b.put(t, buckets.Wants, "want.n1.lemurs", want)
|
||||
b.put(t, buckets.Wants, "want.n1.node", nodeWant)
|
||||
for _, bucket := range []string{buckets.Wants, buckets.Placement, buckets.Have, buckets.Modules, ResolvedBucket, builds.BuilderBuildsBucket} {
|
||||
for _, bucket := range []string{buckets.Wants, buckets.Assignments, buckets.Have, buckets.Modules, ResolvedBucket, builds.BuilderBuildsBucket} {
|
||||
b.send(bucket, agent.Update{Caught: true})
|
||||
}
|
||||
got := map[string]bool{}
|
||||
@@ -324,8 +324,8 @@ func TestTheNodeComposesItsWantsFromTheBus(t *testing.T) {
|
||||
for k, v := range c.wants {
|
||||
c2.wants[k] = v
|
||||
}
|
||||
for k, v := range c.placements {
|
||||
c2.placements[k] = v
|
||||
for k, v := range c.assignments {
|
||||
c2.assignments[k] = v
|
||||
}
|
||||
for k, v := range c.records {
|
||||
c2.records[k] = v
|
||||
@@ -441,9 +441,9 @@ func TestTheNodeComposesItsWantsFromTheBus(t *testing.T) {
|
||||
c3.modules[m] = meshcatalog.ModulesByModuleValue{Fp2: mfp, Manifest: dig, Repository: "novox/" + m, Commit: "c"}
|
||||
c3.wants[m] = meshwants.WantsByWantNodeModuleValue{Fp: mfp, Self: true}
|
||||
}
|
||||
p3 := c3.placements["n1"]
|
||||
p3 := c3.assignments["n1"]
|
||||
p3.Modules = append(append([]meshmoduleassigner.PlacedModule{}, p3.Modules...), meshmoduleassigner.PlacedModule{Module: "proxy"}, meshmoduleassigner.PlacedModule{Module: "de-spiegel"})
|
||||
c3.placements["n1"] = p3
|
||||
c3.assignments["n1"] = p3
|
||||
r3 := c3.records["n1"]
|
||||
r3.Capabilities = []string{"systemd", "container-runtime"}
|
||||
c3.records["n1"] = r3
|
||||
@@ -495,9 +495,9 @@ func TestTheNodeComposesItsWantsFromTheBus(t *testing.T) {
|
||||
// The indexer's verdict on the captured manifest (ADR 0578): the engine judges nothing, it takes this.
|
||||
Verdict: meshcatalogclient.VerdictRefused, Problems: []string{`bar item "shows" is none of them`}}
|
||||
c4.wants["power"] = meshwants.WantsByWantNodeModuleValue{Fp: powerFP, Self: true}
|
||||
p4 := c4.placements["n1"]
|
||||
p4 := c4.assignments["n1"]
|
||||
p4.Modules = append(append([]meshmoduleassigner.PlacedModule{}, p4.Modules...), meshmoduleassigner.PlacedModule{Module: "power"})
|
||||
c4.placements["n1"] = p4
|
||||
c4.assignments["n1"] = p4
|
||||
handed4 := map[string]agent.Update{}
|
||||
for _, u := range c4.compose(ctx) {
|
||||
handed4[u.Key] = u
|
||||
@@ -513,10 +513,10 @@ func TestTheNodeComposesItsWantsFromTheBus(t *testing.T) {
|
||||
// what runs nor the kept declaration: with nothing running (the kept read retired, Running empty) the node's own
|
||||
// still carries its resources, so retiring the read removes nothing of it.
|
||||
c5, told5 := fresh(env.Get)
|
||||
p5 := c5.placements["n1"]
|
||||
p5 := c5.assignments["n1"]
|
||||
p5.Modules = append(append([]meshmoduleassigner.PlacedModule{}, p5.Modules...), meshmoduleassigner.PlacedModule{Module: overlay.Name})
|
||||
p5.Decided.Endpoint = "n1.example:51820"
|
||||
c5.placements["n1"] = p5
|
||||
c5.assignments["n1"] = p5
|
||||
c5.inOwn[overlay.Name] = true
|
||||
nodeKey5, _ := compositions.NodeKey("n1")
|
||||
var own5 string
|
||||
@@ -597,12 +597,12 @@ func TestTheNodeComposesItsWantsFromTheBus(t *testing.T) {
|
||||
// secrets. A key written again with what it held, or a want whose words moved and not its build, makes none.
|
||||
worded, _ := bucketstest.Want(meshwants.WantsByWantNodeModuleValue{Fp: fp, Self: true, Words: "lemurs is held at aaaaaaaaaaaa"})
|
||||
elsewhere, _ := bucketstest.Want(meshwants.WantsByWantNodeModuleValue{Fp: meshcatalogclient.SourcePrefix2 + strings.Repeat("e", 64), Self: true})
|
||||
// Research 072 row 37: the placement converted to one key per module and node moves nothing composed; a write in
|
||||
// keys makes its pass at its node key, the commit, and not at a module key written before it nor at the mirror.
|
||||
placeBase := meshmoduleassigner.Placement{Node: "n1", Decided: meshmoduleassigner.NodeDecided{Hub: true, Address: "10.77.0.1"},
|
||||
// Research 072 row 37: the assignments kept as one key per module and node move nothing composed when written again; a
|
||||
// write in keys makes its pass at its node key, the commit, and not at a module key written before it.
|
||||
placeBase := meshmoduleassigner.Assignments{Node: "n1", Decided: meshmoduleassigner.NodeDecided{Hub: true, Address: "10.77.0.1"},
|
||||
Modules: []meshmoduleassigner.PlacedModule{{Module: "lemurs"}, {Module: "oldie"}}}
|
||||
placeKeys := meshmoduleassignerclient.NewKeys()
|
||||
keyRows := func(after meshmoduleassigner.Placement, what string) []struct {
|
||||
keyRows := func(after meshmoduleassigner.Assignments, what string) []struct {
|
||||
name, bucket, key string
|
||||
value []byte
|
||||
pass bool
|
||||
@@ -622,23 +622,25 @@ func TestTheNodeComposesItsWantsFromTheBus(t *testing.T) {
|
||||
name, bucket, key string
|
||||
value []byte
|
||||
pass bool
|
||||
}{what + ": " + w.Key, buckets.Placement, w.Key, w.Value, w.Commit && what != "converted"})
|
||||
}{what + ": " + w.Key, buckets.Assignments, w.Key, w.Value, w.Commit})
|
||||
}
|
||||
return rows
|
||||
}
|
||||
_, _ = placeKeys.Put("placement.n1", place, 1, false)
|
||||
for k, v := range place {
|
||||
_, _ = placeKeys.Put(k, v, 1, false)
|
||||
}
|
||||
lemursMoved := placeBase
|
||||
lemursMoved.Modules = []meshmoduleassigner.PlacedModule{{Module: "lemurs", Values: map[string]any{"greeting": "hoi"}}, {Module: "oldie"}}
|
||||
var placementRows []struct {
|
||||
var assignmentRows []struct {
|
||||
name, bucket, key string
|
||||
value []byte
|
||||
pass bool
|
||||
}
|
||||
for _, step := range []struct {
|
||||
what string
|
||||
p meshmoduleassigner.Placement
|
||||
}{{"converted", placeBase}, {"lemurs moved", lemursMoved}, {"lemurs back", placeBase}} {
|
||||
placementRows = append(placementRows, keyRows(step.p, step.what)...)
|
||||
p meshmoduleassigner.Assignments
|
||||
}{{"lemurs moved", lemursMoved}, {"lemurs back", placeBase}} {
|
||||
assignmentRows = append(assignmentRows, keyRows(step.p, step.what)...)
|
||||
}
|
||||
for _, row := range append([]struct {
|
||||
name, bucket, key string
|
||||
@@ -648,11 +650,11 @@ func TestTheNodeComposesItsWantsFromTheBus(t *testing.T) {
|
||||
{"lemurs's want again", buckets.Wants, "want.n1.lemurs", want, false},
|
||||
{"the node's own want again", buckets.Wants, "want.n1.node", nodeWant, false},
|
||||
{"lemurs's want with other words", buckets.Wants, "want.n1.lemurs", worded, false},
|
||||
{"the placement again", buckets.Placement, "placement.n1", place, false},
|
||||
{"the assignment again", buckets.Assignments, "n1.node", place["n1.node"], false},
|
||||
{"lemurs's module again", buckets.Modules, "lemurs", mod, false},
|
||||
{"lemurs's want at another build", buckets.Wants, "want.n1.lemurs", elsewhere, true},
|
||||
{"lemurs's want back at its build", buckets.Wants, "want.n1.lemurs", want, true},
|
||||
}, placementRows...) {
|
||||
}, assignmentRows...) {
|
||||
before := passes()
|
||||
b.put(t, row.bucket, row.key, row.value)
|
||||
if !row.pass {
|
||||
@@ -698,18 +700,18 @@ func TestTheNodeComposesItsWantsFromTheBus(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
tplace, _ := meshmoduleassignerclient.EncodePlacement(meshmoduleassigner.Placement{Node: "n1", Decided: meshmoduleassigner.NodeDecided{Hub: true, Address: "10.77.0.1"},
|
||||
tplace := assignedValues(t, meshmoduleassigner.Assignments{Node: "n1", Decided: meshmoduleassigner.NodeDecided{Hub: true, Address: "10.77.0.1"},
|
||||
Modules: []meshmoduleassigner.PlacedModule{{Module: "tool"}}})
|
||||
tmod, _ := meshcatalogclient.EncodeModule(meshcatalog.ModulesByModuleValue{Fp2: next2, Manifest: tdigest, Repository: "novox/t", Commit: "c"})
|
||||
twant, _ := bucketstest.Want(meshwants.WantsByWantNodeModuleValue{Fp: next2, Self: true})
|
||||
building, _ := builds.EncodeBuilderBuild(builds.BuilderBuild{State: "building"})
|
||||
bkey, _ := builds.BuilderBuildKey("tool", next2)
|
||||
tb.kv[builds.BuilderBuildsBucket+"/"+bkey] = building
|
||||
tb.put(t, buckets.Placement, "placement.n1", tplace)
|
||||
tb.putAssigned(t, tplace)
|
||||
tb.put(t, buckets.Have, "n1.node", have)
|
||||
tb.put(t, buckets.Modules, "tool", tmod)
|
||||
tb.put(t, buckets.Wants, "want.n1.tool", twant)
|
||||
for _, bucket := range []string{buckets.Wants, buckets.Placement, buckets.Have, buckets.Modules,
|
||||
for _, bucket := range []string{buckets.Wants, buckets.Assignments, buckets.Have, buckets.Modules,
|
||||
ResolvedBucket, builds.BuilderBuildsBucket} {
|
||||
tb.send(bucket, agent.Update{Caught: true})
|
||||
}
|
||||
@@ -777,18 +779,19 @@ func TestTheNodeComposesItsWantsFromTheBus(t *testing.T) {
|
||||
b.kv[buckets.Manifests+"/"+kkey] = kman
|
||||
b.mu.Unlock()
|
||||
kmod, _ := meshcatalogclient.EncodeModule(meshcatalog.ModulesByModuleValue{Fp2: fp, Manifest: kdigest, Repository: "novox/k", Commit: "c"})
|
||||
both, _ := meshmoduleassignerclient.EncodePlacement(meshmoduleassigner.Placement{Node: "n1", Decided: meshmoduleassigner.NodeDecided{Hub: true, Address: "10.77.0.1"},
|
||||
both := assignedValues(t, meshmoduleassigner.Assignments{Node: "n1", Decided: meshmoduleassigner.NodeDecided{Hub: true, Address: "10.77.0.1"},
|
||||
Modules: []meshmoduleassigner.PlacedModule{{Module: "lemurs"}, {Module: "oldie"}, {Module: "keeper"}}})
|
||||
b.put(t, buckets.Modules, "keeper", kmod)
|
||||
// n1 is held in keys per module and node since the rows above, which a legacy key no longer moves.
|
||||
bothPlaced, _ := meshmoduleassignerclient.DecodePlacement(both)
|
||||
bothWrites, err := placeKeys.Writes("n1", &bothPlaced)
|
||||
// n1 is held in keys per module and node, which the writes below move.
|
||||
bothPlaced, _ := meshmoduleassignerclient.AssignmentsOf(both)
|
||||
bothNode := bothPlaced["n1"]
|
||||
bothWrites, err := placeKeys.Writes("n1", &bothNode)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, w := range bothWrites {
|
||||
if w.Value != nil {
|
||||
b.put(t, buckets.Placement, w.Key, w.Value)
|
||||
b.put(t, buckets.Assignments, w.Key, w.Value)
|
||||
}
|
||||
}
|
||||
b.put(t, buckets.Wants, "want.n1.keeper", want)
|
||||
@@ -889,8 +892,8 @@ func TestTheNodeComposesItsWantsFromTheBus(t *testing.T) {
|
||||
for k, v := range c.wants {
|
||||
again.wants[k] = v
|
||||
}
|
||||
for k, v := range c.placements {
|
||||
again.placements[k] = v
|
||||
for k, v := range c.assignments {
|
||||
again.assignments[k] = v
|
||||
}
|
||||
for k, v := range c.records {
|
||||
again.records[k] = v
|
||||
@@ -912,7 +915,7 @@ func TestTheNodeComposesItsWantsFromTheBus(t *testing.T) {
|
||||
// Then the catalogue no longer places the node: it composes nothing of its own, and owes no pass either, so
|
||||
// no timer is armed again (rev-seed-same-3, round 1).
|
||||
again.mu.Lock()
|
||||
clear(again.placements)
|
||||
clear(again.assignments)
|
||||
again.mu.Unlock()
|
||||
if again.compose(ctx); again.owed.Load() {
|
||||
t.Errorf("%s: an unplaced node still owes a pass", row.name)
|
||||
@@ -1034,17 +1037,17 @@ func TestTheNodeComposesItsWantsFromTheBus(t *testing.T) {
|
||||
if asked, _ := json.Marshal(sent["credentials"]); !strings.Contains(string(asked), `"role":"consumer"`) || !strings.Contains(string(asked), `"role":"provider"`) {
|
||||
t.Errorf("the vault was asked %s", asked)
|
||||
}
|
||||
// ADR 0559 §4: the node answers placement candidates in shadow, placed or not, applying nothing and handing no
|
||||
// composition: the same; a module the group adds, its secret not yet issued; a module removed; a placement it cannot
|
||||
// ADR 0559 §4: the node answers assignment candidates in shadow, placed or not, applying nothing and handing no
|
||||
// composition: the same; a module the group adds, its secret not yet issued; a module removed; a assignment it cannot
|
||||
// compose; a group whose keys went is no longer answered. What runs is never composed from a candidate: the
|
||||
// Composer does not read the state.
|
||||
for _, in := range New(env).inputs() {
|
||||
if in.bucket == buckets.PlacementCandidates {
|
||||
t.Fatal("the node's own composer reads placement candidates")
|
||||
if in.bucket == buckets.ProposalCandidates {
|
||||
t.Fatal("the node's own composer reads assignment candidates")
|
||||
}
|
||||
}
|
||||
sb := newPatternBus()
|
||||
trunk := meshmoduleassigner.Placement{Node: "n1", Decided: meshmoduleassigner.NodeDecided{Hub: true, Address: "10.77.0.1"}, Modules: []meshmoduleassigner.PlacedModule{{Module: "lemurs"}}}
|
||||
trunk := meshmoduleassigner.Assignments{Node: "n1", Decided: meshmoduleassigner.NodeDecided{Hub: true, Address: "10.77.0.1"}, Modules: []meshmoduleassigner.PlacedModule{{Module: "lemurs"}}}
|
||||
mods := map[string]meshcatalog.ModulesByModuleValue{"lemurs": {Fp2: fp, Manifest: digest, Repository: "novox/x", Commit: "c"},
|
||||
"keeper": {Fp2: fp, Manifest: kdigest, Repository: "novox/k", Commit: "c"}}
|
||||
readOnly := &fakeBus{kv: map[string][]byte{buckets.Manifests + "/" + key: man, buckets.Manifests + "/" + kkey: kman}}
|
||||
@@ -1058,7 +1061,7 @@ func TestTheNodeComposesItsWantsFromTheBus(t *testing.T) {
|
||||
return json.RawMessage(`{"node":"n1","key":"sk","own":[]}`), nil // nothing issued for keeper: it is not placed here
|
||||
}
|
||||
// What n1 runs: lemurs and its own composition, as its composer composes them from the trunk.
|
||||
running, _, _, err := frombus.Compose(ctx, fixedReader{placements: map[string]meshmoduleassigner.Placement{"n1": trunk},
|
||||
running, _, _, err := frombus.Compose(ctx, fixedReader{assignments: map[string]meshmoduleassigner.Assignments{"n1": trunk},
|
||||
records: map[string]nodeengine.NodeRecord{"n1": {Node: "n1", TunnelKey: "k", SealingKey: "sk", Capabilities: []string{"systemd"}}},
|
||||
modules: mods, manifests: map[string][]byte{digest: []byte(lemurs), kdigest: []byte(keeper)}}, frombus.Mesh{}, frombus.Scope{Node: "n1"}, map[string]string{"lemurs": fp})
|
||||
if err != nil {
|
||||
@@ -1071,7 +1074,7 @@ func TestTheNodeComposesItsWantsFromTheBus(t *testing.T) {
|
||||
}
|
||||
return out
|
||||
}
|
||||
// The controller's compositions at n1's wants, in n1's composition bucket: what a head deleting its placement
|
||||
// The controller's compositions at n1's wants, in n1's composition bucket: what a head deleting its assignment
|
||||
// returns it to (the seed's revert); here the ones it runs.
|
||||
composedBucket, _ := compositions.BucketFor("n1")
|
||||
for key, c := range running {
|
||||
@@ -1089,15 +1092,15 @@ func TestTheNodeComposesItsWantsFromTheBus(t *testing.T) {
|
||||
defer scancel()
|
||||
// Review of L2b, round 1, finding 2: the candidates' state is not there when the node starts (a delivery before the
|
||||
// indexer made it): the shadow tries again, and answers once it appears.
|
||||
sb.missing(buckets.PlacementCandidates, true)
|
||||
sb.missing(buckets.ProposalCandidates, true)
|
||||
kept := make(chan struct{})
|
||||
go func() { sh.Keep(sctx, func(int) time.Duration { return 5 * time.Millisecond }); close(kept) }()
|
||||
time.Sleep(30 * time.Millisecond)
|
||||
sb.missing(buckets.PlacementCandidates, false)
|
||||
sb.missing(buckets.ProposalCandidates, false)
|
||||
sb.made(6)
|
||||
rec, _ := nodeengineclient.EncodeHaveNode(nodeengine.HaveByNodeNodeValue{Record: &nodeengine.NodeRecord{Node: "n1", TunnelKey: "k", SealingKey: "sk", Capabilities: []string{"systemd"}}})
|
||||
tp, _ := meshmoduleassignerclient.EncodePlacement(trunk)
|
||||
sb.put(buckets.Placement, "placement.n1", tp, 1)
|
||||
tp := assignedValues(t, trunk)
|
||||
sb.putAssigned(tp, 1)
|
||||
sb.put(buckets.Have, "n1.node", rec, 1)
|
||||
for name, m := range mods {
|
||||
raw, _ := meshcatalogclient.EncodeModule(m)
|
||||
@@ -1124,33 +1127,33 @@ func TestTheNodeComposesItsWantsFromTheBus(t *testing.T) {
|
||||
for _, m := range modules {
|
||||
p.Modules = append(p.Modules, meshmoduleassigner.PlacedModule{Module: m})
|
||||
}
|
||||
raw, err := bucketstest.Candidate(meshmoduleassigner.CandidatesByProposalNodeValue{Proposal: group, Placement: &p})
|
||||
raw, err := bucketstest.Candidate(meshmoduleassigner.CandidatesByProposalNodeValue{Proposal: group, Assignments: &p})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
k := meshmoduleassigner.CandidatesByProposalNodeKey(group, "n1")
|
||||
sb.put(buckets.PlacementCandidates, k, raw, rev)
|
||||
sb.put(buckets.ProposalCandidates, k, raw, rev)
|
||||
}
|
||||
candidate("same", 3, "lemurs")
|
||||
candidate("adds", 4, "lemurs", "keeper")
|
||||
candidate("drops", 5)
|
||||
candidate("ghost", 6, "lemurs", "ghost")
|
||||
// A head deleting n1's placement file (the seed's revert, mesh-catalog #526): n1 returns to the controller's
|
||||
// A head deleting n1's assignment file (the seed's revert, mesh-catalog #526): n1 returns to the controller's
|
||||
// compositions, answered as such, not as every module removed.
|
||||
if raw, err := bucketstest.Candidate(meshmoduleassigner.CandidatesByProposalNodeValue{Proposal: "deletes"}); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
k := meshmoduleassigner.CandidatesByProposalNodeKey("deletes", "n1")
|
||||
sb.put(buckets.PlacementCandidates, k, raw, 7)
|
||||
sb.put(buckets.ProposalCandidates, k, raw, 7)
|
||||
}
|
||||
// A proposal that changes another node's key and reaches n1's composition (ADR 0567 §3): n1's candidate holds no
|
||||
// placement of its own change (Reached, nil), and n1 answers against its current placement, never as one whose key
|
||||
// assignment of its own change (Reached, nil), and n1 answers against its current assignment, never as one whose key
|
||||
// the proposal takes away.
|
||||
if raw, err := bucketstest.Candidate(meshmoduleassigner.CandidatesByProposalNodeValue{Proposal: "reach", Reached: true}); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
k := meshmoduleassigner.CandidatesByProposalNodeKey("reach", "n1")
|
||||
sb.put(buckets.PlacementCandidates, k, raw, 8)
|
||||
sb.put(buckets.ProposalCandidates, k, raw, 8)
|
||||
}
|
||||
sb.caught()
|
||||
var answers map[string]nodeengine.CandidateAnswer
|
||||
@@ -1199,7 +1202,7 @@ func TestTheNodeComposesItsWantsFromTheBus(t *testing.T) {
|
||||
return a.Verdict == nodeengine.CandidateAnswerVerdictSame && a.Returns == "" && a.Revision == 8 && len(a.Removed) == 0 &&
|
||||
fmt.Sprint(a.Same) == "[lemurs node]"
|
||||
},
|
||||
// Issue 1126, A7: a candidate deleting the node's placement is refused, never answered as a return to the
|
||||
// Issue 1126, A7: a candidate deleting the node's assignment is refused, never answered as a return to the
|
||||
// controller's compositions: no composition made elsewhere is applied, so the node would compose nothing.
|
||||
"deletes": func(a nodeengine.CandidateAnswer) bool {
|
||||
return a.Verdict == nodeengine.CandidateAnswerVerdictRefused && a.Returns == "" && a.Revision == 7 &&
|
||||
@@ -1218,7 +1221,7 @@ func TestTheNodeComposesItsWantsFromTheBus(t *testing.T) {
|
||||
case <-time.After(100 * time.Millisecond):
|
||||
}
|
||||
// Issue 1126, 2026-10-28 (shanks answered probe/1126-seed-7 at revision 84 every 13-17 s): a candidate revision is
|
||||
// answered once. A module's have whose health or words alone move (each look rewrites them), and a placement, a
|
||||
// answered once. A module's have whose health or words alone move (each look rewrites them), and a assignment, a
|
||||
// module or a config value written again with the value it held, answer nothing again; a new revision answers its
|
||||
// group alone, and what runs moving answers every group once.
|
||||
answering := func() int {
|
||||
@@ -1226,7 +1229,7 @@ func TestTheNodeComposesItsWantsFromTheBus(t *testing.T) {
|
||||
defer readOnly.mu.Unlock()
|
||||
n := 0
|
||||
for _, l := range readOnly.said {
|
||||
if strings.HasPrefix(l, "answering placement candidate ") {
|
||||
if strings.HasPrefix(l, "answering assignment candidate ") {
|
||||
n++
|
||||
}
|
||||
}
|
||||
@@ -1255,7 +1258,7 @@ func TestTheNodeComposesItsWantsFromTheBus(t *testing.T) {
|
||||
settled := answering()
|
||||
lemursHave("its tool lemurs_health: no answer within 10s", 11)
|
||||
lemursHave("its tool lemurs_health: no answer within 20s", 12)
|
||||
sb.put(buckets.Placement, "placement.n1", tp, 2)
|
||||
sb.putAssigned(tp, 2)
|
||||
lraw, _ := meshcatalogclient.EncodeModule(mods["lemurs"])
|
||||
sb.put(buckets.Modules, "lemurs", lraw, 2)
|
||||
drain()
|
||||
@@ -1279,7 +1282,7 @@ func TestTheNodeComposesItsWantsFromTheBus(t *testing.T) {
|
||||
}
|
||||
return ""
|
||||
}
|
||||
if got := lastSaid("answering placement candidate same "); got != "answering placement candidate same (revision 8; woken by the candidate)" {
|
||||
if got := lastSaid("answering assignment candidate same "); got != "answering assignment candidate same (revision 8; woken by the candidate)" {
|
||||
t.Errorf("a new revision's answer said %q", got)
|
||||
}
|
||||
settled = answering()
|
||||
@@ -1290,7 +1293,7 @@ func TestTheNodeComposesItsWantsFromTheBus(t *testing.T) {
|
||||
if got := answering(); got != settled+len(answers) {
|
||||
t.Errorf("what runs moved, and %d answer(s) were composed again for %d group(s)", got-settled, len(answers))
|
||||
}
|
||||
if got := lastSaid("answering placement candidate drops "); got != "answering placement candidate drops (revision 5; woken by haves)" {
|
||||
if got := lastSaid("answering assignment candidate drops "); got != "answering assignment candidate drops (revision 5; woken by haves)" {
|
||||
t.Errorf("an answer woken by what runs moving said %q", got)
|
||||
}
|
||||
// A read the bus did not answer is no answer to keep: the group is answered again after a bound, though nothing moved.
|
||||
@@ -1305,41 +1308,41 @@ func TestTheNodeComposesItsWantsFromTheBus(t *testing.T) {
|
||||
return a["adds"].Revision == 9 && a["adds"].Verdict == nodeengine.CandidateAnswerVerdictDiffers
|
||||
})
|
||||
drain()
|
||||
if got := lastSaid("answering placement candidate adds "); got != "answering placement candidate adds (revision 9; woken by a retry after a read the bus did not answer)" {
|
||||
if got := lastSaid("answering assignment candidate adds "); got != "answering assignment candidate adds (revision 9; woken by a retry after a read the bus did not answer)" {
|
||||
t.Errorf("an answer composed again after the bus did not answer said %q", got)
|
||||
}
|
||||
k := meshmoduleassigner.CandidatesByProposalNodeKey("same", "n1")
|
||||
sb.del(buckets.PlacementCandidates, k)
|
||||
sb.del(buckets.ProposalCandidates, k)
|
||||
waitFor("the deleted group's answer stays", func(a map[string]nodeengine.CandidateAnswer) bool { _, ok := a["same"]; return !ok && len(a) == 5 })
|
||||
|
||||
// Review of L2b, round 2: a watch ends while the link stays; a group's key is deleted before the shadow watches
|
||||
// again. The new run reads afresh, so that group is no longer answered.
|
||||
sb.missing(buckets.PlacementCandidates, true)
|
||||
sb.missing(buckets.ProposalCandidates, true)
|
||||
sb.end(buckets.Modules)
|
||||
dropsKey := meshmoduleassigner.CandidatesByProposalNodeKey("drops", "n1")
|
||||
sb.del(buckets.PlacementCandidates, dropsKey)
|
||||
sb.del(buckets.ProposalCandidates, dropsKey)
|
||||
time.Sleep(30 * time.Millisecond)
|
||||
sb.missing(buckets.PlacementCandidates, false)
|
||||
sb.missing(buckets.ProposalCandidates, false)
|
||||
waitFor("a group deleted while the shadow was down is still answered", func(a map[string]nodeengine.CandidateAnswer) bool {
|
||||
_, ok := a["drops"]
|
||||
return !ok && len(a) == 4
|
||||
})
|
||||
|
||||
// Issue 1126, A7 AC1: a placement that cannot be read composes nothing and says why; the node never applies a
|
||||
// composition made elsewhere instead. (A placement read without the node's key composes nothing either: above.)
|
||||
// Issue 1126, A7 AC1: a assignment that cannot be read composes nothing and says why; the node never applies a
|
||||
// composition made elsewhere instead. (A assignment read without the node's key composes nothing either: above.)
|
||||
{
|
||||
refused := newFakeBus()
|
||||
env := refused.env()
|
||||
watch := env.Watch
|
||||
env.Watch = func(ctx context.Context, bucket, pattern string) (<-chan agent.Update, error) {
|
||||
if bucket == buckets.Placement {
|
||||
if bucket == buckets.Assignments {
|
||||
return nil, fmt.Errorf("nats: Permissions Violation for Subscription to %s", bucket)
|
||||
}
|
||||
return watch(ctx, bucket, pattern)
|
||||
}
|
||||
out, err := New(env).Watch(ctx, "")
|
||||
if out != nil || err == nil || !strings.Contains(err.Error(), buckets.Placement) || !strings.Contains(err.Error(), "cannot be watched") {
|
||||
t.Errorf("an unreadable placement: composed %v, said %v", out != nil, err)
|
||||
if out != nil || err == nil || !strings.Contains(err.Error(), buckets.Assignments) || !strings.Contains(err.Error(), "cannot be watched") {
|
||||
t.Errorf("an unreadable assignment: composed %v, said %v", out != nil, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1359,20 +1362,20 @@ func TestTheNodeComposesItsWantsFromTheBus(t *testing.T) {
|
||||
defer ncancel()
|
||||
go func() { _ = nsh.Run(nctx) }()
|
||||
nb.made(6)
|
||||
nb.put(buckets.Placement, "placement.n1", tp, 1)
|
||||
nb.putAssigned(tp, 1)
|
||||
nb.put(buckets.Have, "n1.node", rec, 1)
|
||||
for name, m := range mods {
|
||||
raw, _ := meshcatalogclient.EncodeModule(m)
|
||||
nb.put(buckets.Modules, name, raw, 1)
|
||||
}
|
||||
sameRaw, _ := bucketstest.Candidate(meshmoduleassigner.CandidatesByProposalNodeValue{Proposal: "same", Placement: &trunk})
|
||||
sameRaw, _ := bucketstest.Candidate(meshmoduleassigner.CandidatesByProposalNodeValue{Proposal: "same", Assignments: &trunk})
|
||||
sameKey := meshmoduleassigner.CandidatesByProposalNodeKey("same", "n1")
|
||||
nb.put(buckets.PlacementCandidates, sameKey, sameRaw, 3)
|
||||
nb.put(buckets.ProposalCandidates, sameKey, sameRaw, 3)
|
||||
// Issue 1126, T3: an older group (a closed pull request's candidate, rev 2) is answered after the newest.
|
||||
oldRaw, _ := bucketstest.Candidate(meshmoduleassigner.CandidatesByProposalNodeValue{Proposal: "older", Placement: &trunk})
|
||||
oldRaw, _ := bucketstest.Candidate(meshmoduleassigner.CandidatesByProposalNodeValue{Proposal: "older", Assignments: &trunk})
|
||||
oldKey := meshmoduleassigner.CandidatesByProposalNodeKey("older", "n1")
|
||||
nb.put(buckets.PlacementCandidates, oldKey, oldRaw, 2)
|
||||
for _, bucket := range []string{buckets.PlacementCandidates, buckets.Placement, buckets.Have, buckets.Modules, builds.BuilderBuildsBucket} {
|
||||
nb.put(buckets.ProposalCandidates, oldKey, oldRaw, 2)
|
||||
for _, bucket := range []string{buckets.ProposalCandidates, buckets.Assignments, buckets.Have, buckets.Modules, builds.BuilderBuildsBucket} {
|
||||
nb.send(bucket, agent.Update{Caught: true})
|
||||
}
|
||||
select {
|
||||
@@ -1384,7 +1387,7 @@ func TestTheNodeComposesItsWantsFromTheBus(t *testing.T) {
|
||||
t.Fatal("a shadow not ready after its wait answered nothing")
|
||||
}
|
||||
nmu.Lock()
|
||||
if !strings.Contains(strings.Join(nsaid, "\n"), "this node answers no placement candidate yet: the node has not read "+ResolvedBucket) {
|
||||
if !strings.Contains(strings.Join(nsaid, "\n"), "this node answers no assignment candidate yet: the node has not read "+ResolvedBucket) {
|
||||
t.Errorf("a shadow not ready said %q", nsaid)
|
||||
}
|
||||
nmu.Unlock()
|
||||
@@ -1408,13 +1411,13 @@ func TestTheNodeComposesItsWantsFromTheBus(t *testing.T) {
|
||||
// Issue 1126, T2: an answer says when it starts and when it ends (and, every minute between, what it waits on).
|
||||
nmu.Lock()
|
||||
said := strings.Join(nsaid, "\n")
|
||||
for _, line := range []string{"the answer to same took", "answering placement candidate same (revision 3; woken by its first answer since the shadow began)",
|
||||
"answered placement candidate same in", "answering placement candidate older (revision 2;"} {
|
||||
for _, line := range []string{"the answer to same took", "answering assignment candidate same (revision 3; woken by its first answer since the shadow began)",
|
||||
"answered assignment candidate same in", "answering assignment candidate older (revision 2;"} {
|
||||
if !strings.Contains(said, line) {
|
||||
t.Errorf("%q was not said: %q", line, nsaid)
|
||||
}
|
||||
}
|
||||
if strings.Index(said, "answering placement candidate same") > strings.Index(said, "answering placement candidate older") {
|
||||
if strings.Index(said, "answering assignment candidate same") > strings.Index(said, "answering assignment candidate older") {
|
||||
t.Errorf("the older group was answered first: %q", nsaid)
|
||||
}
|
||||
nmu.Unlock()
|
||||
@@ -1454,7 +1457,7 @@ func TestTheNodeComposesItsWantsFromTheBus(t *testing.T) {
|
||||
// trunk's.
|
||||
inOwnRunning := []compositions.Composed{{Node: "n1", Module: "lemurs", FP: fp}}
|
||||
other := "src2:" + strings.Repeat("9", 64)
|
||||
gotFps := shadowBuilds(inOwnRunning, meshmoduleassigner.Placement{Node: "n1", Modules: []meshmoduleassigner.PlacedModule{{Module: "lemurs"}, {Module: "nats"}, {Module: "keeper"}}},
|
||||
gotFps := shadowBuilds(inOwnRunning, meshmoduleassigner.Assignments{Node: "n1", Modules: []meshmoduleassigner.PlacedModule{{Module: "lemurs"}, {Module: "nats"}, {Module: "keeper"}}},
|
||||
map[string]meshcatalog.ModulesByModuleValue{"lemurs": {Fp2: other}, "nats": {Fp2: other}, "keeper": {Fp2: other}}, []string{"nats"})
|
||||
if fmt.Sprint(gotFps) != fmt.Sprint(map[string]string{"lemurs": fp, "keeper": other}) {
|
||||
t.Errorf("shadow builds %v; want lemurs at what runs, keeper at the trunk's, nats at none (folded)", gotFps)
|
||||
@@ -1519,12 +1522,12 @@ func TestTheNodeComposesItsWantsFromTheBus(t *testing.T) {
|
||||
cc.manifests[cdigest] = []byte(withCert)
|
||||
cc.modules = map[string]meshcatalog.ModulesByModuleValue{"lemurs": {Manifest: digest}, "web": {Manifest: cdigest}}
|
||||
cc.records["n1"] = nodeengine.NodeRecord{Node: "n1", ServingKey: base64.StdEncoding.EncodeToString(make([]byte, 32))}
|
||||
onlyLemurs := meshmoduleassigner.Placement{Node: "n1", Modules: []meshmoduleassigner.PlacedModule{{Module: "lemurs"}}}
|
||||
onlyLemurs := meshmoduleassigner.Assignments{Node: "n1", Modules: []meshmoduleassigner.PlacedModule{{Module: "lemurs"}}}
|
||||
cc.certifyIfWanted(context.Background(), reader{c: cc}, onlyLemurs)
|
||||
if certAsks != 0 {
|
||||
t.Errorf("no module asks for a certificate, and the vault was asked %d times", certAsks)
|
||||
}
|
||||
withWeb := meshmoduleassigner.Placement{Node: "n1", Modules: []meshmoduleassigner.PlacedModule{{Module: "lemurs"}, {Module: "web"}}}
|
||||
withWeb := meshmoduleassigner.Assignments{Node: "n1", Modules: []meshmoduleassigner.PlacedModule{{Module: "lemurs"}, {Module: "web"}}}
|
||||
cc.certifyIfWanted(context.Background(), reader{c: cc}, withWeb)
|
||||
cc.certifyIfWanted(context.Background(), reader{c: cc}, withWeb)
|
||||
if certAsks != 1 {
|
||||
@@ -1665,14 +1668,14 @@ func (b *patternBus) caught() {
|
||||
|
||||
// fixedReader is frombus's Reader over values held, for composing what a node runs.
|
||||
type fixedReader struct {
|
||||
placements map[string]meshmoduleassigner.Placement
|
||||
records map[string]nodeengine.NodeRecord
|
||||
modules map[string]meshcatalog.ModulesByModuleValue
|
||||
manifests map[string][]byte
|
||||
assignments map[string]meshmoduleassigner.Assignments
|
||||
records map[string]nodeengine.NodeRecord
|
||||
modules map[string]meshcatalog.ModulesByModuleValue
|
||||
manifests map[string][]byte
|
||||
}
|
||||
|
||||
func (r fixedReader) Placements(context.Context) (map[string]meshmoduleassigner.Placement, error) {
|
||||
return r.placements, nil
|
||||
func (r fixedReader) Assignments(context.Context) (map[string]meshmoduleassigner.Assignments, error) {
|
||||
return r.assignments, nil
|
||||
}
|
||||
func (r fixedReader) Records(context.Context) (map[string]nodeengine.NodeRecord, error) {
|
||||
return r.records, nil
|
||||
@@ -1791,18 +1794,18 @@ func TestAnUnreadSeatListHoldsWhatIsNewAndHandsItAtTheRead(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
place, _ := meshmoduleassignerclient.EncodePlacement(meshmoduleassigner.Placement{Node: "n1", Decided: meshmoduleassigner.NodeDecided{Hub: true, Address: "10.77.0.1"},
|
||||
place := assignedValues(t, meshmoduleassigner.Assignments{Node: "n1", Decided: meshmoduleassigner.NodeDecided{Hub: true, Address: "10.77.0.1"},
|
||||
Modules: []meshmoduleassigner.PlacedModule{{Module: "lemurs"}}})
|
||||
have, _ := nodeengineclient.EncodeHaveNode(nodeengine.HaveByNodeNodeValue{Record: &nodeengine.NodeRecord{Node: "n1", TunnelKey: "k", SealingKey: "sk", Capabilities: []string{"systemd"}}})
|
||||
mod, _ := meshcatalogclient.EncodeModule(meshcatalog.ModulesByModuleValue{Fp2: fp, Manifest: digest, Repository: "novox/x", Commit: "c"})
|
||||
want, _ := bucketstest.Want(meshwants.WantsByWantNodeModuleValue{Fp: fp, Self: true})
|
||||
nodeWant, _ := bucketstest.NodeWant(meshwants.WantsByWantNodeNodeValue{Self: true})
|
||||
b.put(t, buckets.Placement, "placement.n1", place)
|
||||
b.putAssigned(t, place)
|
||||
b.put(t, buckets.Have, "n1.node", have)
|
||||
b.put(t, buckets.Modules, "lemurs", mod)
|
||||
b.put(t, buckets.Wants, "want.n1.lemurs", want)
|
||||
b.put(t, buckets.Wants, "want.n1.node", nodeWant)
|
||||
for _, bucket := range []string{buckets.Wants, buckets.Placement, buckets.Have, buckets.Modules, ResolvedBucket, builds.BuilderBuildsBucket} {
|
||||
for _, bucket := range []string{buckets.Wants, buckets.Assignments, buckets.Have, buckets.Modules, ResolvedBucket, builds.BuilderBuildsBucket} {
|
||||
b.send(bucket, agent.Update{Caught: true})
|
||||
}
|
||||
handed := map[string]bool{}
|
||||
@@ -1872,18 +1875,18 @@ func TestAHeldOwnCompositionThatWasHandedIsNotDropped(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
place, _ := meshmoduleassignerclient.EncodePlacement(meshmoduleassigner.Placement{Node: "n1", Decided: meshmoduleassigner.NodeDecided{Hub: true, Address: "10.77.0.1"},
|
||||
place := assignedValues(t, meshmoduleassigner.Assignments{Node: "n1", Decided: meshmoduleassigner.NodeDecided{Hub: true, Address: "10.77.0.1"},
|
||||
Modules: []meshmoduleassigner.PlacedModule{{Module: "lemurs"}}})
|
||||
have, _ := nodeengineclient.EncodeHaveNode(nodeengine.HaveByNodeNodeValue{Record: &nodeengine.NodeRecord{Node: "n1", TunnelKey: "k", SealingKey: "sk", Capabilities: []string{"systemd"}}})
|
||||
mod, _ := meshcatalogclient.EncodeModule(meshcatalog.ModulesByModuleValue{Fp2: fp, Manifest: digest, Repository: "novox/x", Commit: "c"})
|
||||
want, _ := bucketstest.Want(meshwants.WantsByWantNodeModuleValue{Fp: fp, Self: true})
|
||||
nodeWant, _ := bucketstest.NodeWant(meshwants.WantsByWantNodeNodeValue{Self: true})
|
||||
b.put(t, buckets.Placement, "placement.n1", place)
|
||||
b.putAssigned(t, place)
|
||||
b.put(t, buckets.Have, "n1.node", have)
|
||||
b.put(t, buckets.Modules, "lemurs", mod)
|
||||
b.put(t, buckets.Wants, "want.n1.lemurs", want)
|
||||
b.put(t, buckets.Wants, "want.n1.node", nodeWant)
|
||||
for _, bucket := range []string{buckets.Wants, buckets.Placement, buckets.Have, buckets.Modules, ResolvedBucket, builds.BuilderBuildsBucket} {
|
||||
for _, bucket := range []string{buckets.Wants, buckets.Assignments, buckets.Have, buckets.Modules, ResolvedBucket, builds.BuilderBuildsBucket} {
|
||||
b.send(bucket, agent.Update{Caught: true})
|
||||
}
|
||||
// The list is read: the node's own composition is handed. Then the reader cannot act again (it restarted and has
|
||||
@@ -1999,13 +2002,13 @@ func TestTheHolderOfTheCatalogIsStartedFromTheOwnCompositionBeforeTheListIsReadA
|
||||
b.put(t, buckets.Have, hk, hv)
|
||||
placed = append(placed, meshmoduleassigner.PlacedModule{Module: m})
|
||||
}
|
||||
place, _ := meshmoduleassignerclient.EncodePlacement(meshmoduleassigner.Placement{Node: "n1", Decided: meshmoduleassigner.NodeDecided{Hub: true, Address: "10.77.0.1"}, Modules: placed})
|
||||
place := assignedValues(t, meshmoduleassigner.Assignments{Node: "n1", Decided: meshmoduleassigner.NodeDecided{Hub: true, Address: "10.77.0.1"}, Modules: placed})
|
||||
have, _ := nodeengineclient.EncodeHaveNode(nodeengine.HaveByNodeNodeValue{Record: &nodeengine.NodeRecord{Node: "n1", TunnelKey: "k", SealingKey: "sk", Capabilities: []string{"systemd"}}})
|
||||
nodeWant, _ := bucketstest.NodeWant(meshwants.WantsByWantNodeNodeValue{Self: true})
|
||||
b.put(t, buckets.Placement, "placement.n1", place)
|
||||
b.putAssigned(t, place)
|
||||
b.put(t, buckets.Have, "n1.node", have)
|
||||
b.put(t, buckets.Wants, "want.n1.node", nodeWant)
|
||||
for _, bucket := range []string{buckets.Wants, buckets.Placement, buckets.Have, buckets.Modules, ResolvedBucket, builds.BuilderBuildsBucket} {
|
||||
for _, bucket := range []string{buckets.Wants, buckets.Assignments, buckets.Have, buckets.Modules, ResolvedBucket, builds.BuilderBuildsBucket} {
|
||||
b.send(bucket, agent.Update{Caught: true})
|
||||
}
|
||||
servicesIn := func(u agent.Update) []string {
|
||||
@@ -2056,3 +2059,28 @@ func TestACompositionHoldsWhenTheSeatListReaderCouldNotStart(t *testing.T) {
|
||||
t.Errorf("held %v, comps %v: a reader that did not start must hold the node's own composition", held, comps)
|
||||
}
|
||||
}
|
||||
|
||||
// assignedValues is every key the assigner writes for p: the node's, `<node>.node`, and each module's, `<node>.<module>`.
|
||||
func assignedValues(t *testing.T, p meshmoduleassigner.Assignments) map[string][]byte {
|
||||
t.Helper()
|
||||
vals, err := meshmoduleassignerclient.AssignmentsValues(p)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return vals
|
||||
}
|
||||
|
||||
// putAssigned writes the keys of one node's assignments into the assignments state.
|
||||
func (b *fakeBus) putAssigned(t *testing.T, vals map[string][]byte) {
|
||||
t.Helper()
|
||||
for _, k := range slices.Sorted(maps.Keys(vals)) {
|
||||
b.put(t, buckets.Assignments, k, vals[k])
|
||||
}
|
||||
}
|
||||
|
||||
// putAssigned sends the keys of one node's assignments, each at the revision.
|
||||
func (b *patternBus) putAssigned(vals map[string][]byte, rev uint64) {
|
||||
for _, k := range slices.Sorted(maps.Keys(vals)) {
|
||||
b.put(buckets.Assignments, k, vals[k], rev)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,10 +6,10 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient"
|
||||
"git.novox.be/novox/mesh-contracts/go/seats/meshmoduleassigner"
|
||||
nodeengine "git.novox.be/novox/mesh-contracts/go/seats/nodeengine"
|
||||
"git.novox.be/novox/mesh-contracts/placement/go/seats/meshmoduleassigner"
|
||||
"git.novox.be/novox/mesh-contracts/placement/go/seats/meshwants"
|
||||
"git.novox.be/novox/mesh-delivery/contracts/go/seats/meshcatalog"
|
||||
"git.novox.be/novox/mesh-delivery/contracts/go/seats/meshwants"
|
||||
"github.com/novox/mesh-host/internal/buckets"
|
||||
"github.com/novox/mesh-host/internal/compose/frombus"
|
||||
engcomp "github.com/novox/mesh-host/internal/compositions"
|
||||
@@ -23,13 +23,13 @@ import (
|
||||
"github.com/novox/mesh-host/internal/agent"
|
||||
)
|
||||
|
||||
// Shadow is the node's answer to placement candidates (novox/hq ADR 0559 §4, issue 1126): for every proposal with a key in
|
||||
// the placement seat's state `candidates`, it composes this node in shadow from the trunk's placement with the proposal's
|
||||
// Shadow is the node's answer to assignment candidates (novox/hq ADR 0559 §4, issue 1126): for every proposal with a key in
|
||||
// the assignment seat's state `candidates`, it composes this node in shadow from the trunk's assignment with the proposal's
|
||||
// keys laid over it and its own inputs (the sealed values and boxes it holds among them), compares the result with what
|
||||
// the node runs, and hands the answers to be written into the node's own have key, `<node>.node`, under `candidates`.
|
||||
// It applies nothing and hands no composition: what runs is still composed from `placement` alone, by the Composer.
|
||||
// It applies nothing and hands no composition: what runs is still composed from `assignment` alone, by the Composer.
|
||||
//
|
||||
// **Event-driven, like the Composer.** It watches every candidate key, the trunk's placement, every node's record, the
|
||||
// **Event-driven, like the Composer.** It watches every candidate key, the trunk's assignment, every node's record, the
|
||||
// indexer's modules, this node's config values, and this node's module haves (what it runs moved); a burst of changes
|
||||
// answers once. It runs whether or not the node is placed yet, against what it runs. An answer is handed only when it changes, and a proposal's answer is dropped when its
|
||||
// keys go.
|
||||
@@ -72,7 +72,7 @@ type answeredAt struct {
|
||||
}
|
||||
|
||||
// inputWords name the shadow's inputs, in Run's order, as an answer says which of them woke it.
|
||||
var inputWords = [...]string{"the candidate", "placement", "records", "modules", "values", "haves"}
|
||||
var inputWords = [...]string{"the candidate", "assignment", "records", "modules", "values", "haves"}
|
||||
|
||||
// wokenBy says what moved between the answer a proposal stands at (had, when done) and the one about to be composed (at):
|
||||
// its first answer, a retry, its candidate's revisions, or the inputs that changed, by their words.
|
||||
@@ -130,7 +130,7 @@ func (s *Shadow) Keep(ctx context.Context, backoff func(try int) time.Duration)
|
||||
why = err.Error()
|
||||
}
|
||||
if why != said {
|
||||
s.c.env.Say("this node answers no placement candidate for now, and tries again: " + why)
|
||||
s.c.env.Say("this node answers no assignment candidate for now, and tries again: " + why)
|
||||
said = why
|
||||
}
|
||||
select {
|
||||
@@ -161,8 +161,8 @@ func (s *Shadow) Run(ctx context.Context) error {
|
||||
node := c.env.Node
|
||||
// In inputWords' order.
|
||||
ins := []input{
|
||||
{buckets.PlacementCandidates, ">", nil, nil},
|
||||
{buckets.Placement, ">", (*Composer).takePlacement, nil},
|
||||
{buckets.ProposalCandidates, ">", nil, nil},
|
||||
{buckets.Assignments, ">", (*Composer).takeAssignments, nil},
|
||||
{buckets.Have, "*." + nodeengineclient.NodeWord, nil, nil},
|
||||
{buckets.Modules, ">", (*Composer).takeModule, nil},
|
||||
{ResolvedBucket, node + ".>", (*Composer).takeValue, nil},
|
||||
@@ -178,7 +178,7 @@ func (s *Shadow) Run(ctx context.Context) error {
|
||||
for i, in := range ins {
|
||||
ch, err := c.env.Watch(ctx, in.bucket, in.pattern)
|
||||
if err != nil {
|
||||
return fmt.Errorf("the node answers placement candidates from %s, which cannot be watched: %w", in.bucket, err)
|
||||
return fmt.Errorf("the node answers assignment candidates from %s, which cannot be watched: %w", in.bucket, err)
|
||||
}
|
||||
go func(i int, ch <-chan agent.Update) {
|
||||
for u := range ch {
|
||||
@@ -216,7 +216,7 @@ func (s *Shadow) Run(ctx context.Context) error {
|
||||
continue
|
||||
case t := <-merged:
|
||||
if !t.ok {
|
||||
return fmt.Errorf("the watch of %s ended; the node answers no placement candidate until its agent starts again", ins[t.in].bucket)
|
||||
return fmt.Errorf("the watch of %s ended; the node answers no assignment candidate until its agent starts again", ins[t.in].bucket)
|
||||
}
|
||||
// Only a change of what an answer is composed from answers again: a key written again with the value it held,
|
||||
// this node's own key (its answers), or a module's have whose health or words moved but not what it runs, is
|
||||
@@ -258,7 +258,7 @@ func (s *Shadow) Run(ctx context.Context) error {
|
||||
if s.owed {
|
||||
wait := LaterWait(tries)
|
||||
tries++
|
||||
c.env.Say(fmt.Sprintf("this node answers again in %s the placement candidates whose answer met a bus that did not answer", wait))
|
||||
c.env.Say(fmt.Sprintf("this node answers again in %s the assignment candidates whose answer met a bus that did not answer", wait))
|
||||
again = time.After(wait)
|
||||
} else {
|
||||
tries, again = 0, nil
|
||||
@@ -300,7 +300,7 @@ func (s *Shadow) takeCandidate(u agent.Update) bool {
|
||||
return true
|
||||
}
|
||||
c, err := meshmoduleassigner.DecodeCandidatesByProposalNodeValue(u.Value)
|
||||
if err != nil || c.Proposal != proposal || (c.Placement != nil && c.Placement.Node != node) {
|
||||
if err != nil || c.Proposal != proposal || (c.Assignments != nil && c.Assignments.Node != node) {
|
||||
// Not one: read as gone.
|
||||
if _, ok := s.candidates[proposal][node]; ok {
|
||||
delete(s.candidates[proposal], node)
|
||||
@@ -345,7 +345,7 @@ func (s *Shadow) notReady(ctx context.Context, ins []input, caught []bool) {
|
||||
}
|
||||
}
|
||||
why := fmt.Sprintf("the node has not read %s after %s; it answers once it has", strings.Join(waits, ", "), notReadyAfter)
|
||||
s.c.env.Say("this node answers no placement candidate yet: " + why)
|
||||
s.c.env.Say("this node answers no assignment candidate yet: " + why)
|
||||
s.mu.Lock()
|
||||
next := map[string]nodeengine.CandidateAnswer{}
|
||||
for proposal, keys := range s.candidates {
|
||||
@@ -428,7 +428,7 @@ func (s *Shadow) answerAll(ctx context.Context) {
|
||||
given[g] = a
|
||||
}
|
||||
s.answer(ctx, given)
|
||||
c.env.Say(fmt.Sprintf("%s answered %d placement candidate proposal(s)", node, len(given)))
|
||||
c.env.Say(fmt.Sprintf("%s answered %d assignment candidate proposal(s)", node, len(given)))
|
||||
}
|
||||
}
|
||||
for _, l := range proposals {
|
||||
@@ -444,7 +444,7 @@ func (s *Shadow) answerAll(ctx context.Context) {
|
||||
continue
|
||||
}
|
||||
began := time.Now()
|
||||
c.env.Say(fmt.Sprintf("answering placement candidate %s (revision %d; woken by %s)", proposal, l.rev, wokenBy(at, done, retry, l.at)))
|
||||
c.env.Say(fmt.Sprintf("answering assignment candidate %s (revision %d; woken by %s)", proposal, l.rev, wokenBy(at, done, retry, l.at)))
|
||||
stop := make(chan struct{})
|
||||
go func() {
|
||||
tick := time.NewTicker(progressEvery)
|
||||
@@ -474,10 +474,10 @@ func (s *Shadow) answerAll(ctx context.Context) {
|
||||
if ok {
|
||||
a = judge.FitAnswer(a, engcomp.MaxAnswerBytes)
|
||||
next[proposal] = a
|
||||
c.env.Say(fmt.Sprintf("answered placement candidate %s in %s: %s", proposal, took.Round(time.Millisecond), a.Verdict))
|
||||
c.env.Say(fmt.Sprintf("answered assignment candidate %s in %s: %s", proposal, took.Round(time.Millisecond), a.Verdict))
|
||||
} else {
|
||||
delete(next, proposal)
|
||||
c.env.Say(fmt.Sprintf("placement candidate %s does not place this node: nothing to answer", proposal))
|
||||
c.env.Say(fmt.Sprintf("assignment candidate %s does not place this node: nothing to answer", proposal))
|
||||
}
|
||||
s.mu.Lock()
|
||||
if provisional {
|
||||
@@ -507,12 +507,12 @@ func (s *Shadow) answerProposal(ctx context.Context, proposal string) (nodeengin
|
||||
defer c.waiting("composing")()
|
||||
s.mu.Lock()
|
||||
keys := s.candidates[proposal]
|
||||
given := make(map[string]*meshmoduleassigner.Placement, len(keys))
|
||||
given := make(map[string]*meshmoduleassigner.Assignments, len(keys))
|
||||
for n, k := range keys {
|
||||
if k.c.Reached && k.c.Placement == nil {
|
||||
if k.c.Reached && k.c.Assignments == nil {
|
||||
continue // reached, with no key of its own: nothing laid over it
|
||||
}
|
||||
given[n] = k.c.Placement
|
||||
given[n] = k.c.Assignments
|
||||
}
|
||||
// The revision answered is the node's own candidate key's; a node with none is not asked.
|
||||
own, mine := keys[node]
|
||||
@@ -534,26 +534,26 @@ func (s *Shadow) answerProposal(ctx context.Context, proposal string) (nodeengin
|
||||
running = c.env.Running()
|
||||
}
|
||||
if p, ok := given[node]; ok && p == nil && !own.c.Reached {
|
||||
// The proposal deletes this node's placement key: the node would compose nothing and keep running what it runs,
|
||||
// The proposal deletes this node's assignment key: the node would compose nothing and keep running what it runs,
|
||||
// since no composition made elsewhere is applied (issue 1126: the controller ended by its unassignment). Refused,
|
||||
// so the catalogue does not take a node's placement away by a merge.
|
||||
// so the catalogue does not take a node's assignment away by a merge.
|
||||
return nodeengine.CandidateAnswer{Proposal: proposal, Revision: int64(rev), Verdict: nodeengine.CandidateAnswerVerdictRefused,
|
||||
Refused: "the proposal takes this node's placement away: it then composes nothing, and no composition made " +
|
||||
Refused: "the proposal takes this node's assignment away: it then composes nothing, and no composition made " +
|
||||
"elsewhere is applied, so what runs here would be followed by nothing"}, true
|
||||
}
|
||||
|
||||
placement := given[node]
|
||||
if placement == nil {
|
||||
assignment := given[node]
|
||||
if assignment == nil {
|
||||
c.mu.Lock()
|
||||
p := c.placements[node]
|
||||
p := c.assignments[node]
|
||||
c.mu.Unlock()
|
||||
placement = &p
|
||||
assignment = &p
|
||||
}
|
||||
// What it runs inside its own composition, of what the candidate places (the seed's trunk places nothing).
|
||||
c.mu.Lock()
|
||||
inOwn := c.inOwnOf(*placement)
|
||||
inOwn := c.inOwnOf(*assignment)
|
||||
c.mu.Unlock()
|
||||
fps := shadowBuilds(running, *placement, modules, inOwn)
|
||||
fps := shadowBuilds(running, *assignment, modules, inOwn)
|
||||
kept := map[string]string{}
|
||||
for module, fp := range fps {
|
||||
if mod, ok := modules[module]; ok && mod.Fp2 == fp {
|
||||
@@ -570,7 +570,7 @@ func (s *Shadow) answerProposal(ctx context.Context, proposal string) (nodeengin
|
||||
c.mu.Lock()
|
||||
c.wants = held
|
||||
c.mu.Unlock()
|
||||
a := frombus.Answer(ctx, reader{c: c}, c.env.Mesh, frombus.Scope{Node: node, KeptAt: kept, Placements: given, InOwn: inOwn,
|
||||
a := frombus.Answer(ctx, reader{c: c}, c.env.Mesh, frombus.Scope{Node: node, KeptAt: kept, Assignments: given, InOwn: inOwn,
|
||||
SameValue: c.sameValue, HeldToday: s.heldToday()}, fps, running, proposal, rev)
|
||||
s.mu.Lock()
|
||||
ran := make(map[string]string, len(s.ran))
|
||||
@@ -664,7 +664,7 @@ func asHavesSay(a nodeengine.CandidateAnswer, ran map[string]string) nodeengine.
|
||||
// of the old form) is given none, so it is folded there again, as the node's own composer folds it, rather than
|
||||
// composed at the trunk's build as if the candidate added it (issue 1126: nats and photos have a trunk build that no
|
||||
// want names).
|
||||
func shadowBuilds(running []engcomp.Composed, placement meshmoduleassigner.Placement, modules map[string]meshcatalog.ModulesByModuleValue, inOwn []string) map[string]string {
|
||||
func shadowBuilds(running []engcomp.Composed, assignment meshmoduleassigner.Assignments, modules map[string]meshcatalog.ModulesByModuleValue, inOwn []string) map[string]string {
|
||||
fps := map[string]string{}
|
||||
for _, r := range running {
|
||||
if r.Module != "" && r.FP != "" {
|
||||
@@ -675,7 +675,7 @@ func shadowBuilds(running []engcomp.Composed, placement meshmoduleassigner.Place
|
||||
for _, m := range inOwn {
|
||||
folded[m] = true
|
||||
}
|
||||
for _, m := range placement.Modules {
|
||||
for _, m := range assignment.Modules {
|
||||
if _, runs := fps[m.Module]; !runs && !folded[m.Module] {
|
||||
if mod, ok := modules[m.Module]; ok && mod.Fp2 != "" {
|
||||
fps[m.Module] = mod.Fp2
|
||||
|
||||
Reference in New Issue
Block a user