@@ -21,7 +21,9 @@ import (
21
21
mongodbAPI "github.com/doodlescheduling/kubedb/common/db/mongodb"
22
22
"github.com/doodlescheduling/kubedb/common/vault"
23
23
"os"
24
+ "sigs.k8s.io/controller-runtime/pkg/cache"
24
25
"sigs.k8s.io/controller-runtime/pkg/healthz"
26
+ "strings"
25
27
26
28
postgresqlAPI "github.com/doodlescheduling/kubedb/common/db/postgresql"
27
29
"k8s.io/apimachinery/pkg/runtime"
@@ -50,21 +52,34 @@ func init() {
50
52
func main () {
51
53
var metricsAddr string
52
54
var enableLeaderElection bool
55
+ var namespacesConfig string
56
+ var maxConcurrentReconciles int
53
57
flag .StringVar (& metricsAddr , "metrics-addr" , ":8080" , "The address the metric endpoint binds to." )
54
58
flag .BoolVar (& enableLeaderElection , "enable-leader-election" , false ,
55
59
"Enable leader election for controller manager. " +
56
60
"Enabling this will ensure there is only one active controller manager." )
61
+ flag .StringVar (& namespacesConfig , "namespaces" , "" , "Comma-separated list of namespaces to watch. If not set, all namespaces will be watched." )
62
+ flag .IntVar (& maxConcurrentReconciles , "max-concurrent-reconciles" , 1 , "Maximum number of concurrent reconciles. Default is 1." )
57
63
flag .Parse ()
58
64
59
65
ctrl .SetLogger (zap .New (zap .UseDevMode (true )))
60
66
61
- mgr , err := ctrl .NewManager (ctrl .GetConfigOrDie (), ctrl.Options {
67
+ namespaces := strings .Split (namespacesConfig , "," )
68
+ options := ctrl.Options {
62
69
Scheme : scheme ,
63
70
MetricsBindAddress : metricsAddr ,
64
71
Port : 9443 ,
65
72
LeaderElection : enableLeaderElection ,
66
73
LeaderElectionID : "99a96989.doodle.com" ,
67
- })
74
+ }
75
+ if len (namespaces ) > 0 && namespaces [0 ] != "" {
76
+ options .NewCache = cache .MultiNamespacedCacheBuilder (namespaces )
77
+ setupLog .Info ("watching configured namespaces" , "namespaces" , namespaces )
78
+ } else {
79
+ setupLog .Info ("watching all namespaces" )
80
+ }
81
+
82
+ mgr , err := ctrl .NewManager (ctrl .GetConfigOrDie (), options )
68
83
if err != nil {
69
84
setupLog .Error (err , "unable to start manager" )
70
85
os .Exit (1 )
@@ -93,7 +108,7 @@ func main() {
93
108
Scheme : mgr .GetScheme (),
94
109
ServerCache : mongoDBServerCache ,
95
110
VaultCache : vaultCache ,
96
- }).SetupWithManager (mgr ); err != nil {
111
+ }).SetupWithManager (mgr , maxConcurrentReconciles ); err != nil {
97
112
setupLog .Error (err , "unable to create controller" , "controller" , "MongoDBDatabase" )
98
113
os .Exit (1 )
99
114
}
@@ -106,7 +121,7 @@ func main() {
106
121
Scheme : mgr .GetScheme (),
107
122
ServerCache : postgreSQLServerCache ,
108
123
VaultCache : vaultCache ,
109
- }).SetupWithManager (mgr ); err != nil {
124
+ }).SetupWithManager (mgr , maxConcurrentReconciles ); err != nil {
110
125
setupLog .Error (err , "unable to create controller" , "controller" , "PostgreSQLDatabase" )
111
126
os .Exit (1 )
112
127
}
0 commit comments