Skip to content

Commit

Permalink
cmd/main: add back the --namespace flag
Browse files Browse the repository at this point in the history
  • Loading branch information
dethi committed Apr 11, 2024
1 parent 81d917c commit 4138e05
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,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"
Expand All @@ -49,17 +50,21 @@ func init() {
}

func main() {
var metricsAddr string
var pprofAddr string
var enableLeaderElection bool
var probeAddr string
var zkQuorum string
var (
metricsAddr string
pprofAddr string
enableLeaderElection bool
probeAddr string
namespace string
zkQuorum string
)
flag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&pprofAddr, "pprof-addr", ":6060", "The address the pprof endpoint binds to.")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
flag.StringVar(&namespace, "namespace", "hbase", "The namespace to watch for resource definitions.")
flag.StringVar(&zkQuorum, "zkquorum", "localhost:2181",
"Comma-separated list of zookeeper addresses.")

Expand All @@ -71,8 +76,18 @@ func main() {

ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))

var watchNamespaces map[string]cache.Config
if namespace != "" {
watchNamespaces = map[string]cache.Config{
namespace: {},
}
}

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
Cache: cache.Options{
DefaultNamespaces: watchNamespaces,
},
Metrics: metricsserver.Options{
BindAddress: metricsAddr,
},
Expand Down

0 comments on commit 4138e05

Please sign in to comment.