diff --git a/cmd/bbr/runner/runner.go b/cmd/bbr/runner/runner.go index 6f26043d55..18a0d19f75 100644 --- a/cmd/bbr/runner/runner.go +++ b/cmd/bbr/runner/runner.go @@ -20,6 +20,7 @@ import ( "context" "flag" "fmt" + "os" uberzap "go.uber.org/zap" "go.uber.org/zap/zapcore" @@ -106,18 +107,24 @@ func (r *Runner) Run(ctx context.Context) error { } // label "inference-gateway.k8s.io/managed" = "true" is used for server-side filtering of configmaps. // only the configmap objects with this label will be tracked by bbr. - mgr, err := ctrl.NewManager(cfg, ctrl.Options{ - Cache: cache.Options{ - ByObject: map[client.Object]cache.ByObject{ - &corev1.ConfigMap{}: { - Label: labels.SelectorFromSet(labels.Set{ - "inference-gateway.k8s.io/managed": "true", - }), - }, + cacheOptions := cache.Options{ + ByObject: map[client.Object]cache.ByObject{ + &corev1.ConfigMap{}: { + Label: labels.SelectorFromSet(labels.Set{ + "inference-gateway.k8s.io/managed": "true", + }), }, }, - Metrics: metricsServerOptions, - }) + } + // Apply namespace filtering only if env var is set + namespace := os.Getenv("NAMESPACE") + if namespace != "" { + cacheOptions.DefaultNamespaces = map[string]cache.Config{ + namespace: {}, + } + } + + mgr, err := ctrl.NewManager(cfg, ctrl.Options{Cache: cacheOptions, Metrics: metricsServerOptions}) if err != nil { setupLog.Error(err, "Failed to create manager", "config", cfg) return err diff --git a/config/charts/body-based-routing/templates/bbr.yaml b/config/charts/body-based-routing/templates/bbr.yaml index 155a376518..e88f4235c9 100644 --- a/config/charts/body-based-routing/templates/bbr.yaml +++ b/config/charts/body-based-routing/templates/bbr.yaml @@ -25,6 +25,13 @@ spec: - --{{ $key }} - "{{ $value }}" {{- end }} + {{- if not .Values.bbr.multiNamespace }} + env: + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + {{- end }} ports: - containerPort: {{ .Values.bbr.port }} # health check