Carry an adopted node's mode and taken modules in every declaration, from one marshaller (hq ADR 0100)

This commit is contained in:
2026-09-22 17:17:54 +02:00
parent 1c32af6a22
commit a86a6c2974
6 changed files with 357 additions and 49 deletions
+30
View File
@@ -146,6 +146,34 @@ func (r Rendering) machinePort(module string, wanted int) int {
// both call something "config", and without this the second would silently replace the first —
// the node applying one of them and reporting success.
func (r Resolution) Declaration(with Rendering) ([]map[string]any, error) {
composed, err := r.Compose(with)
if err != nil {
return nil, err
}
return composed.Resources, nil
}
// Composed is a declaration's resources and which module each came from.
//
// Owner is kept beside the resources because a resource id cannot be split back into its module:
// a module's name may itself contain a dot. What the mesh adds of its own — an opening, the guard —
// has no owner.
type Composed struct {
Resources []map[string]any
Owner map[string]string
}
// Compose is Declaration with the owner of every resource said.
func (r Resolution) Compose(with Rendering) (Composed, error) {
owner := map[string]string{}
resources, err := r.compose(with, owner)
if err != nil {
return Composed{}, err
}
return Composed{Resources: resources, Owner: owner}, nil
}
func (r Resolution) compose(with Rendering, owner map[string]string) ([]map[string]any, error) {
// Where each provision's credentials land, so a contribution can name the file rather than
// carry a value the mesh does not have.
directories := map[string]string{}
@@ -521,6 +549,7 @@ func (r Resolution) Declaration(with Rendering) ([]map[string]any, error) {
if renamed := reflectsRenamed(m.Module, resource["restart-on"]); renamed != nil {
copied["restart-on"] = renamed
}
owner[fmt.Sprint(copied["id"])] = m.Module
out = append(out, copied)
}
@@ -534,6 +563,7 @@ func (r Resolution) Declaration(with Rendering) ([]map[string]any, error) {
}
for _, fact := range given {
fact["id"] = m.Module + "." + fmt.Sprint(fact["id"])
owner[fmt.Sprint(fact["id"])] = m.Module
out = append(out, fact)
}
}