Skip to content

Commit 7c2a54f

Browse files
add a sidekick_address param to managed exporter templates
when we need a reference back to the exporter host address
1 parent adae770 commit 7c2a54f

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

internal/exporter/host/host.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func (e *ExporterHostSyncer) filterExporterInstances(hostName string, exporterIn
129129
}
130130

131131
// processExporterInstance processes a single exporter instance
132-
func (e *ExporterHostSyncer) processExporterInstance(exporterInstance *api.ExporterInstance, hostSsh ssh.HostManager) error {
132+
func (e *ExporterHostSyncer) processExporterInstance(exporterInstance *api.ExporterInstance, hostSsh ssh.HostManager, renderedHost *api.ExporterHost) error {
133133
if isDead, deadAnnotation := isExporterInstanceDead(exporterInstance); isDead {
134134
fmt.Printf(" 📟 Exporter instance: %s skipped - dead: %s\n", exporterInstance.Name, deadAnnotation)
135135
return nil
@@ -149,6 +149,7 @@ func (e *ExporterHostSyncer) processExporterInstance(exporterInstance *api.Expor
149149
return fmt.Errorf("service parameters not found for %s", spRef)
150150
}
151151
et.SetServiceParameters(serviceParameters)
152+
et.SetRenderedExporterHost(renderedHost)
152153

153154
_, err = et.RenderTemplateLabels()
154155
if err != nil {
@@ -241,7 +242,7 @@ func (e *ExporterHostSyncer) processExporterInstancesAndBootc(exporterInstances
241242

242243
// Process exporter instances
243244
for _, exporterInstance := range exporterInstances {
244-
if err := e.processExporterInstance(exporterInstance, hostSsh); err != nil {
245+
if err := e.processExporterInstance(exporterInstance, hostSsh, renderedHost); err != nil {
245246
fmt.Printf(" ❌ Failed to process %s: %v\n", exporterInstance.Name, err)
246247
*retryQueue = append(*retryQueue, RetryItem{
247248
ExporterInstance: exporterInstance,
@@ -343,7 +344,7 @@ func (e *ExporterHostSyncer) processGlobalRetryQueue(retryQueue []RetryItem) err
343344
}
344345
} else {
345346
// This was an exporter instance failure
346-
if err := e.processExporterInstance(retryItem.ExporterInstance, hostSsh); err != nil {
347+
if err := e.processExporterInstance(retryItem.ExporterInstance, hostSsh, retryItem.RenderedHost); err != nil {
347348
fmt.Printf("❌ Retry failed for %s on %s: %v\n", retryItem.ExporterInstance.Name, retryItem.HostName, err)
348349
e.addToRetryQueue(&retryItem, err, &nextRetryQueue)
349350
} else {

internal/exporter/template/exporter_instance.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type ExporterInstanceTemplater struct {
1717
exporterInstance *v1alpha1.ExporterInstance
1818
exporterConfigTemplate *v1alpha1.ExporterConfigTemplate
1919
serviceParameters ServiceParameters
20+
renderedExporterHost *v1alpha1.ExporterHost
2021
}
2122

2223
func NewExporterInstanceTemplater(cfg *config.Config, exporterInstance *v1alpha1.ExporterInstance) (*ExporterInstanceTemplater, error) {
@@ -35,6 +36,10 @@ func (e *ExporterInstanceTemplater) SetServiceParameters(serviceParameters Servi
3536
e.serviceParameters = serviceParameters
3637
}
3738

39+
func (e *ExporterInstanceTemplater) SetRenderedExporterHost(renderedExporterHost *v1alpha1.ExporterHost) {
40+
e.renderedExporterHost = renderedExporterHost
41+
}
42+
3843
func (s *ServiceParameters) Parameters() *templating.Parameters {
3944
parameters := templating.NewParameters("service")
4045
parameters.Set("tls_ca", s.TlsCA)
@@ -65,6 +70,11 @@ func (e *ExporterInstanceTemplater) renderTemplates() (*v1alpha1.ExporterInstanc
6570
templateParametersMap["namespace"] = namespace
6671
templateParametersMap["endpoint"] = endpoint
6772
templateParametersMap["container_image"] = e.exporterConfigTemplate.Spec.ContainerImage
73+
74+
// Add ExporterHost addresses if available (managed devices only)
75+
if e.renderedExporterHost != nil && len(e.renderedExporterHost.Spec.Addresses) > 0 {
76+
templateParametersMap["sidekick_address"] = e.renderedExporterHost.Spec.Addresses[0]
77+
}
6878
templateParameters := templating.NewParameters("exporter-instance")
6979
templateParameters.SetFromMap(templateParametersMap)
7080

0 commit comments

Comments
 (0)