diff --git a/CHANGELOG.md b/CHANGELOG.md index 1cb599fe433..369afd9b667 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ - Override the vhost on a RabbitMQ scaler via `vhostName` in the metadata. ([#1451](https://github.com/kedacore/keda/pull/1451)) - Optimize Kafka scaler's `getLagForPartition` function. ([#1464](https://github.com/kedacore/keda/pull/1464)) - Reduce unnecessary /scale requests from ScaledObject controller ([#1453](https://github.com/kedacore/keda/pull/1453)) +- Add support for the WATCH_NAMESPACE environment variable to the operator ([#1474](https://github.com/kedacore/keda/pull/1474)) ### Breaking Changes diff --git a/main.go b/main.go index d768fdaeea6..99edd95a0f0 100644 --- a/main.go +++ b/main.go @@ -47,6 +47,16 @@ func init() { // +kubebuilder:scaffold:scheme } +// getWatchNamespace returns the namespace the operator should be watching for changes +func getWatchNamespace() (string, error) { + const WatchNamespaceEnvVar = "WATCH_NAMESPACE" + ns, found := os.LookupEnv(WatchNamespaceEnvVar) + if !found { + return "", fmt.Errorf("%s must be set", WatchNamespaceEnvVar) + } + return ns, nil +} + func main() { var metricsAddr string var enableLeaderElection bool @@ -64,6 +74,12 @@ func main() { ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts))) setupLog := ctrl.Log.WithName("setup") + namespace, err := getWatchNamespace() + if err != nil { + setupLog.Error(err, "failed to get watch namespace") + os.Exit(1) + } + mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{ Scheme: scheme, MetricsBindAddress: metricsAddr, @@ -71,6 +87,7 @@ func main() { Port: 9443, LeaderElection: enableLeaderElection, LeaderElectionID: "operator.keda.sh", + Namespace: namespace, }) if err != nil { setupLog.Error(err, "unable to start manager")