layer1: track namespace removals in manager
This commit is contained in:
@@ -0,0 +1,20 @@
|
|||||||
|
# 2026-04-26 — NamespaceManager rewrite, step 35
|
||||||
|
|
||||||
|
## Цель шага
|
||||||
|
|
||||||
|
Научить watcher-ы фиксировать label-drop/delete в локальном `NamespaceManager`, не трогая реальные runtime регистрации.
|
||||||
|
|
||||||
|
## Что меняем
|
||||||
|
|
||||||
|
1. Во все три namespace watcher-а добавляем:
|
||||||
|
- `DeleteFunc`
|
||||||
|
- обработку `managed -> unmanaged` в `UpdateFunc`
|
||||||
|
2. При таком событии watcher:
|
||||||
|
- создаёт `NamespaceEventRemove`
|
||||||
|
- записывает его в manager через `Upsert()`
|
||||||
|
- пишет явный log, что runtime cleanup НЕ выполняется
|
||||||
|
|
||||||
|
## Что НЕ меняем
|
||||||
|
|
||||||
|
- не вызываем `DispatchRemove()` из watcher-ов;
|
||||||
|
- не удаляем informer-ы, resolver state или runtime registrations.
|
||||||
@@ -58,9 +58,20 @@ func StartNSWatcher(
|
|||||||
zap.String("namespace", nsObj.Name), zap.Error(err))
|
zap.String("namespace", nsObj.Name), zap.Error(err))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
UpdateFunc: func(_, newObj interface{}) {
|
UpdateFunc: func(oldObj, newObj interface{}) {
|
||||||
nsObj, ok := newObj.(*corev1.Namespace)
|
nsObj, ok := newObj.(*corev1.Namespace)
|
||||||
if !ok || !utils.IsManagedNamespace(nsObj.Labels) {
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
oldNSObj, _ := oldObj.(*corev1.Namespace)
|
||||||
|
if oldNSObj != nil && utils.IsManagedNamespace(oldNSObj.Labels) && !utils.IsManagedNamespace(nsObj.Labels) {
|
||||||
|
event := utils.NamespaceEventFromNamespace(utils.NamespaceEventRemove, nsObj, utils.NamespaceSourceWatcher, time.Now().UTC())
|
||||||
|
nsManager.Upsert(event)
|
||||||
|
logger.Info("buildermgr.NSWatcher: namespace removed from manager state; runtime registrations kept",
|
||||||
|
zap.String("namespace", nsObj.Name))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !utils.IsManagedNamespace(nsObj.Labels) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
nsManager.Upsert(utils.NamespaceEventFromNamespace(utils.NamespaceEventUpdate, nsObj, utils.NamespaceSourceWatcher, time.Now().UTC()))
|
nsManager.Upsert(utils.NamespaceEventFromNamespace(utils.NamespaceEventUpdate, nsObj, utils.NamespaceSourceWatcher, time.Now().UTC()))
|
||||||
@@ -69,6 +80,15 @@ func StartNSWatcher(
|
|||||||
zap.String("namespace", nsObj.Name), zap.Error(err))
|
zap.String("namespace", nsObj.Name), zap.Error(err))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
DeleteFunc: func(obj interface{}) {
|
||||||
|
event := utils.NamespaceEventFromObject(utils.NamespaceEventRemove, obj, utils.NamespaceSourceWatcher, time.Now().UTC())
|
||||||
|
if event.Name == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
nsManager.Upsert(event)
|
||||||
|
logger.Info("buildermgr.NSWatcher: namespace deleted from manager state; runtime registrations kept",
|
||||||
|
zap.String("namespace", event.Name))
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
mgr.Add(ctx, func(ctx context.Context) {
|
mgr.Add(ctx, func(ctx context.Context) {
|
||||||
|
|||||||
@@ -127,11 +127,19 @@ func StartNSWatcher(
|
|||||||
},
|
},
|
||||||
// UpdateFunc fires when an existing Namespace is updated — covers the case
|
// UpdateFunc fires when an existing Namespace is updated — covers the case
|
||||||
// where the label is added to a pre-existing Namespace.
|
// where the label is added to a pre-existing Namespace.
|
||||||
UpdateFunc: func(_, newObj interface{}) {
|
UpdateFunc: func(oldObj, newObj interface{}) {
|
||||||
nsObj, ok := newObj.(*corev1.Namespace)
|
nsObj, ok := newObj.(*corev1.Namespace)
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
oldNSObj, _ := oldObj.(*corev1.Namespace)
|
||||||
|
if oldNSObj != nil && utils.IsManagedNamespace(oldNSObj.Labels) && !utils.IsManagedNamespace(nsObj.Labels) {
|
||||||
|
event := utils.NamespaceEventFromNamespace(utils.NamespaceEventRemove, nsObj, utils.NamespaceSourceWatcher, time.Now().UTC())
|
||||||
|
nsManager.Upsert(event)
|
||||||
|
logger.Info("multitenant.NSWatcher: namespace removed from manager state; runtime registrations kept",
|
||||||
|
zap.String("namespace", nsObj.Name))
|
||||||
|
return
|
||||||
|
}
|
||||||
if !utils.IsManagedNamespace(nsObj.Labels) {
|
if !utils.IsManagedNamespace(nsObj.Labels) {
|
||||||
return // label was removed — nothing to do (executor keeps existing registrations)
|
return // label was removed — nothing to do (executor keeps existing registrations)
|
||||||
}
|
}
|
||||||
@@ -141,6 +149,15 @@ func StartNSWatcher(
|
|||||||
zap.String("namespace", nsObj.Name), zap.Error(err))
|
zap.String("namespace", nsObj.Name), zap.Error(err))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
DeleteFunc: func(obj interface{}) {
|
||||||
|
event := utils.NamespaceEventFromObject(utils.NamespaceEventRemove, obj, utils.NamespaceSourceWatcher, time.Now().UTC())
|
||||||
|
if event.Name == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
nsManager.Upsert(event)
|
||||||
|
logger.Info("multitenant.NSWatcher: namespace deleted from manager state; runtime registrations kept",
|
||||||
|
zap.String("namespace", event.Name))
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
mgr.Add(ctx, func(ctx context.Context) {
|
mgr.Add(ctx, func(ctx context.Context) {
|
||||||
|
|||||||
@@ -58,9 +58,20 @@ func StartNSWatcher(
|
|||||||
zap.String("namespace", nsObj.Name), zap.Error(err))
|
zap.String("namespace", nsObj.Name), zap.Error(err))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
UpdateFunc: func(_, newObj interface{}) {
|
UpdateFunc: func(oldObj, newObj interface{}) {
|
||||||
nsObj, ok := newObj.(*corev1.Namespace)
|
nsObj, ok := newObj.(*corev1.Namespace)
|
||||||
if !ok || !utils.IsManagedNamespace(nsObj.Labels) {
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
oldNSObj, _ := oldObj.(*corev1.Namespace)
|
||||||
|
if oldNSObj != nil && utils.IsManagedNamespace(oldNSObj.Labels) && !utils.IsManagedNamespace(nsObj.Labels) {
|
||||||
|
event := utils.NamespaceEventFromNamespace(utils.NamespaceEventRemove, nsObj, utils.NamespaceSourceWatcher, time.Now().UTC())
|
||||||
|
nsManager.Upsert(event)
|
||||||
|
logger.Info("router.NSWatcher: namespace removed from manager state; runtime registrations kept",
|
||||||
|
zap.String("namespace", nsObj.Name))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !utils.IsManagedNamespace(nsObj.Labels) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
nsManager.Upsert(utils.NamespaceEventFromNamespace(utils.NamespaceEventUpdate, nsObj, utils.NamespaceSourceWatcher, time.Now().UTC()))
|
nsManager.Upsert(utils.NamespaceEventFromNamespace(utils.NamespaceEventUpdate, nsObj, utils.NamespaceSourceWatcher, time.Now().UTC()))
|
||||||
@@ -69,6 +80,15 @@ func StartNSWatcher(
|
|||||||
zap.String("namespace", nsObj.Name), zap.Error(err))
|
zap.String("namespace", nsObj.Name), zap.Error(err))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
DeleteFunc: func(obj interface{}) {
|
||||||
|
event := utils.NamespaceEventFromObject(utils.NamespaceEventRemove, obj, utils.NamespaceSourceWatcher, time.Now().UTC())
|
||||||
|
if event.Name == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
nsManager.Upsert(event)
|
||||||
|
logger.Info("router.NSWatcher: namespace deleted from manager state; runtime registrations kept",
|
||||||
|
zap.String("namespace", event.Name))
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
mgr.Add(ctx, func(ctx context.Context) {
|
mgr.Add(ctx, func(ctx context.Context) {
|
||||||
|
|||||||
Reference in New Issue
Block a user