@@ -41,7 +41,6 @@ import (
4141 "sigs.k8s.io/controller-runtime/pkg/cache"
4242 "sigs.k8s.io/controller-runtime/pkg/client"
4343 "sigs.k8s.io/controller-runtime/pkg/controller"
44- metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
4544 "sigs.k8s.io/controller-runtime/pkg/webhook"
4645
4746 clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
@@ -59,49 +58,44 @@ var (
5958 scheme = runtime .NewScheme ()
6059 setupLog = ctrl .Log .WithName ("setup" )
6160 controllerName = "cluster-api-kubeadm-bootstrap-manager"
61+
62+ // flags.
63+ enableLeaderElection bool
64+ leaderElectionLeaseDuration time.Duration
65+ leaderElectionRenewDeadline time.Duration
66+ leaderElectionRetryPeriod time.Duration
67+ watchFilterValue string
68+ watchNamespace string
69+ profilerAddress string
70+ enableContentionProfiling bool
71+ syncPeriod time.Duration
72+ restConfigQPS float32
73+ restConfigBurst int
74+ webhookPort int
75+ webhookCertDir string
76+ healthAddr string
77+ tlsOptions = flags.TLSOptions {}
78+ diagnosticsOptions = flags.DiagnosticsOptions {}
79+ logOptions = logs .NewOptions ()
80+ // CABPK specific flags.
81+ clusterConcurrency int
82+ clusterCacheTrackerConcurrency int
83+ kubeadmConfigConcurrency int
84+ tokenTTL time.Duration
6285)
6386
6487func init () {
65- klog .InitFlags (nil )
66-
6788 _ = clientgoscheme .AddToScheme (scheme )
6889 _ = clusterv1 .AddToScheme (scheme )
6990 _ = expv1 .AddToScheme (scheme )
7091 _ = bootstrapv1alpha4 .AddToScheme (scheme )
7192 _ = bootstrapv1 .AddToScheme (scheme )
7293}
7394
74- var (
75- metricsBindAddr string
76- enableLeaderElection bool
77- leaderElectionLeaseDuration time.Duration
78- leaderElectionRenewDeadline time.Duration
79- leaderElectionRetryPeriod time.Duration
80- watchFilterValue string
81- watchNamespace string
82- profilerAddress string
83- enableContentionProfiling bool
84- clusterConcurrency int
85- clusterCacheTrackerConcurrency int
86- kubeadmConfigConcurrency int
87- syncPeriod time.Duration
88- restConfigQPS float32
89- restConfigBurst int
90- webhookPort int
91- webhookCertDir string
92- healthAddr string
93- tokenTTL time.Duration
94- tlsOptions = flags.TLSOptions {}
95- logOptions = logs .NewOptions ()
96- )
97-
98- // InitFlags initializes this manager's flags.
95+ // InitFlags initializes the flags.
9996func InitFlags (fs * pflag.FlagSet ) {
10097 logsv1 .AddFlags (logOptions , fs )
10198
102- fs .StringVar (& metricsBindAddr , "metrics-bind-addr" , "localhost:8080" ,
103- "The address the metric endpoint binds to." )
104-
10599 fs .BoolVar (& enableLeaderElection , "leader-elect" , false ,
106100 "Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager." )
107101
@@ -117,11 +111,14 @@ func InitFlags(fs *pflag.FlagSet) {
117111 fs .StringVar (& watchNamespace , "namespace" , "" ,
118112 "Namespace that the controller watches to reconcile cluster-api objects. If unspecified, the controller watches for cluster-api objects across all namespaces." )
119113
114+ fs .StringVar (& watchFilterValue , "watch-filter" , "" ,
115+ fmt .Sprintf ("Label value that the controller watches to reconcile cluster-api objects. Label key is always %s. If unspecified, the controller watches for all cluster-api objects." , clusterv1 .WatchLabel ))
116+
120117 fs .StringVar (& profilerAddress , "profiler-address" , "" ,
121118 "Bind address to expose the pprof profiler (e.g. localhost:6060)" )
122119
123120 fs .BoolVar (& enableContentionProfiling , "contention-profiling" , false ,
124- "Enable block profiling, if profiler-address is set. " )
121+ "Enable block profiling" )
125122
126123 fs .IntVar (& clusterConcurrency , "cluster-concurrency" , 10 ,
127124 "Number of clusters to process simultaneously" )
@@ -145,9 +142,6 @@ func InitFlags(fs *pflag.FlagSet) {
145142 fs .DurationVar (& tokenTTL , "bootstrap-token-ttl" , kubeadmbootstrapcontrollers .DefaultTokenTTL ,
146143 "The amount of time the bootstrap token will be valid" )
147144
148- fs .StringVar (& watchFilterValue , "watch-filter" , "" ,
149- fmt .Sprintf ("Label value that the controller watches to reconcile cluster-api objects. Label key is always %s. If unspecified, the controller watches for all cluster-api objects." , clusterv1 .WatchLabel ))
150-
151145 fs .IntVar (& webhookPort , "webhook-port" , 9443 ,
152146 "Webhook Server port" )
153147
@@ -157,11 +151,16 @@ func InitFlags(fs *pflag.FlagSet) {
157151 fs .StringVar (& healthAddr , "health-addr" , ":9440" ,
158152 "The address the health endpoint binds to." )
159153
154+ flags .AddDiagnosticsOptions (fs , & diagnosticsOptions )
160155 flags .AddTLSOptions (fs , & tlsOptions )
161156
162157 feature .MutableGates .AddFlag (fs )
163158}
164159
160+ // Add RBAC for the authorized diagnostics endpoint.
161+ // +kubebuilder:rbac:groups=authentication.k8s.io,resources=tokenreviews,verbs=create
162+ // +kubebuilder:rbac:groups=authorization.k8s.io,resources=subjectaccessreviews,verbs=create
163+
165164func main () {
166165 InitFlags (pflag .CommandLine )
167166 pflag .CommandLine .SetNormalizeFunc (cliflag .WordSepNormalizeFunc )
@@ -192,14 +191,16 @@ func main() {
192191 os .Exit (1 )
193192 }
194193
194+ diagnosticsOpts := flags .GetDiagnosticsOptions (diagnosticsOptions )
195+
195196 var watchNamespaces map [string ]cache.Config
196197 if watchNamespace != "" {
197198 watchNamespaces = map [string ]cache.Config {
198199 watchNamespace : {},
199200 }
200201 }
201202
202- if profilerAddress != "" && enableContentionProfiling {
203+ if enableContentionProfiling {
203204 goruntime .SetBlockProfileRate (1 )
204205 }
205206
@@ -216,9 +217,7 @@ func main() {
216217 LeaderElectionResourceLock : resourcelock .LeasesResourceLock ,
217218 HealthProbeBindAddress : healthAddr ,
218219 PprofBindAddress : profilerAddress ,
219- Metrics : metricsserver.Options {
220- BindAddress : metricsBindAddr ,
221- },
220+ Metrics : diagnosticsOpts ,
222221 Cache : cache.Options {
223222 DefaultNamespaces : watchNamespaces ,
224223 SyncPeriod : & syncPeriod ,
0 commit comments