layer1: add namespace manager bridge step 12
This commit is contained in:
@@ -0,0 +1,17 @@
|
|||||||
|
# 2026-04-26 — NamespaceManager rewrite, step 12
|
||||||
|
|
||||||
|
## Цель шага
|
||||||
|
|
||||||
|
Добавить bridge helper между legacy `NamespaceResolver` и новым `NamespaceManager`.
|
||||||
|
|
||||||
|
## Что меняем
|
||||||
|
|
||||||
|
1. Добавляем helper `NewBootstrappedNamespaceManager()`.
|
||||||
|
2. Helper берёт snapshot из resolver и bootstraps manager.
|
||||||
|
3. Добавляем unit test на bootstrap from resolver.
|
||||||
|
|
||||||
|
## Что НЕ меняем
|
||||||
|
|
||||||
|
- не подключаем helper к production startup path;
|
||||||
|
- не меняем watcher-ы;
|
||||||
|
- не меняем runtime components.
|
||||||
@@ -35,6 +35,15 @@ func NewNamespaceManager() NamespaceManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewBootstrappedNamespaceManager(resolver *NamespaceResolver, source NamespaceSource, observedAt time.Time) NamespaceManager {
|
||||||
|
manager := NewNamespaceManager()
|
||||||
|
if resolver == nil {
|
||||||
|
return manager
|
||||||
|
}
|
||||||
|
manager.Bootstrap(resolver.Snapshot(), source, observedAt)
|
||||||
|
return manager
|
||||||
|
}
|
||||||
|
|
||||||
func (m *inMemoryNamespaceManager) Subscribe(subscriber NamespaceSubscriber) {
|
func (m *inMemoryNamespaceManager) Subscribe(subscriber NamespaceSubscriber) {
|
||||||
m.mu.Lock()
|
m.mu.Lock()
|
||||||
defer m.mu.Unlock()
|
defer m.mu.Unlock()
|
||||||
|
|||||||
@@ -157,4 +157,25 @@ func TestNamespaceManagerBootstrap(t *testing.T) {
|
|||||||
if record.Source != NamespaceSourceBackfill {
|
if record.Source != NamespaceSourceBackfill {
|
||||||
t.Fatalf("expected bootstrap source backfill, got %s", record.Source)
|
t.Fatalf("expected bootstrap source backfill, got %s", record.Source)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNewBootstrappedNamespaceManager(t *testing.T) {
|
||||||
|
resolver := &NamespaceResolver{
|
||||||
|
FissionResourceNS: map[string]string{
|
||||||
|
"tenant-b": "tenant-b",
|
||||||
|
"tenant-a": "tenant-a",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
manager := NewBootstrappedNamespaceManager(resolver, NamespaceSourceEnv, time.Now().UTC())
|
||||||
|
if !reflect.DeepEqual([]string{"tenant-a", "tenant-b"}, manager.Snapshot()) {
|
||||||
|
t.Fatalf("expected bootstrapped manager snapshot from resolver")
|
||||||
|
}
|
||||||
|
record, ok := manager.Get("tenant-a")
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("expected tenant-a in bootstrapped manager")
|
||||||
|
}
|
||||||
|
if record.Source != NamespaceSourceEnv {
|
||||||
|
t.Fatalf("expected env source, got %s", record.Source)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user