diff --git a/cmd/wordpress-operator/main.go b/cmd/wordpress-operator/main.go index 31f6d5ca..d521b2ae 100644 --- a/cmd/wordpress-operator/main.go +++ b/cmd/wordpress-operator/main.go @@ -54,15 +54,21 @@ func main() { os.Exit(genericErrorExitCode) } - // Create a new Cmd to provide shared dependencies and start components - mgr, err := manager.New(cfg, manager.Options{ + opt := manager.Options{ LeaderElection: options.LeaderElection, LeaderElectionID: options.LeaderElectionID, LeaderElectionNamespace: options.LeaderElectionNamespace, LeaderElectionResourceLock: "leases", MetricsBindAddress: options.MetricsBindAddress, HealthProbeBindAddress: options.HealthProbeBindAddress, - }) + } + + if options.ScopedNamespace != "" { + opt.Namespace = options.ScopedNamespace + } + + // Create a new Cmd to provide shared dependencies and start components + mgr, err := manager.New(cfg, opt) if err != nil { setupLog.Error(err, "unable to create a new manager") os.Exit(genericErrorExitCode) diff --git a/pkg/cmd/options/options.go b/pkg/cmd/options/options.go index 5876b867..0abd7e57 100644 --- a/pkg/cmd/options/options.go +++ b/pkg/cmd/options/options.go @@ -51,6 +51,8 @@ var ( // HealthProbeBindAddress is the TCP address that the controller should bind to for serving health probes. HealthProbeBindAddress = ":8081" + + ScopedNamespace = os.Getenv("SCOPED_NAMESPACE") ) func namespace() string {