Files
mesh-controller/internal/inventory/chain_links.go
T

35 lines
1.2 KiB
Go

package inventory
import (
"context"
"sort"
"github.com/novox/mesh-controller/internal/chain"
)
// The links of the chain (novox/hq ADR 0408 §1, design 47 acceptance 10, issue 1095): a send that puts a build on a machine
// writes, in the assignment of the module there, the build, what it published, its commit and the rollout that sent it, and
// since when; the rollout lists the assignments it changed with the build before and after (the controller's send, in
// release_plan.go). One read of an assignment then names the commit, the build and the rollout that put it there, and one read
// of the rollout lists its assignments.
// AssignmentsOn are the assignments of a machine as the chain names them, by module: the standing ones, with their links.
func (i *Inventory) AssignmentsOn(ctx context.Context, node string) ([]chain.Assignment, error) {
c, err := i.theChain(ctx)
if err != nil {
return nil, err
}
all, err := c.Assignments.All(ctx)
if err != nil {
return nil, err
}
var out []chain.Assignment
for _, k := range all {
if a := k.Value; a.Node == node && !a.Assigned.IsZero() && a.Stands() {
out = append(out, a)
}
}
sort.Slice(out, func(a, b int) bool { return out[a].Module < out[b].Module })
return out, nil
}