Skip to content
Open
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
20 changes: 14 additions & 6 deletions internal/bootc/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ func (e *HostExecutor) Stage(ctx context.Context, image string) error {
if ctx.Err() != nil {
return ctx.Err()
}
e.copyJournalUnitLogs(log, stageUnitName, cursor)
journalOutput := e.copyJournalUnitLogs(log, stageUnitName, cursor)
if journalOutput != "" {
return fmt.Errorf("running bootc switch: %s: %w", journalOutput, err)
}
Comment thread
alicefr marked this conversation as resolved.
return fmt.Errorf("running bootc switch: %w", err)
}
return nil
Expand Down Expand Up @@ -117,10 +120,10 @@ func (e *HostExecutor) journalCursor() string {
return ""
}

// copyJournalUnitLogs logs recent journal output from the given systemd unit.
// If cursor is non-empty, only entries after that cursor are shown; otherwise
// shows all entries.
func (e *HostExecutor) copyJournalUnitLogs(log logr.Logger, unit string, cursor string) {
// copyJournalUnitLogs logs recent journal output from the given systemd unit
// and returns the raw output. If cursor is non-empty, only entries after that
// cursor are shown; otherwise shows all entries.
func (e *HostExecutor) copyJournalUnitLogs(log logr.Logger, unit string, cursor string) string {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
args := []string{"journalctl", "-o", "cat", "--no-pager",
Expand All @@ -132,13 +135,18 @@ func (e *HostExecutor) copyJournalUnitLogs(log logr.Logger, unit string, cursor
out, err := e.nsenterCmd(ctx, args...).Output()
if err != nil {
log.Error(err, "Failed to read unit journal", "unit", unit)
return
return ""
}
var errLines []string
for _, line := range strings.Split(strings.TrimSpace(string(out)), "\n") {
if line != "" {
log.Info(line, "unit", unit)
if strings.HasPrefix(line, "error:") {
errLines = append(errLines, line)
}
}
}
return strings.Join(errLines, "\n")
}

func (e *HostExecutor) Reboot(ctx context.Context) error {
Expand Down
Loading