Skip to content

Commit

Permalink
Watch Namespace (#454)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkumatag authored Dec 8, 2021
1 parent 6b14e4b commit 0a7ce2e
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import (
)

var (
watchNamespace string

scheme = runtime.NewScheme()
setupLog = ctrl.Log.WithName("setup")
)
Expand All @@ -55,9 +57,20 @@ func main() {
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.",
)
flag.Parse()

ctrl.SetLogger(zap.New(zap.UseDevMode(true)))

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

syncPeriod := 15 * time.Second
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
Expand All @@ -66,6 +79,7 @@ func main() {
LeaderElection: enableLeaderElection,
LeaderElectionID: "effcf9b8.cluster.x-k8s.io",
SyncPeriod: &syncPeriod,
Namespace: watchNamespace,
})
if err != nil {
setupLog.Error(err, "unable to start manager")
Expand Down

0 comments on commit 0a7ce2e

Please sign in to comment.