Skip to content

Commit

Permalink
Support watchNamespace for controller
Browse files Browse the repository at this point in the history
  • Loading branch information
jayesh-srivastava committed Apr 6, 2024
1 parent 61c9106 commit 51605fe
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,14 @@ func main() {
var metricsAddr string
var enableLeaderElection bool
var probeAddr string
var watchNamespace string
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8082", "The address the metric endpoint binds to.")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8083", "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(&watchNamespace, "namespace", "", "Namespace that the controller watches to reconcile cluster-api objects. If unspecified, the controller watches for cluster-api objects across all namespaces.")

opts := zap.Options{
Development: true,
}
Expand All @@ -71,13 +74,18 @@ func main() {

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

if watchNamespace != "" {
setupLog.Info("Watching cluster-api objects only in namespace for reconciliation\", \"namespace", watchNamespace)
}

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
MetricsBindAddress: metricsAddr,
Port: 9443,
HealthProbeBindAddress: probeAddr,
LeaderElection: enableLeaderElection,
LeaderElectionID: "microk8s-control-plane-manager-leader-election-capi",
Namespace: watchNamespace,
})
if err != nil {
setupLog.Error(err, "unable to start manager")
Expand Down

0 comments on commit 51605fe

Please sign in to comment.