layer1: centralize managed namespace labels step 13

This commit is contained in:
Naeel
2026-04-26 10:04:18 +03:00
parent 5e5058ba0e
commit b3f99b2b6c
6 changed files with 52 additions and 23 deletions
+4 -5
View File
@@ -16,11 +16,10 @@ import (
"k8s.io/client-go/kubernetes"
k8sCache "k8s.io/client-go/tools/cache"
"github.com/fission/fission/pkg/utils"
"github.com/fission/fission/pkg/utils/manager"
)
const routerManagedNSLabel = "fission.io/managed"
// StartNSWatcher registers a Kubernetes Namespace Informer for the router.
// Whenever a Namespace with label fission.io/managed=true appears (or is relabeled),
// the router immediately subscribes to HTTPTriggers and Functions in that namespace.
@@ -35,7 +34,7 @@ func StartNSWatcher(
kubeClient,
30*time.Minute,
k8sInformers.WithTweakListOptions(func(opts *metav1.ListOptions) {
opts.LabelSelector = routerManagedNSLabel + "=true"
opts.LabelSelector = utils.ManagedNamespaceLabelSelector()
}),
)
@@ -54,7 +53,7 @@ func StartNSWatcher(
},
UpdateFunc: func(_, newObj interface{}) {
nsObj, ok := newObj.(*corev1.Namespace)
if !ok || nsObj.Labels[routerManagedNSLabel] != "true" {
if !ok || !utils.IsManagedNamespace(nsObj.Labels) {
return
}
if err := ts.AddNamespace(ctx, nsObj.Name, mgr); err != nil {
@@ -66,7 +65,7 @@ func StartNSWatcher(
mgr.Add(ctx, func(ctx context.Context) {
logger.Info("router.NSWatcher: started",
zap.String("label", routerManagedNSLabel+"=true"))
zap.String("label", utils.ManagedNamespaceLabelSelector()))
factory.Start(ctx.Done())
factory.WaitForCacheSync(ctx.Done())
logger.Info("router.NSWatcher: cache synced — watching for new namespaces")