Skip to content

Commit 0c11c45

Browse files
authored
fix: add reports informer to ensure correct metrics (#1592)
1 parent fdc5cc3 commit 0c11c45

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

internal/controller/stas/scan_job_controller.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"slices"
99
"strings"
1010

11-
openreportsv1alpha1 "github.com/openreports/reports-api/apis/openreports.io/v1alpha1"
1211
batchv1 "k8s.io/api/batch/v1"
1312
corev1 "k8s.io/api/core/v1"
1413
eventsv1 "k8s.io/api/events/v1"
@@ -66,8 +65,7 @@ func (r *ScanJobReconciler) SetupWithManager(mgr ctrl.Manager) error {
6665
inNamespacePredicate(r.ScanJobNamespace),
6766
jobIsFinished,
6867
ignoreDeletionPredicate(),
69-
)).
70-
Watches(&openreportsv1alpha1.Report{}, handler.Funcs{}). // Watches reports with empty handler to ensure informer creation for metrics collection
68+
)).
7169
Complete(r.reconcile())
7270
if err != nil {
7371
return err

internal/operator/operator.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,14 @@ func (o Operator) Start(cfg config.Config) error {
262262
return fmt.Errorf("unable to set up ready check: %w", err)
263263
}
264264

265+
ctx := ctrl.SetupSignalHandler()
266+
267+
// We need to create an informer for reports to ensure all reports are available in cache to
268+
// serve custom image scanner metrics.
269+
if _, err := mgr.GetCache().GetInformer(ctx, &openreportsv1alpha1.Report{}); err != nil {
270+
return fmt.Errorf("failed to create reports informer: %w", err)
271+
}
272+
265273
if err = (&metrics.ImageMetricsCollector{
266274
Reader: mgr.GetCache(),
267275
Config: cfg,
@@ -272,7 +280,7 @@ func (o Operator) Start(cfg config.Config) error {
272280

273281
ctrl.Log.Info("starting manager")
274282

275-
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
283+
if err := mgr.Start(ctx); err != nil {
276284
return fmt.Errorf("problem running manager: %w", err)
277285
}
278286

0 commit comments

Comments
 (0)