Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions platform/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,19 @@ func NewMachines(c Cluster, userdata *conf.UserData, n int) ([]Machine, error) {
return machs, nil
}

// systemRunningState classifies `systemctl is-system-running` output. keep
// is true while still on the way to "running"; anything else, including
// empty output, means stop retrying.
Comment on lines +344 to +346

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep=true doesn't actually mean retries continue. util.Retry stops on any nil return, which happens both when keep=false and when keep=true with state=="running" (success case). Retries only continue when keep=true and err != nil.

func systemRunningState(raw []byte) (state string, keep bool) {
state = strings.TrimSpace(string(raw))
switch state {
case "initializing", "starting", "running", "stopping":
return state, true
default:
return state, false
}
}

// CheckMachine tests a machine for various error conditions such as ssh
// being available and no systemd units failing at the time ssh is reachable.
// It also ensures the remote system is running Flatcar Container Linux.
Expand All @@ -353,11 +366,12 @@ func CheckMachine(ctx context.Context, m Machine) error {
return err
}
out, stderr, err := m.SSH("systemctl is-system-running")
if !bytes.Contains([]byte("initializing starting running stopping"), out) {
state, keep := systemRunningState(out)
if !keep {
return nil // stop retrying if the system went haywire, e.g., "degraded"
}
jobs := ""
if bytes.Contains([]byte("starting"), out) {
if state == "starting" {
startingOut, startingStderr, startingErr := m.SSH("systemctl list-jobs")
jobs = fmt.Sprintf(", systemctl list-jobs returned stdout: %q, stderr: %q, err: %v", startingOut, startingStderr, startingErr)
}
Expand Down
48 changes: 48 additions & 0 deletions platform/platform_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2026 The Flatcar Maintainers.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package platform

import "testing"

func TestSystemRunningState(t *testing.T) {
tests := []struct {
name string
raw string
wantState string
wantKeep bool
}{
{"running", "running", "running", true},
{"running with trailing newline", "running\n", "running", true},
{"initializing", "initializing", "initializing", true},
{"starting", "starting", "starting", true},
{"stopping", "stopping", "stopping", true},
{"degraded", "degraded", "degraded", false},
{"maintenance", "maintenance", "maintenance", false},
{"offline", "offline", "offline", false},
// A blank/empty SSH response (e.g. a transient connection hiccup)
// must not be mistaken for an in-progress state.
{"empty output", "", "", false},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotState, gotKeep := systemRunningState([]byte(tt.raw))
if gotState != tt.wantState || gotKeep != tt.wantKeep {
t.Errorf("systemRunningState(%q) = (%q, %v), want (%q, %v)",
tt.raw, gotState, gotKeep, tt.wantState, tt.wantKeep)
}
})
}
}