layer1: share namespace watcher event handlers

This commit is contained in:
Naeel
2026-04-26 10:50:28 +03:00
parent c3b161da83
commit 49be1db3a0
6 changed files with 65 additions and 57 deletions
+23
View File
@@ -406,6 +406,29 @@ func TestHandleWatcherNamespaceUpdateDispatchRemoval(t *testing.T) {
}
}
func TestNewNamespaceWatcherEventHandlers(t *testing.T) {
manager := NewNamespaceManager()
router := &testNamespaceSubscriber{name: "router"}
manager.Subscribe(router)
logger := zap.NewNop()
handlers := NewNamespaceWatcherEventHandlers(context.Background(), logger, "router.NSWatcher", manager, NamespaceRemovalStrategyTrackOnly)
namespace := &corev1.Namespace{}
namespace.Name = "tenant-a"
namespace.Labels = map[string]string{ManagedNamespaceLabelKey: ManagedNamespaceLabelValue}
handlers.AddFunc(namespace)
handlers.UpdateFunc(namespace, namespace)
handlers.DeleteFunc(k8sCache.DeletedFinalStateUnknown{Obj: namespace})
record, ok := manager.Get("tenant-a")
if !ok || record.Phase != NamespacePhaseRemoved {
t.Fatalf("expected watcher event handlers to drive namespace lifecycle")
}
if router.addCalls != 1 || router.resyncCalls != 1 {
t.Fatalf("expected add and resync calls through event handlers")
}
}
func TestNamespaceManagerDispatchAdd(t *testing.T) {
manager := NewNamespaceManager()
manager.Upsert(NamespaceEvent{Type: NamespaceEventAdd, Name: "tenant-a", Source: NamespaceSourceWatcher})