Skip to content

OpenRAG is a comprehensive, single package Retrieval-Augmented Generation platform built on Langflow, Docling, and Opensearch.

Python

feat: operator namespace watch (#1590)

ming67fbb22aa9af
diff --git a/kubernetes/operator/cmd/main.go b/kubernetes/operator/cmd/main.go
index c834f6aed..8c6a90402 100644
--- a/kubernetes/operator/cmd/main.go
+++ b/kubernetes/operator/cmd/main.go
@@ -3,6 +3,7 @@ package main
import (
"flag"
"os"
+ "strings"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
@@ -11,6 +12,7 @@ import (
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
ctrl "sigs.k8s.io/controller-runtime"
+ "sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
@@ -40,13 +42,28 @@ func main() {
opts.BindFlags(flag.CommandLine)
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))
- mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
+ mgrOptions := ctrl.Options{
Scheme: scheme,
Metrics: metricsserver.Options{BindAddress: cfg.MetricsBindAddress},
HealthProbeBindAddress: cfg.HealthProbeBindAddress,
LeaderElection: cfg.LeaderElectionEnabled,
LeaderElectionID: "openrag-operator.openr.ag",
- })
+ }
+
+ // If WATCH_NAMESPACE is set, configure namespace-scoped watching
+ watchNamespace := strings.TrimSpace(os.Getenv("WATCH_NAMESPACE"))
+ if watchNamespace != "" {
+ setupLog.Info("configuring namespace-scoped watching", "namespace", watchNamespace)
+ // Note: Setting Cache.DefaultNamespaces limits the cache to specific namespaces
+ // This is available in controller-runtime v0.15+
+ mgrOptions.Cache.DefaultNamespaces = map[string]cache.Config{
+ watchNamespace: {},
+ }
+ } else {
+ setupLog.Info("configuring cluster-scoped watching")
+ }
+
+ mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), mgrOptions)
if err != nil {
setupLog.Error(err, "unable to start manager")
os.Exit(1)