@@ -34,10 +34,13 @@ import (
34
34
_ "k8s.io/component-base/logs/json/register"
35
35
"k8s.io/klog/v2"
36
36
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
37
+ "sigs.k8s.io/cluster-api/util/flags"
37
38
ctrl "sigs.k8s.io/controller-runtime"
38
- "sigs.k8s.io/controller-runtime/pkg/client"
39
+ cache "sigs.k8s.io/controller-runtime/pkg/cache"
40
+ client "sigs.k8s.io/controller-runtime/pkg/client"
39
41
"sigs.k8s.io/controller-runtime/pkg/client/config"
40
42
"sigs.k8s.io/controller-runtime/pkg/controller"
43
+ "sigs.k8s.io/controller-runtime/pkg/webhook"
41
44
42
45
infrav1alpha5 "sigs.k8s.io/cluster-api-provider-openstack/api/v1alpha5"
43
46
infrav1alpha6 "sigs.k8s.io/cluster-api-provider-openstack/api/v1alpha6"
54
57
setupLog = ctrl .Log .WithName ("setup" )
55
58
56
59
// flags.
57
- metricsBindAddr string
60
+ diagnosticsOptions = flags. DiagnosticsOptions {}
58
61
enableLeaderElection bool
59
62
leaderElectionLeaseDuration time.Duration
60
63
leaderElectionRenewDeadline time.Duration
@@ -91,8 +94,7 @@ func InitFlags(fs *pflag.FlagSet) {
91
94
logs .AddFlags (fs , logs .SkipLoggingConfigurationFlags ())
92
95
logsv1 .AddFlags (logOptions , fs )
93
96
94
- fs .StringVar (& metricsBindAddr , "metrics-bind-addr" , "localhost:8080" ,
95
- "The address the metric endpoint binds to." )
97
+ flags .AddDiagnosticsOptions (fs , & diagnosticsOptions )
96
98
97
99
fs .BoolVar (& enableLeaderElection , "leader-elect" , false ,
98
100
"Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager." )
@@ -143,6 +145,10 @@ func InitFlags(fs *pflag.FlagSet) {
143
145
fs .BoolVar (& showVersion , "version" , false , "Show current version and exit." )
144
146
}
145
147
148
+ // Add RBAC for the authorized diagnostics endpoint.
149
+ // +kubebuilder:rbac:groups=authentication.k8s.io,resources=tokenreviews,verbs=create
150
+ // +kubebuilder:rbac:groups=authorization.k8s.io,resources=subjectaccessreviews,verbs=create
151
+
146
152
func main () {
147
153
InitFlags (pflag .CommandLine )
148
154
pflag .CommandLine .SetNormalizeFunc (cliflag .WordSepNormalizeFunc )
@@ -183,22 +189,41 @@ func main() {
183
189
}
184
190
}
185
191
192
+ diagnosticsOpts := flags .GetDiagnosticsOptions (diagnosticsOptions )
193
+
194
+ var watchNamespaces map [string ]cache.Config
195
+ if watchNamespace != "" {
196
+ watchNamespaces = map [string ]cache.Config {
197
+ watchNamespace : {},
198
+ }
199
+ }
200
+
186
201
mgr , err := ctrl .NewManager (cfg , ctrl.Options {
187
- Scheme : scheme ,
188
- MetricsBindAddress : metricsBindAddr ,
189
- LeaderElection : enableLeaderElection ,
190
- LeaderElectionID : "controller-leader-election-capo" ,
191
- LeaseDuration : & leaderElectionLeaseDuration ,
192
- RenewDeadline : & leaderElectionRenewDeadline ,
193
- RetryPeriod : & leaderElectionRetryPeriod ,
194
- Namespace : watchNamespace ,
195
- SyncPeriod : & syncPeriod ,
196
- ClientDisableCacheFor : []client.Object {
197
- & corev1.ConfigMap {},
198
- & corev1.Secret {},
202
+ Scheme : scheme ,
203
+ Metrics : diagnosticsOpts ,
204
+ LeaderElection : enableLeaderElection ,
205
+ LeaderElectionID : "controller-leader-election-capo" ,
206
+ LeaseDuration : & leaderElectionLeaseDuration ,
207
+ RenewDeadline : & leaderElectionRenewDeadline ,
208
+ RetryPeriod : & leaderElectionRetryPeriod ,
209
+ Cache : cache.Options {
210
+ DefaultNamespaces : watchNamespaces ,
211
+ SyncPeriod : & syncPeriod ,
212
+ },
213
+ Client : client.Options {
214
+ Cache : & client.CacheOptions {
215
+ DisableFor : []client.Object {
216
+ & corev1.ConfigMap {},
217
+ & corev1.Secret {},
218
+ },
219
+ },
199
220
},
200
- Port : webhookPort ,
201
- CertDir : webhookCertDir ,
221
+ WebhookServer : webhook .NewServer (
222
+ webhook.Options {
223
+ Port : webhookPort ,
224
+ CertDir : webhookCertDir ,
225
+ },
226
+ ),
202
227
HealthProbeBindAddress : healthAddr ,
203
228
})
204
229
if err != nil {
0 commit comments