Files
archie/internal/releaseupdate/topology.go
T

38 lines
1.2 KiB
Go

package releaseupdate
import (
"fmt"
"slices"
)
type Topology struct {
Units []string `json:"units"`
ConfigSections []string `json:"config_sections"`
// Binaries are the release's host binaries that run beside the units
// without a service of their own, such as the archie-agent a Kit run
// mounts from archied's directory. They are installed and switched with
// the units and are never started, stopped or demanded as a unit.
Binaries []string `json:"binaries,omitempty"`
}
// apps returns the binaries the release installs: its units, and the host
// binaries that run beside them without a service.
func (t Topology) apps() []string { return append(slices.Clone(t.Units), t.Binaries...) }
// MigrationPlan preserves the release's dependency order. Unknown observations
// require every step to be checked manually rather than assuming a partial host.
func (t Topology) MigrationPlan(units, sections map[string]bool) []string {
var steps []string
for _, section := range t.ConfigSections {
if !sections[section] {
steps = append(steps, fmt.Sprintf("configure [%s]", section))
}
}
for _, unit := range t.Units {
if !units[unit] {
steps = append(steps, fmt.Sprintf("install and enable %s.service", unit))
}
}
return steps
}