layer1: prepare managed namespace watchers
This commit is contained in:
@@ -109,6 +109,12 @@ func NewWatcherNamespaceManager(ctx context.Context, namespaces []string, source
|
||||
return manager, err
|
||||
}
|
||||
|
||||
func PrepareManagedNamespaceWatcher(ctx context.Context, logger *zap.Logger, component string, namespaces []string, removalStrategy NamespaceRemovalStrategy, subscriber NamespaceSubscriber) (NamespaceManager, k8sCache.ResourceEventHandlerFuncs, error) {
|
||||
manager, err := NewWatcherNamespaceManager(ctx, namespaces, NamespaceSourceEnv, time.Now().UTC(), subscriber)
|
||||
handlers := NewNamespaceWatcherEventHandlers(ctx, logger, component, manager, removalStrategy)
|
||||
return manager, handlers, err
|
||||
}
|
||||
|
||||
func NamespaceBecameUnmanaged(oldNamespace *corev1.Namespace, newNamespace *corev1.Namespace) bool {
|
||||
if oldNamespace == nil || newNamespace == nil {
|
||||
return false
|
||||
|
||||
@@ -429,6 +429,25 @@ func TestNewNamespaceWatcherEventHandlers(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrepareManagedNamespaceWatcher(t *testing.T) {
|
||||
router := &testNamespaceSubscriber{name: "router"}
|
||||
logger := zap.NewNop()
|
||||
manager, handlers, err := PrepareManagedNamespaceWatcher(context.Background(), logger, "router.NSWatcher", []string{"tenant-a"}, NamespaceRemovalStrategyTrackOnly, router)
|
||||
if err != nil {
|
||||
t.Fatalf("expected watcher preparation success: %v", err)
|
||||
}
|
||||
if !reflect.DeepEqual([]string{"tenant-a"}, manager.Snapshot()) {
|
||||
t.Fatalf("expected watcher manager snapshot to contain bootstrapped namespace")
|
||||
}
|
||||
namespace := &corev1.Namespace{}
|
||||
namespace.Name = "tenant-a"
|
||||
namespace.Labels = map[string]string{ManagedNamespaceLabelKey: ManagedNamespaceLabelValue}
|
||||
handlers.UpdateFunc(namespace, namespace)
|
||||
if router.addCalls != 1 || router.resyncCalls != 1 {
|
||||
t.Fatalf("expected bootstrap add and handler resync calls")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNamespaceManagerDispatchAdd(t *testing.T) {
|
||||
manager := NewNamespaceManager()
|
||||
manager.Upsert(NamespaceEvent{Type: NamespaceEventAdd, Name: "tenant-a", Source: NamespaceSourceWatcher})
|
||||
|
||||
Reference in New Issue
Block a user