@@ -35,9 +35,12 @@ import (
35
35
"k8s.io/klog/v2"
36
36
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
37
37
ctrl "sigs.k8s.io/controller-runtime"
38
- "sigs.k8s.io/controller-runtime/pkg/client"
38
+ cache "sigs.k8s.io/controller-runtime/pkg/cache"
39
+ client "sigs.k8s.io/controller-runtime/pkg/client"
39
40
"sigs.k8s.io/controller-runtime/pkg/client/config"
40
41
"sigs.k8s.io/controller-runtime/pkg/controller"
42
+ metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
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"
@@ -183,22 +186,39 @@ func main() {
183
186
}
184
187
}
185
188
189
+ var watchNamespaces map [string ]cache.Config
190
+ if watchNamespace != "" {
191
+ watchNamespaces = map [string ]cache.Config {
192
+ watchNamespace : {},
193
+ }
194
+ }
195
+
186
196
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 {},
197
+ Scheme : scheme ,
198
+ Metrics : metricsserver.Options {BindAddress : metricsBindAddr },
199
+ LeaderElection : enableLeaderElection ,
200
+ LeaderElectionID : "controller-leader-election-capo" ,
201
+ LeaseDuration : & leaderElectionLeaseDuration ,
202
+ RenewDeadline : & leaderElectionRenewDeadline ,
203
+ RetryPeriod : & leaderElectionRetryPeriod ,
204
+ Cache : cache.Options {
205
+ DefaultNamespaces : watchNamespaces ,
206
+ SyncPeriod : & syncPeriod ,
207
+ },
208
+ Client : client.Options {
209
+ Cache : & client.CacheOptions {
210
+ DisableFor : []client.Object {
211
+ & corev1.ConfigMap {},
212
+ & corev1.Secret {},
213
+ },
214
+ },
199
215
},
200
- Port : webhookPort ,
201
- CertDir : webhookCertDir ,
216
+ WebhookServer : webhook .NewServer (
217
+ webhook.Options {
218
+ Port : webhookPort ,
219
+ CertDir : webhookCertDir ,
220
+ },
221
+ ),
202
222
HealthProbeBindAddress : healthAddr ,
203
223
})
204
224
if err != nil {
0 commit comments