layer1: hook executor watcher to namespace manager
This commit is contained in:
@@ -93,6 +93,9 @@ func StartNSWatcher(
|
||||
executorTypes map[fv1.ExecutorType]executortype.ExecutorType,
|
||||
mgr manager.Interface,
|
||||
) {
|
||||
nsManager := utils.NewBootstrappedNamespaceManager(utils.DefaultNSResolver(), utils.NamespaceSourceEnv, time.Now().UTC())
|
||||
nsManager.Subscribe(NewNamespaceSubscriber(logger, kubernetesClient, executorTypes, mgr))
|
||||
|
||||
// Use a label-filtered informer so only Namespaces with our label are delivered.
|
||||
// The resync period of 30m is standard for Fission informers — it re-lists to recover
|
||||
// from any missed events, but normal operation is purely event-driven (no ticking).
|
||||
@@ -109,11 +112,15 @@ func StartNSWatcher(
|
||||
_, _ = nsInformer.AddEventHandler(k8sCache.ResourceEventHandlerFuncs{
|
||||
// AddFunc fires when a new Namespace with the label appears.
|
||||
AddFunc: func(obj interface{}) {
|
||||
ns := namespaceName(obj)
|
||||
if ns == "" {
|
||||
nsObj, ok := obj.(*corev1.Namespace)
|
||||
if !ok || nsObj.Name == "" {
|
||||
return
|
||||
}
|
||||
registerNamespace(ctx, logger, kubernetesClient, ns, executorTypes, mgr)
|
||||
nsManager.Upsert(utils.NamespaceEventFromNamespace(utils.NamespaceEventAdd, nsObj, utils.NamespaceSourceWatcher, time.Now().UTC()))
|
||||
if _, _, err := nsManager.DispatchAdd(ctx, nsObj.Name); err != nil {
|
||||
logger.Error("multitenant.NSWatcher: DispatchAdd failed",
|
||||
zap.String("namespace", nsObj.Name), zap.Error(err))
|
||||
}
|
||||
},
|
||||
// UpdateFunc fires when an existing Namespace is updated — covers the case
|
||||
// where the label is added to a pre-existing Namespace.
|
||||
@@ -125,7 +132,11 @@ func StartNSWatcher(
|
||||
if !utils.IsManagedNamespace(nsObj.Labels) {
|
||||
return // label was removed — nothing to do (executor keeps existing registrations)
|
||||
}
|
||||
registerNamespace(ctx, logger, kubernetesClient, nsObj.Name, executorTypes, mgr)
|
||||
nsManager.Upsert(utils.NamespaceEventFromNamespace(utils.NamespaceEventUpdate, nsObj, utils.NamespaceSourceWatcher, time.Now().UTC()))
|
||||
if _, _, err := nsManager.DispatchResync(ctx, nsObj.Name); err != nil {
|
||||
logger.Error("multitenant.NSWatcher: DispatchResync failed",
|
||||
zap.String("namespace", nsObj.Name), zap.Error(err))
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user