Repository navigation
Start nspawn workers after reboot on RHEL and recover stopped workers #437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Copilot
wants to merge
13
commits into
main
Choose a base branch
from
copilot/fix-machines-target-issue
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+201
−4
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
72a1624
Initial plan
Copilot 22bd80d
Start machines target with daemon and recover stopped workers
Copilot 695b06b
Remove worker liveness recovery per review
Copilot 69f1cc6
Note planned move of machines target check to Unbounded
Copilot 85ea2de
Handle missing machines target during online preflight
Copilot 098d45b
Rename missing-target preflight flag
Copilot 7689e72
Fail containerized preflight on missing host target
Copilot dc6cf2e
Inline machines target preflight predicate per review
Copilot 6a8f70a
Inline missing-target preflight predicate per review
Copilot aedc842
Name machines target preflight predicate
Copilot fce7d11
Move machines-target changelog entry to Fixed
Copilot 416d340
Warn on unfamiliar machines target states
Copilot f05131a
Merge remote-tracking branch 'origin/main' into copilot/fix-machines-…
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| package daemon | ||
|
bcho marked this conversation as resolved.
Resolved
|
||
|
|
||
| import ( | ||
| "context" | ||
| "log/slog" | ||
| "strings" | ||
|
|
||
| "github.com/Azure/AKSFlexNode/pkg/utils/utilexec" | ||
| "github.com/Azure/unbounded/pkg/agent/preflight" | ||
| ) | ||
|
|
||
| type machinesTargetChecker struct { | ||
| log *slog.Logger | ||
| failForMissing bool | ||
| output func(context.Context, *slog.Logger, string, ...string) (string, error) | ||
| } | ||
|
|
||
| // CheckMachinesTarget checks that systemd can start nspawn workers at boot. | ||
| // TODO: Move this check to Unbounded's host preflight checks. | ||
| func CheckMachinesTarget(log *slog.Logger, failForMissing bool) preflight.Checker { | ||
| return machinesTargetChecker{log: log, failForMissing: failForMissing, output: utilexec.OutputCmd} | ||
| } | ||
|
|
||
| func (machinesTargetChecker) Name() string { return "machines-target" } | ||
|
|
||
| func (c machinesTargetChecker) Check(ctx context.Context) []preflight.Result { | ||
| const target = "machines.target" | ||
| state, err := c.output(ctx, c.log, "systemctl", "show", "--property=UnitFileState", "--value", target) | ||
| if err != nil { | ||
| return preflight.ResultsError(c.Name(), target, "failed to inspect machines.target") | ||
|
bcho marked this conversation as resolved.
Resolved
|
||
| } | ||
| switch strings.TrimSpace(state) { | ||
| case "enabled", "static", "linked": | ||
| return preflight.ResultsOK(c.Name(), target, "machines.target is available for worker startup") | ||
| case "disabled", "enabled-runtime": | ||
| return preflight.ResultsWarning(c.Name(), target, "machines.target is not enabled persistently; bootstrap installs a daemon Wants=machines.target dependency to start workers at boot") | ||
| case "linked-runtime": | ||
| return preflight.ResultsWarning(c.Name(), target, "machines.target is linked only at runtime; make the link persistent for workers to start at boot") | ||
| case "", "not-found": | ||
| if c.failForMissing { | ||
| return preflight.ResultsError(c.Name(), target, "machines.target is missing; install systemd-container on the host before offline or containerized bootstrap") | ||
| } | ||
| return preflight.ResultsWarning(c.Name(), target, "machines.target is missing and may be installed by online bootstrap with systemd-container") | ||
| case "masked", "masked-runtime": | ||
| return preflight.ResultsError(c.Name(), target, "machines.target is masked; unmask it before bootstrap") | ||
| default: | ||
| return preflight.ResultsWarning(c.Name(), target, "machines.target has unrecognized UnitFileState %q; verify that it is available and persistent", strings.TrimSpace(state)) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| package daemon | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "log/slog" | ||
| "slices" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/Azure/unbounded/pkg/agent/preflight" | ||
| ) | ||
|
|
||
| func TestCheckMachinesTarget(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| tests := map[string]struct { | ||
| state string | ||
| err error | ||
| failForMissing bool | ||
| want preflight.Severity | ||
| wantMessage string | ||
| }{ | ||
| "enabled": {state: "enabled\n", want: preflight.SeverityOK}, | ||
| "static": {state: "static", want: preflight.SeverityOK}, | ||
| "linked": {state: "linked", want: preflight.SeverityOK}, | ||
| "disabled": {state: "disabled", want: preflight.SeverityWarning}, | ||
| "runtime only": {state: "enabled-runtime", want: preflight.SeverityWarning}, | ||
| "runtime linked": {state: "linked-runtime", want: preflight.SeverityWarning, wantMessage: "make the link persistent"}, | ||
| "masked": {state: "masked", want: preflight.SeverityError}, | ||
| "runtime masked": {state: "masked-runtime", want: preflight.SeverityError}, | ||
| "masked strict": {state: "masked", failForMissing: true, want: preflight.SeverityError}, | ||
| "runtime masked strict": {state: "masked-runtime", failForMissing: true, want: preflight.SeverityError}, | ||
| "missing online": {want: preflight.SeverityWarning, wantMessage: "may be installed by online bootstrap with systemd-container"}, | ||
| "missing strict": {failForMissing: true, want: preflight.SeverityError, wantMessage: "install systemd-container on the host before offline or containerized bootstrap"}, | ||
| "not found online": {state: "not-found", want: preflight.SeverityWarning}, | ||
| "not found strict": {state: "not-found", failForMissing: true, want: preflight.SeverityError, wantMessage: "install systemd-container on the host before offline or containerized bootstrap"}, | ||
| "unrecognized unit state": {state: "future-state", want: preflight.SeverityWarning, wantMessage: "future-state"}, | ||
| "inspect failure": {err: errors.New("systemd unavailable"), want: preflight.SeverityError}, | ||
| } | ||
| for name, tt := range tests { | ||
| t.Run(name, func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| check := machinesTargetChecker{ | ||
| log: slog.Default(), | ||
| failForMissing: tt.failForMissing, | ||
| output: func(_ context.Context, _ *slog.Logger, command string, args ...string) (string, error) { | ||
| if command != "systemctl" || !slices.Equal(args, []string{"show", "--property=UnitFileState", "--value", "machines.target"}) { | ||
| t.Fatalf("unexpected command: %s %v", command, args) | ||
| } | ||
| return tt.state, tt.err | ||
| }, | ||
| } | ||
| for range 2 { | ||
| results := check.Check(t.Context()) | ||
| if len(results) != 1 || results[0].Severity != tt.want || results[0].Name != "machines-target" { | ||
| t.Fatalf("Check() = %#v, want severity %s", results, tt.want) | ||
| } | ||
| if !strings.Contains(results[0].Message, tt.wantMessage) { | ||
| t.Fatalf("Check() message = %q, want it to include %q", results[0].Message, tt.wantMessage) | ||
| } | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestCheckMachinesTargetBootstrapModes(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| modes := map[string]struct { | ||
| containerized bool | ||
| offline bool | ||
| wantMissing preflight.Severity | ||
| }{ | ||
| "native online": {wantMissing: preflight.SeverityWarning}, | ||
| "native offline": {offline: true, wantMissing: preflight.SeverityError}, | ||
| "containerized online": {containerized: true, wantMissing: preflight.SeverityError}, | ||
| "containerized offline": {containerized: true, offline: true, wantMissing: preflight.SeverityError}, | ||
| } | ||
| for name, mode := range modes { | ||
| t.Run(name, func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| for _, state := range []string{"", "not-found", "masked", "masked-runtime"} { | ||
| t.Run("state="+state, func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| check, ok := CheckMachinesTarget(slog.Default(), mode.containerized || mode.offline).(machinesTargetChecker) | ||
| if !ok { | ||
| t.Fatal("CheckMachinesTarget() returned an unexpected checker type") | ||
| } | ||
| check.output = func(context.Context, *slog.Logger, string, ...string) (string, error) { | ||
| return state, nil | ||
| } | ||
| want := preflight.SeverityError | ||
| if state == "" || state == "not-found" { | ||
| want = mode.wantMissing | ||
| } | ||
| results := check.Check(t.Context()) | ||
| if len(results) != 1 || results[0].Severity != want { | ||
| t.Fatalf("Check() = %#v, want severity %s", results, want) | ||
| } | ||
| if (state == "" || state == "not-found") && want == preflight.SeverityError && | ||
| !strings.Contains(results[0].Message, "install systemd-container on the host") { | ||
| t.Fatalf("Check() message = %q, want host package provisioning guidance", results[0].Message) | ||
| } | ||
| }) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestDaemonUnitsWantMachinesTarget(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| hostUnit, err := renderAgentServiceUnit("/usr/local/bin/aks-flex-node", agentServiceOptions{}) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| for name, content := range map[string][]byte{ | ||
| "host": hostUnit, | ||
| "container": containerServiceUnitContent, | ||
| } { | ||
| t.Run(name, func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| for _, line := range strings.Split(string(content), "\n") { | ||
| if wants, ok := strings.CutPrefix(line, "Wants="); ok && slices.Contains(strings.Fields(wants), "machines.target") { | ||
| return | ||
| } | ||
| } | ||
| t.Fatal("daemon unit must want machines.target so workers start even when the target is disabled") | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.