Skip to content

Commit 8d16800

Browse files
Support watchNamespace for controller
1 parent 099d28f commit 8d16800

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,23 @@ func main() {
7070
var metricsAddr string
7171
var enableLeaderElection bool
7272
var probeAddr string
73+
var watchNamespace string
7374
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
7475
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
7576
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
7677
"Enable leader election for controller manager. "+
7778
"Enabling this will ensure there is only one active controller manager.")
79+
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.")
7880
opts := zap.Options{
7981
Development: true,
8082
}
8183
opts.BindFlags(flag.CommandLine)
8284
flag.Parse()
8385

86+
if watchNamespace != "" {
87+
setupLog.Info("Watching cluster-api objects only in namespace for reconciliation", "namespace", watchNamespace)
88+
}
89+
8490
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))
8591
restConfig := ctrl.GetConfigOrDie()
8692
restConfig.UserAgent = remote.DefaultClusterAPIUserAgent("cluster-api-microk8s-bootstrap-manager")
@@ -94,6 +100,7 @@ func main() {
94100
&corev1.ConfigMap{},
95101
&corev1.Secret{},
96102
},
103+
Namespace: watchNamespace,
97104
})
98105
if err != nil {
99106
setupLog.Error(err, "unable to start manager")

0 commit comments

Comments
 (0)