Skip to content

Commit

Permalink
Update operator to support the WATCH_NAMESPACE env var (kedacore#1474)
Browse files Browse the repository at this point in the history
* add support to the operator for the WATCH_NAMESPACE env var

Signed-off-by: Colton Herinckx <herinckc@gmail.com>

* update the changelog

Signed-off-by: Colton Herinckx <herinckc@gmail.com>

* address PR comments - add PR number and link to changelog

Signed-off-by: Colton Herinckx <herinckc@gmail.com>
  • Loading branch information
herinckc authored and ycabrer committed Mar 1, 2021
1 parent e2982f4 commit dbc6802
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -64,13 +74,20 @@ 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,
HealthProbeBindAddress: ":8081",
Port: 9443,
LeaderElection: enableLeaderElection,
LeaderElectionID: "operator.keda.sh",
Namespace: namespace,
})
if err != nil {
setupLog.Error(err, "unable to start manager")
Expand Down

0 comments on commit dbc6802

Please sign in to comment.