diff --git a/internal/exporter/host/host.go b/internal/exporter/host/host.go index 4ab89d8..b8b9537 100644 --- a/internal/exporter/host/host.go +++ b/internal/exporter/host/host.go @@ -129,7 +129,7 @@ func (e *ExporterHostSyncer) filterExporterInstances(hostName string, exporterIn } // processExporterInstance processes a single exporter instance -func (e *ExporterHostSyncer) processExporterInstance(exporterInstance *api.ExporterInstance, hostSsh ssh.HostManager) error { +func (e *ExporterHostSyncer) processExporterInstance(exporterInstance *api.ExporterInstance, hostSsh ssh.HostManager, renderedHost *api.ExporterHost) error { if isDead, deadAnnotation := isExporterInstanceDead(exporterInstance); isDead { fmt.Printf(" 📟 Exporter instance: %s skipped - dead: %s\n", exporterInstance.Name, deadAnnotation) return nil @@ -149,6 +149,7 @@ func (e *ExporterHostSyncer) processExporterInstance(exporterInstance *api.Expor return fmt.Errorf("service parameters not found for %s", spRef) } et.SetServiceParameters(serviceParameters) + et.SetRenderedExporterHost(renderedHost) _, err = et.RenderTemplateLabels() if err != nil { @@ -241,7 +242,7 @@ func (e *ExporterHostSyncer) processExporterInstancesAndBootc(exporterInstances // Process exporter instances for _, exporterInstance := range exporterInstances { - if err := e.processExporterInstance(exporterInstance, hostSsh); err != nil { + if err := e.processExporterInstance(exporterInstance, hostSsh, renderedHost); err != nil { fmt.Printf(" ❌ Failed to process %s: %v\n", exporterInstance.Name, err) *retryQueue = append(*retryQueue, RetryItem{ ExporterInstance: exporterInstance, @@ -343,7 +344,7 @@ func (e *ExporterHostSyncer) processGlobalRetryQueue(retryQueue []RetryItem) err } } else { // This was an exporter instance failure - if err := e.processExporterInstance(retryItem.ExporterInstance, hostSsh); err != nil { + if err := e.processExporterInstance(retryItem.ExporterInstance, hostSsh, retryItem.RenderedHost); err != nil { fmt.Printf("❌ Retry failed for %s on %s: %v\n", retryItem.ExporterInstance.Name, retryItem.HostName, err) e.addToRetryQueue(&retryItem, err, &nextRetryQueue) } else { diff --git a/internal/exporter/template/exporter_instance.go b/internal/exporter/template/exporter_instance.go index b47298a..75c69c4 100644 --- a/internal/exporter/template/exporter_instance.go +++ b/internal/exporter/template/exporter_instance.go @@ -17,6 +17,7 @@ type ExporterInstanceTemplater struct { exporterInstance *v1alpha1.ExporterInstance exporterConfigTemplate *v1alpha1.ExporterConfigTemplate serviceParameters ServiceParameters + renderedExporterHost *v1alpha1.ExporterHost } func NewExporterInstanceTemplater(cfg *config.Config, exporterInstance *v1alpha1.ExporterInstance) (*ExporterInstanceTemplater, error) { @@ -35,6 +36,10 @@ func (e *ExporterInstanceTemplater) SetServiceParameters(serviceParameters Servi e.serviceParameters = serviceParameters } +func (e *ExporterInstanceTemplater) SetRenderedExporterHost(renderedExporterHost *v1alpha1.ExporterHost) { + e.renderedExporterHost = renderedExporterHost +} + func (s *ServiceParameters) Parameters() *templating.Parameters { parameters := templating.NewParameters("service") parameters.Set("tls_ca", s.TlsCA) @@ -65,6 +70,11 @@ func (e *ExporterInstanceTemplater) renderTemplates() (*v1alpha1.ExporterInstanc templateParametersMap["namespace"] = namespace templateParametersMap["endpoint"] = endpoint templateParametersMap["container_image"] = e.exporterConfigTemplate.Spec.ContainerImage + + // Add ExporterHost addresses if available (managed devices only) + if e.renderedExporterHost != nil && len(e.renderedExporterHost.Spec.Addresses) > 0 { + templateParametersMap["sidekick_address"] = e.renderedExporterHost.Spec.Addresses[0] + } templateParameters := templating.NewParameters("exporter-instance") templateParameters.SetFromMap(templateParametersMap)