Skip to content

Conversation

@michalskrivanek
Copy link
Contributor

@michalskrivanek michalskrivanek commented Oct 11, 2025

when we need a reference back to the exporter host address

Summary by CodeRabbit

  • New Features

    • Exporter instance templates now auto-fill sidekick_address from the associated Exporter Host when available, reducing manual setup.
    • Template rendering now consistently uses the current host context during retries to ensure stable, repeatable outputs.
  • Behavior

    • If the host has no addresses, sidekick_address remains unset to preserve prior behavior.

@coderabbitai
Copy link

coderabbitai bot commented Oct 11, 2025

Walkthrough

Passes a rendered ExporterHost through exporter host processing into the exporter instance templater. Adds a new field and setter on ExporterInstanceTemplater to accept the rendered host, and updates processExporterInstance and its call sites to forward the renderedHost (including retry paths) so templates can use sidekick_address from that host.

Changes

Cohort / File(s) Summary of Changes
Exporter instance templater
internal/exporter/template/exporter_instance.go
Added field renderedExporterHost *v1alpha1.ExporterHost to ExporterInstanceTemplater and a public setter SetRenderedExporterHost. Rendering logic now reads sidekick_address from the provided renderedExporterHost when present instead of deriving it solely from config-loaded data.
Exporter host processing & call sites
internal/exporter/host/host.go
Function signature changed: processExporterInstance(..., hostSsh)processExporterInstance(..., hostSsh, renderedHost). Threaded renderedHost through initial calls and retry logic; calls et.SetRenderedExporterHost(renderedHost) before rendering. Updated retry invocation to pass retryItem.RenderedHost.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    actor Caller
    participant HostSyncer as ExporterHostSyncer
    participant Template as ExporterInstanceTemplater
    participant Retry as RetryLogic

    Caller->>HostSyncer: processExporterInstance(exporterInstance, hostSsh, renderedHost)
    HostSyncer->>Template: New ExporterInstanceTemplater(...)
    HostSyncer->>Template: SetRenderedExporterHost(renderedHost)
    HostSyncer->>Template: Render template (uses renderedExporterHost to set sidekick_address)
    alt render success
        Template-->>HostSyncer: rendered instance
    else render fails
        HostSyncer->>Retry: enqueue retry with RenderedHost
        Retry->>HostSyncer: retry trigger
        HostSyncer->>HostSyncer: processExporterInstance(..., renderedHost from retry)
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

I hop through code with eager paws,
A rendered host I clutch because—
One sidekick address, neatly placed,
Slips into templates, warmly traced.
Carrot cheers for stitched-up flows,
Soft whisker bows where logic goes. 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly and clearly describes the primary change in the pull request, namely adding a sidekick_address parameter to managed exporter templates, without extraneous details or vague wording.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

Comment @coderabbitai help to get the list of available commands and usage tips.

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

🧹 Nitpick comments (2)
internal/exporter/template/exporter_instance.go (2)

69-75: Consider adding a comment explaining the sidekick_address parameter.

The purpose and usage of sidekick_address isn't immediately clear from the code. Adding a brief comment would improve maintainability.

 	// Add ExporterHost addresses if available (managed devices only)
+	// sidekick_address provides the exporter host address back to the managed device
 	if exporterInstanceCopy.Spec.ExporterHostRef.Name != "" {

70-70: ExporterHostRef is a value type—no nil check needed

  • Add a comment explaining why the first address is chosen for sidekick_address.
  • Ensure code passes make lint, make build, and make fmt.
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between adae770 and 81672fc.

📒 Files selected for processing (1)
  • internal/exporter/template/exporter_instance.go (1 hunks)
🧰 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/template/exporter_instance.go
🧬 Code graph analysis (1)
internal/exporter/template/exporter_instance.go (1)
api/v1alpha1/exporterinstance_types.go (1)
  • ExporterHostRef (46-48)
🔇 Additional comments (2)
internal/exporter/template/exporter_instance.go (2)

68-75: Reminder: Run linting and build checks before merging.

As per coding guidelines, ensure you run:

  • make lint to check for linting errors
  • make build to verify the binary compiles
  • make fmt to format the code

Based on coding guidelines.


68-75: The overall implementation looks solid.

The logic correctly handles:

  • Optional ExporterHostRef (silently skips when not set)
  • Missing or invalid host reference (using ok pattern)
  • Empty addresses array (defensive length check)

This is appropriate behavior for an optional feature that applies only to managed devices.

when we need a reference back to the exporter host address
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

🧹 Nitpick comments (1)
internal/exporter/template/exporter_instance.go (1)

73-77: Consider documenting the first-address selection.

The logic correctly checks for nil and non-empty addresses before setting sidekick_address. However, consider adding a brief inline comment explaining why the first address (Spec.Addresses[0]) is selected when multiple addresses might exist.

Example addition:

 	// Add ExporterHost addresses if available (managed devices only)
 	if e.renderedExporterHost != nil && len(e.renderedExporterHost.Spec.Addresses) > 0 {
+		// Use the first address as the primary sidekick address
 		templateParametersMap["sidekick_address"] = e.renderedExporterHost.Spec.Addresses[0]
 	}

Note: This parameter will override any manually-set sidekick_address in ConfigTemplateRef.Parameters, which is likely intentional for managed devices.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 81672fc and 7c2a54f.

📒 Files selected for processing (2)
  • internal/exporter/host/host.go (4 hunks)
  • internal/exporter/template/exporter_instance.go (3 hunks)
🧰 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/template/exporter_instance.go
  • internal/exporter/host/host.go
🧬 Code graph analysis (2)
internal/exporter/template/exporter_instance.go (1)
api/v1alpha1/exporterhost_types.go (1)
  • ExporterHost (102-108)
internal/exporter/host/host.go (3)
api/v1alpha1/exporterinstance_types.go (1)
  • ExporterInstance (71-77)
internal/exporter/ssh/ssh.go (1)
  • HostManager (37-46)
api/v1alpha1/exporterhost_types.go (1)
  • ExporterHost (102-108)
🔇 Additional comments (7)
internal/exporter/template/exporter_instance.go (2)

20-20: LGTM! New field properly typed.

The renderedExporterHost field is correctly typed as a pointer to support nil values when not dealing with managed devices.


39-41: LGTM! Setter follows established patterns.

The SetRenderedExporterHost method follows the same pattern as SetServiceParameters and appropriately accepts nil values.

internal/exporter/host/host.go (5)

132-132: LGTM! Signature correctly extended.

The processExporterInstance method signature properly adds the renderedHost parameter to enable template access to host information.


152-152: LGTM! Rendered host correctly propagated to templater.

The rendered host is set on the templater after service parameters, ensuring templates have access to the host context during rendering.


245-245: LGTM! Initial processing correctly passes rendered host.

The call site in the initial processing loop properly passes the renderedHost parameter.


347-347: LGTM! Retry logic maintains host context.

The retry logic correctly uses retryItem.RenderedHost to ensure retries operate with the same host context as the initial attempt.


1-433: Verify Go formatting, linting, and build

Execute make fmt, make lint, and make build (or locally go fmt ./…, golangci-lint run ./…, go build ./…) and resolve any errors before merging.

@michalskrivanek
Copy link
Contributor Author

too ugly

@michalskrivanek michalskrivanek deleted the exporter-host branch October 11, 2025 13:06
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