From f29a24ba965a1d14990caf58baee25eda4834de0 Mon Sep 17 00:00:00 2001 From: Marco Iorio Date: Tue, 5 May 2026 18:56:25 +0200 Subject: [PATCH] reconciler: append name to job names Respect the reconciler name configured through the [WithName] option when constructing the name of the jobs, to prevent them from conflicting (and consequently have the health scopes conflict) in case of multiple reconcilers inside the same module. Signed-off-by: Marco Iorio --- reconciler/builder.go | 13 +++++++++++-- reconciler/multi_test.go | 10 ++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/reconciler/builder.go b/reconciler/builder.go index 9e94f6a..be706c6 100644 --- a/reconciler/builder.go +++ b/reconciler/builder.go @@ -4,6 +4,7 @@ package reconciler import ( + "fmt" "time" "github.com/cilium/hive/job" @@ -81,9 +82,17 @@ func Register[Obj comparable]( progress: newProgressTracker(), } - params.JobGroup.Add(job.OneShot("reconcile", r.reconcileLoop)) + var scoped = func(jn string) string { + if cfg.Name == "" { + return jn + } + + return fmt.Sprintf("%s-%s", jn, cfg.Name) + } + + params.JobGroup.Add(job.OneShot(scoped("reconcile"), r.reconcileLoop)) if r.config.RefreshInterval > 0 { - params.JobGroup.Add(job.OneShot("refresh", r.refreshLoop)) + params.JobGroup.Add(job.OneShot(scoped("refresh"), r.refreshLoop)) } return r, nil } diff --git a/reconciler/multi_test.go b/reconciler/multi_test.go index 6340973..2e8066f 100644 --- a/reconciler/multi_test.go +++ b/reconciler/multi_test.go @@ -214,6 +214,7 @@ func TestMultipleReconcilersPerModuleMetrics(t *testing.T) { var ops1, ops2 multiMockOps var db *statedb.DB + var health *cell.SimpleHealth metrics := reconciler.NewUnpublishedExpVarMetrics() hive := hive.New( @@ -228,8 +229,8 @@ func TestMultipleReconcilersPerModuleMetrics(t *testing.T) { return r.NewGroup(h) }, ), - cell.Invoke(func(db_ *statedb.DB) (err error) { - db = db_ + cell.Invoke(func(db_ *statedb.DB, h *cell.SimpleHealth) (err error) { + db, health = db_, h table, err = statedb.NewTable(db, "objects", multiStatusIndex) return err }), @@ -306,5 +307,10 @@ func TestMultipleReconcilersPerModuleMetrics(t *testing.T) { assert.Equal(t, "0", metrics.ReconciliationCurrentErrorsVar.Get("test/right").String()) assert.Nil(t, metrics.ReconciliationCountVar.Get("test")) + assert.NotNil(t, health.GetChild("job-reconcile-left")) + assert.NotNil(t, health.GetChild("job-refresh-left")) + assert.NotNil(t, health.GetChild("job-reconcile-right")) + assert.NotNil(t, health.GetChild("job-refresh-right")) + require.NoError(t, hive.Stop(log, context.TODO()), "Stop") }