@@ -41,7 +41,6 @@ import (
41
41
"sigs.k8s.io/controller-runtime/pkg/cache"
42
42
"sigs.k8s.io/controller-runtime/pkg/client"
43
43
"sigs.k8s.io/controller-runtime/pkg/controller"
44
- metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
45
44
"sigs.k8s.io/controller-runtime/pkg/webhook"
46
45
47
46
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
@@ -59,49 +58,44 @@ var (
59
58
scheme = runtime .NewScheme ()
60
59
setupLog = ctrl .Log .WithName ("setup" )
61
60
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
62
85
)
63
86
64
87
func init () {
65
- klog .InitFlags (nil )
66
-
67
88
_ = clientgoscheme .AddToScheme (scheme )
68
89
_ = clusterv1 .AddToScheme (scheme )
69
90
_ = expv1 .AddToScheme (scheme )
70
91
_ = bootstrapv1alpha4 .AddToScheme (scheme )
71
92
_ = bootstrapv1 .AddToScheme (scheme )
72
93
}
73
94
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.
99
96
func InitFlags (fs * pflag.FlagSet ) {
100
97
logsv1 .AddFlags (logOptions , fs )
101
98
102
- fs .StringVar (& metricsBindAddr , "metrics-bind-addr" , "localhost:8080" ,
103
- "The address the metric endpoint binds to." )
104
-
105
99
fs .BoolVar (& enableLeaderElection , "leader-elect" , false ,
106
100
"Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager." )
107
101
@@ -117,11 +111,14 @@ func InitFlags(fs *pflag.FlagSet) {
117
111
fs .StringVar (& watchNamespace , "namespace" , "" ,
118
112
"Namespace that the controller watches to reconcile cluster-api objects. If unspecified, the controller watches for cluster-api objects across all namespaces." )
119
113
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
+
120
117
fs .StringVar (& profilerAddress , "profiler-address" , "" ,
121
118
"Bind address to expose the pprof profiler (e.g. localhost:6060)" )
122
119
123
120
fs .BoolVar (& enableContentionProfiling , "contention-profiling" , false ,
124
- "Enable block profiling, if profiler-address is set. " )
121
+ "Enable block profiling" )
125
122
126
123
fs .IntVar (& clusterConcurrency , "cluster-concurrency" , 10 ,
127
124
"Number of clusters to process simultaneously" )
@@ -145,9 +142,6 @@ func InitFlags(fs *pflag.FlagSet) {
145
142
fs .DurationVar (& tokenTTL , "bootstrap-token-ttl" , kubeadmbootstrapcontrollers .DefaultTokenTTL ,
146
143
"The amount of time the bootstrap token will be valid" )
147
144
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
-
151
145
fs .IntVar (& webhookPort , "webhook-port" , 9443 ,
152
146
"Webhook Server port" )
153
147
@@ -157,11 +151,16 @@ func InitFlags(fs *pflag.FlagSet) {
157
151
fs .StringVar (& healthAddr , "health-addr" , ":9440" ,
158
152
"The address the health endpoint binds to." )
159
153
154
+ flags .AddDiagnosticsOptions (fs , & diagnosticsOptions )
160
155
flags .AddTLSOptions (fs , & tlsOptions )
161
156
162
157
feature .MutableGates .AddFlag (fs )
163
158
}
164
159
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
+
165
164
func main () {
166
165
InitFlags (pflag .CommandLine )
167
166
pflag .CommandLine .SetNormalizeFunc (cliflag .WordSepNormalizeFunc )
@@ -192,14 +191,16 @@ func main() {
192
191
os .Exit (1 )
193
192
}
194
193
194
+ diagnosticsOpts := flags .GetDiagnosticsOptions (diagnosticsOptions )
195
+
195
196
var watchNamespaces map [string ]cache.Config
196
197
if watchNamespace != "" {
197
198
watchNamespaces = map [string ]cache.Config {
198
199
watchNamespace : {},
199
200
}
200
201
}
201
202
202
- if profilerAddress != "" && enableContentionProfiling {
203
+ if enableContentionProfiling {
203
204
goruntime .SetBlockProfileRate (1 )
204
205
}
205
206
@@ -216,9 +217,7 @@ func main() {
216
217
LeaderElectionResourceLock : resourcelock .LeasesResourceLock ,
217
218
HealthProbeBindAddress : healthAddr ,
218
219
PprofBindAddress : profilerAddress ,
219
- Metrics : metricsserver.Options {
220
- BindAddress : metricsBindAddr ,
221
- },
220
+ Metrics : diagnosticsOpts ,
222
221
Cache : cache.Options {
223
222
DefaultNamespaces : watchNamespaces ,
224
223
SyncPeriod : & syncPeriod ,
0 commit comments