Skip to content

Handle bootc last, and always apply configuration changes#17

Merged
mangelajo merged 1 commit intomainfrom
bootc-order
Sep 5, 2025
Merged

Handle bootc last, and always apply configuration changes#17
mangelajo merged 1 commit intomainfrom
bootc-order

Conversation

@mangelajo
Copy link
Member

@mangelajo mangelajo commented Sep 5, 2025

  • Moves bootc handling into the ssh module, since a different module/manager like flightctl would do things differently than what we do via SSH

  • Apply bootc changes at the end, after configuration changes and services have been handled on the exporter hosts

  • If bootc update is in progress don't restart services, since that will happen naturally on the host after bootc reboot, and it means too much pressure for some sidekicks.

Summary by CodeRabbit

  • New Features
    • Bootc upgrade awareness: view status (up-to-date, updating, will update, not managed) per host.
    • Ability to trigger bootc upgrades from the workflow, with clear dry-run messaging.
  • Improvements
    • Safer operations: exporter restarts/updates are skipped while a bootc upgrade is in progress.
    • More reliable retries: separate retry paths for bootc upgrades vs exporter instances.
    • Clearer logs and status messages distinguishing bootc upgrade actions from exporter processing.

@coderabbitai
Copy link

coderabbitai bot commented Sep 5, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Refactors bootc upgrade handling into per-host processing, integrates it with the global retry flow, and extends the SSH HostManager interface with bootc-aware methods. Adds a retry helper, replaces a processing function, removes a pre-check function, and updates apply logic to respect bootc upgrade status. Notes potential duplicate method blocks in ssh.go.

Changes

Cohort / File(s) Summary
Host processing and retries
internal/exporter/host/host.go
Replaced processExporterInstances with processExporterInstancesAndBootc; added addToRetryQueue; removed handleBootcUpgrade; integrated bootc upgrade attempts via hostSsh.HandleBootcUpgrade into per-host flow; expanded global retry logic to differentiate nil vs non-nil ExporterInstance items; updated logging and error handling accordingly.
SSH HostManager bootc integration
internal/exporter/ssh/ssh.go
Added exported BootcStatus enum and constants; extended HostManager with GetBootcStatus() and HandleBootcUpgrade(dryRun bool); implemented both on SSHHostManager; modified Apply to skip restarts/updates when bootc is updating; added status detection via systemd and bootc checks; added upgrade triggering via systemctl; note: duplicate insertions of the new methods appear in the file.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Sync as SyncExporterHosts
  participant Host as processExporterInstancesAndBootc
  participant SSH as HostManager (SSH)
  participant Retry as Global Retry Loop

  Sync->>Host: For each host: process(exporterInstances, hostSsh, hostName, retryQueue)
  Host->>SSH: GetBootcStatus()
  alt Bootc WILL_UPDATE
    Host->>SSH: HandleBootcUpgrade(dryRun=false)
    alt Error triggering upgrade
      Host->>Host: enqueue RetryItem{ExporterInstance=nil}
    end
  else Bootc UPDATING
    Note over Host: Skip exporter restarts/updates due to active upgrade
  end
  Host->>Host: Process non-nil exporter instances (apply/update)

  loop For each retry item
    Retry->>Retry: Check item.ExporterInstance
    alt item.ExporterInstance == nil (bootc)
      Retry->>SSH: HandleBootcUpgrade(dryRun=false)
      alt Error persists
        Retry->>Retry: Re-enqueue (increment attempts)
      end
    else Exporter instance retry
      Retry->>Host: process exporter instance
      alt Error persists
        Retry->>Retry: Re-enqueue (increment attempts)
      end
    end
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

A rabbit taps the keys with glee,
Bootc checks now per-host, you see.
Retries sorted, nil or not,
Timers tick, upgrades caught.
SSH whispers, “All up to date!”
Carrot logs confirm the state. 🥕✨


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 931c1f3 and a9e6222.

