Name every kind of an untaken module's resources in the adoption envelope, not only files and containers (hq ADR 0103)

This commit is contained in:
2026-09-22 18:03:03 +02:00
parent c91fe1a6eb
commit 41c300eae0
2 changed files with 12 additions and 10 deletions
+8 -8
View File
@@ -4,6 +4,7 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"sort" "sort"
"strings"
"github.com/novox/mesh-controller/internal/catalogue" "github.com/novox/mesh-controller/internal/catalogue"
"github.com/novox/mesh-controller/internal/inventory" "github.com/novox/mesh-controller/internal/inventory"
@@ -23,8 +24,8 @@ type sendable struct {
} }
// adoptionEnvelope is what an adopted node is told about its mode. Taken is every module taken on // adoptionEnvelope is what an adopted node is told about its mode. Taken is every module taken on
// it that it runs; Untaken is, for every module it runs that is not taken, the ids of that module's // it that it runs; Untaken is, for every module it runs that is not taken, the ids of every one of
// files and containers — the resources the host keeps as found until the module is taken. Ids // that module's resources — what the host keeps as found until the module is taken (ADR 0103). Ids
// rather than a rule to split them by, because a module's name may contain a dot. // rather than a rule to split them by, because a module's name may contain a dot.
type adoptionEnvelope struct { type adoptionEnvelope struct {
Taken []string `json:"taken"` Taken []string `json:"taken"`
@@ -75,12 +76,11 @@ func adoptionFor(plan catalogue.Resolution, taken []string,
for _, r := range composed.Resources { for _, r := range composed.Resources {
id, _ := r["id"].(string) id, _ := r["id"].(string)
module, owned := composed.Owner[id] module, owned := composed.Owner[id]
if !owned || !runs[module] || isTaken[module] { // Every kind, not only files and containers (novox/hq ADR 0103): a directory, a service, a
continue // container mounting what was found and an action run in a held container all reach what
} // the machine already has. What the mesh declares of its own is never held.
switch r["type"] { if !owned || !runs[module] || isTaken[module] ||
case "file", "container": strings.HasPrefix(id, catalogue.AdoptionPrefix) {
default:
continue continue
} }
if out.Untaken == nil { if out.Untaken == nil {
+4 -2
View File
@@ -84,8 +84,10 @@ func TestAnAdoptedDeclarationCarriesItsModeAndWhatWasTaken(t *testing.T) {
t.Fatal("an adopted node's declaration does not say it is adopted") t.Fatal("an adopted node's declaration does not say it is adopted")
} }
untaken := declared.Adoption.Untaken["hello-web"] untaken := declared.Adoption.Untaken["hello-web"]
if !reflect.DeepEqual(untaken, []string{"hello-web.page", "hello-web.server"}) { // Every kind — its directory too (novox/hq ADR 0103).
t.Fatalf("hello-web's files and containers are not named untaken: %v", declared.Adoption) if !reflect.DeepEqual(untaken, []string{"hello-web.page", "hello-web.server",
"hello-web.served"}) {
t.Fatalf("hello-web's resources are not all named untaken: %v", declared.Adoption)
} }
if len(declared.Adoption.Taken) != 0 { if len(declared.Adoption.Taken) != 0 {
t.Fatalf("nothing was taken, and the declaration says %v", declared.Adoption.Taken) t.Fatalf("nothing was taken, and the declaration says %v", declared.Adoption.Taken)