review: a unit whose file the mesh wrote is stopped when undeclared, and what was found survives a failed first apply (hq ADR 0118)
Records written before Found existed left the adoption guard and the converge filter loaded on undeclare, then deleted their unit files from under them; a unit whose own file the mesh created is now the mesh's, whatever its record says. Found is kept apart the moment it is read, so a first apply that enabled and then failed is not read back as the machine's; boot is found the first time the mesh sets it; a service once stateless, or moved to another unit, is found afresh (the old unit given back). The unit is read after the reload that loads a file written in the same apply, and removal reports what it actually did.
This commit is contained in:
+28
-7
@@ -19,7 +19,7 @@ import (
|
||||
|
||||
// Step is one thing an apply would do to this machine.
|
||||
type Step struct {
|
||||
// Verb is create · update · check · hold · run · remove · forget · disable · enable.
|
||||
// Verb is create · update · check · hold · run · remove · forget · restore · disable · enable.
|
||||
Verb string `json:"verb"`
|
||||
Type string `json:"type,omitempty"`
|
||||
ID string `json:"id,omitempty"`
|
||||
@@ -77,6 +77,7 @@ func Plan(d *declaration.Declaration, known store.State, origin string) []Step {
|
||||
}
|
||||
|
||||
var protecting, orphans []Step
|
||||
made := meshMadeUnits(known)
|
||||
for _, orphan := range known.Orphans(declared, origin) {
|
||||
step := Step{Verb: "remove", Type: orphan.Type, ID: orphan.ID, Target: orphan.Target,
|
||||
Why: "recorded here and no longer declared"}
|
||||
@@ -84,12 +85,32 @@ func Plan(d *declaration.Declaration, known store.State, origin string) []Step {
|
||||
case orphan.Stateless:
|
||||
step.Verb, step.Why = "forget", "no longer declared; its unit's state was never the mesh's and is left as it is"
|
||||
case orphan.Type == string(declaration.TypeService):
|
||||
// What removal will do, said before it does it (novox/hq ADR 0118): a unit is given
|
||||
// back what the host found, so the preview names which units that stops.
|
||||
if f := orphan.Found; f != nil && (f.State == "stopped" || f.Boot == "disabled") {
|
||||
step.Verb, step.Why = "restore", "no longer declared; the mesh started or enabled it, and it goes back as it was found"
|
||||
} else {
|
||||
step.Verb, step.Why = "forget", "no longer declared; the unit is the machine's and is left as it is"
|
||||
// What removal will do, said before it does it (novox/hq ADR 0118), in removeService's
|
||||
// words. "restore" only where it may stop or disable something — the record cannot say
|
||||
// whether the unit is still as the mesh left it, so "may" is as far as a preview goes —
|
||||
// and a unit whose file the mesh wrote is named as the mesh's, since that one is
|
||||
// stopped whatever was found.
|
||||
f := orphan.Found
|
||||
switch {
|
||||
case made[orphan.Target]:
|
||||
step.Verb, step.Why = "remove", "no longer declared; the mesh wrote its unit file, so it is "+
|
||||
"stopped and disabled at boot before that file goes"
|
||||
case f == nil:
|
||||
step.Verb, step.Why = "forget", "no longer declared; recorded before the host kept what it "+
|
||||
"found, so it is left as it is"
|
||||
case f.State == "stopped" || f.Boot == "disabled":
|
||||
var back []string
|
||||
if f.State == "stopped" {
|
||||
back = append(back, "stopped")
|
||||
}
|
||||
if f.Boot == "disabled" {
|
||||
back = append(back, "disabled at boot")
|
||||
}
|
||||
step.Verb, step.Why = "restore", "no longer declared; the host found it "+
|
||||
strings.Join(back, " and ")+", and it goes back to that if the mesh changed it"
|
||||
default:
|
||||
step.Verb, step.Why = "forget", "no longer declared; it was running before the mesh and is "+
|
||||
"left as it is — nothing is started or stopped on the way out"
|
||||
}
|
||||
}
|
||||
if d.Adoption == nil && strings.HasPrefix(orphan.ID, declaration.AdoptionPrefix) {
|
||||
|
||||
Reference in New Issue
Block a user