📒 Files selected for processing (2)
  • internal/exporter/host/host.go (4 hunks)
  • internal/exporter/ssh/ssh.go (3 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch bootc-order

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Comment on lines 391 to 397
func TestBootcStatusConstants(t *testing.T) {
// Test that all BootcStatus constants are defined correctly
assert.Equal(t, BootcStatus(0), BOOTC_UP_TO_DATE)
assert.Equal(t, BootcStatus(1), BOOTC_UPDATING)
assert.Equal(t, BootcStatus(2), BOOTC_WILL_UPDATE)
assert.Equal(t, BootcStatus(3), BOOTC_NOT_MANAGED)
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Worst test ever, will remove

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
internal/exporter/host/host.go (2)

238-241: Fix nil deref when max attempts exceeded for bootc retry items

retryItem.ExporterInstance can be nil for bootc entries, causing a panic here. Handle both cases.

-				fmt.Printf("💀 Max retry attempts exceeded for %s on %s, giving up: %v\n",
-					retryItem.ExporterInstance.Name, retryItem.HostName, retryItem.LastError)
-				finalErrors = append(finalErrors, fmt.Sprintf("%s on %s: %v", retryItem.ExporterInstance.Name, retryItem.HostName, retryItem.LastError))
-				continue
+				if retryItem.ExporterInstance == nil {
+					fmt.Printf("💀 Max retry attempts exceeded for bootc upgrade on %s, giving up: %v\n",
+						retryItem.HostName, retryItem.LastError)
+					finalErrors = append(finalErrors, fmt.Sprintf("bootc upgrade on %s: %v", retryItem.HostName, retryItem.LastError))
+				} else {
+					fmt.Printf("💀 Max retry attempts exceeded for %s on %s, giving up: %v\n",
+						retryItem.ExporterInstance.Name, retryItem.HostName, retryItem.LastError)
+					finalErrors = append(finalErrors, fmt.Sprintf("%s on %s: %v", retryItem.ExporterInstance.Name, retryItem.HostName, retryItem.LastError))
+				}
+				continue

329-332: Bootc never runs when a host has zero exporter instances

Early-continue skips bootc and host-level template apply, contradicting “always apply configuration changes” and “handle bootc last.” Remove the guard and let processExporterInstancesAndBootc run even with an empty slice.

-		// Skip the host if no viable exporter instances remain
-		if len(exporterInstances) == 0 {
-			continue
-		}

Note: processExporterInstancesAndBootc safely ranges over a nil slice and still performs bootc handling.

🧹 Nitpick comments (4)
internal/exporter/host/host.go (4)

187-194: Avoid address-of-range variable; pass RetryItem by value

Taking &retryItem where retryItem is the range variable is a classic Go pitfall. Make the helper take a value and append it.

-// addToRetryQueue increments attempts and adds a retry item to the next retry queue
-func (e *ExporterHostSyncer) addToRetryQueue(retryItem *RetryItem, err error, nextRetryQueue *[]RetryItem) {
-	retryItem.Attempts++
-	retryItem.LastError = err
-	retryItem.LastAttemptTime = time.Now()
-	*nextRetryQueue = append(*nextRetryQueue, *retryItem)
-}
+// addToRetryQueue increments attempts and adds a retry item to the next retry queue
+func (e *ExporterHostSyncer) addToRetryQueue(retryItem RetryItem, err error, nextRetryQueue *[]RetryItem) {
+	retryItem.Attempts++
+	retryItem.LastError = err
+	retryItem.LastAttemptTime = time.Now()
+	*nextRetryQueue = append(*nextRetryQueue, retryItem)
+}

259-267: Update helper call to pass value (bootc branch)

Align with the safer addToRetryQueue signature.

-					e.addToRetryQueue(&retryItem, err, &nextRetryQueue)
+					e.addToRetryQueue(retryItem, err, &nextRetryQueue)

269-278: Update helper call to pass value (instance branch)

Align with the safer addToRetryQueue signature.

-					e.addToRetryQueue(&retryItem, err, &nextRetryQueue)
+					e.addToRetryQueue(retryItem, err, &nextRetryQueue)

360-360: Wording nit: queue contains bootc items too

Message says “failed instances” but queue may have bootc entries.

-		fmt.Printf("\n🔄 Processing retry queue (%d failed instances) ===========================\n", len(retryQueue))
+		fmt.Printf("\n🔄 Processing retry queue (%d failed items) ===========================\n", len(retryQueue))
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 6d9ce80 and 8a7ea44.

📒 Files selected for processing (2)
  • internal/exporter/host/host.go (4 hunks)
  • internal/exporter/ssh/ssh.go (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/exporter/ssh/ssh.go
🧰 Additional context used
📓 Path-based instructions (1)
**/*.go

📄 CodeRabbit inference engine (.cursorrules)

**/*.go: Run golangci-lint via make lint and fix all linting errors before proceeding
Run make build to ensure the binary compiles successfully and fix any build errors
Run make fmt to ensure code formatting (go fmt) before finalizing changes

Files:

  • internal/exporter/host/host.go
🧬 Code graph analysis (1)
internal/exporter/host/host.go (2)
api/v1alpha1/exporterinstance_types.go (1)
  • ExporterInstance (71-77)
internal/exporter/ssh/ssh.go (1)
  • HostManager (32-40)
🔇 Additional comments (2)
internal/exporter/host/host.go (2)

195-224: Bootc-after-instances flow looks good

Bootc is handled after instance processing and enqueued for retries distinctly. Nice separation.


355-356: Ready after CI verification
No stale callers of processExporterInstances remain; please confirm build, vet, test, and lint all pass before merging.

* Moves bootc handling into the ssh module, since a different module/manager
  like flightctl would do things differently than what we do via SSH

* Apply bootc changes at the end, after configuration changes and services
  have been handled on the exporter hosts

* If bootc update is in progress don't restart services, since that will
  happen naturally on the host after bootc reboot, and it means too much
  pressure for some sidekicks.
@mangelajo mangelajo merged commit 753eb2d into main Sep 5, 2025
3 checks passed
@mangelajo mangelajo deleted the bootc-order branch September 5, 2025 13:41
@coderabbitai coderabbitai bot mentioned this pull request Sep 8, 2025
@coderabbitai coderabbitai bot mentioned this pull request Oct 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant