From 10186ec9ba8c3cb2939c1a22c8961e79461cb720 Mon Sep 17 00:00:00 2001 From: Sanchit2662 Date: Fri, 16 Jan 2026 16:06:06 +0530 Subject: [PATCH] fix: add nil check for sconInfs before ScrapeConfig cleanup Prevents nil pointer dereference when config resource status feature is enabled but ScrapeConfig CRD support is unavailable. Signed-off-by: Sanchit2662 --- pkg/prometheus/server/operator.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/pkg/prometheus/server/operator.go b/pkg/prometheus/server/operator.go index 836fb997b..329695c20 100644 --- a/pkg/prometheus/server/operator.go +++ b/pkg/prometheus/server/operator.go @@ -1116,8 +1116,11 @@ func (c *Operator) updateConfigResourcesStatus(ctx context.Context, p *monitorin // Remove bindings from scrapeConfigs which reference the // workload but aren't selected anymore. - if err := operator.CleanupBindings(ctx, c.sconInfs.ListAll, resources.scrapeConfigs, configResourceSyncer); err != nil { - return fmt.Errorf("failed to remove bindings for scrapeConfigs: %w", err) + // Only cleanup if ScrapeConfig support is enabled (sconInfs is initialized). + if c.sconInfs != nil { + if err := operator.CleanupBindings(ctx, c.sconInfs.ListAll, resources.scrapeConfigs, configResourceSyncer); err != nil { + return fmt.Errorf("failed to remove bindings for scrapeConfigs: %w", err) + } } // Remove bindings from probes which reference the @@ -1153,8 +1156,11 @@ func (c *Operator) configResStatusCleanup(ctx context.Context, p *monitoringv1.P } // Remove bindings from all scrapeConfigs which reference the workload. - if err := operator.CleanupBindings(ctx, c.sconInfs.ListAll, operator.TypedResourcesSelection[*monitoringv1alpha1.ScrapeConfig]{}, configResourceSyncer); err != nil { - return fmt.Errorf("failed to remove bindings for scrapeConfigs: %w", err) + // Only cleanup if ScrapeConfig support is enabled (sconInfs is initialized). + if c.sconInfs != nil { + if err := operator.CleanupBindings(ctx, c.sconInfs.ListAll, operator.TypedResourcesSelection[*monitoringv1alpha1.ScrapeConfig]{}, configResourceSyncer); err != nil { + return fmt.Errorf("failed to remove bindings for scrapeConfigs: %w", err) + } } // Remove bindings from all probes which reference the workload.